Kkdjskjd
This commit is contained in:
@@ -2,7 +2,7 @@ import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import { compileText } from '../src/effects/compile.js'
|
||||
import { formatAbility } from '../src/effects/format.js'
|
||||
import { parsePseudoCard } from '../src/effects/pseudo.js'
|
||||
import { parseCardSource } from '../src/effects/source.js'
|
||||
import type { Ability, Effect, Target } from '../src/effects/types.js'
|
||||
|
||||
function creature(text: string, keywords: string[] = []): Ability[] {
|
||||
@@ -41,6 +41,33 @@ test('activated mana ability', () => {
|
||||
})
|
||||
})
|
||||
|
||||
test('"or" in a mana ability marks the symbols as a choice', () => {
|
||||
const [ability] = creature('{T}: Add {G} or {U}.')
|
||||
assert.equal(ability.kind, 'activated')
|
||||
if (ability.kind !== 'activated') return
|
||||
assert.deepEqual(ability.effects[0], {
|
||||
op: 'add_mana',
|
||||
player: 'you',
|
||||
mana: { kind: 'symbols', symbols: ['{G}', '{U}'], oneOf: true },
|
||||
})
|
||||
})
|
||||
|
||||
test('paying life to enter untapped compiles to an enters-tapped replacement', () => {
|
||||
const [ability] = compileText(
|
||||
"As this land enters, you may pay 2 life. If you don't, it enters tapped.",
|
||||
'Steam Vents',
|
||||
[],
|
||||
'Land — Island Mountain',
|
||||
)
|
||||
assert.equal(ability.kind, 'static')
|
||||
if (ability.kind !== 'static') return
|
||||
assert.deepEqual(ability.effects[0], {
|
||||
op: 'enters_tapped',
|
||||
target: { kind: 'self' },
|
||||
unlessCost: { kind: 'pay_life', amount: { kind: 'number', value: 2 } },
|
||||
})
|
||||
})
|
||||
|
||||
test('search effect keeps destination, tapped, and shuffle', () => {
|
||||
const [ability] = spell('Search your library for a basic land card, put it onto the battlefield tapped, then shuffle.')
|
||||
assert.equal(ability.kind, 'spell')
|
||||
@@ -169,10 +196,10 @@ test('trigger condition cards in graveyard', () => {
|
||||
assert.deepEqual(ability.condition, { kind: 'cards_in_graveyard', player: 'you', atLeast: 7 })
|
||||
})
|
||||
|
||||
test('formatter renders pseudocode', () => {
|
||||
test('formatter renders card source', () => {
|
||||
const [ability] = creature('When this creature enters, draw a card.')
|
||||
const text = formatAbility(ability)
|
||||
assert.match(text, /on enters\(this\)/)
|
||||
assert.match(text, /triggered\(when\.enters\(self\)/)
|
||||
assert.match(text, /draw\(you, 1\)/)
|
||||
})
|
||||
|
||||
@@ -201,7 +228,10 @@ test('token copy of the triggering nontoken Dragon loses legendary', () => {
|
||||
if (effect.op !== 'create_token') return
|
||||
assert.deepEqual(effect.copyOf, { kind: 'trigger_subject' })
|
||||
assert.equal(effect.notLegendary, true)
|
||||
assert.equal(formatAbility(ability), 'on enters(each other nontoken dragon creature you control):\n create_token(you, 1, copy of the triggering object, not legendary)')
|
||||
assert.equal(
|
||||
formatAbility(ability),
|
||||
"triggered(when.enters(each(permanents.other().nontoken().withSubtype('dragon').withType('creature').youControl())), () => createToken(you, 1, copyOf(triggerSubject, { notLegendary: true })))",
|
||||
)
|
||||
})
|
||||
|
||||
test('all effects are typed', () => {
|
||||
@@ -299,9 +329,9 @@ test('"until the end of your next turn" gets its own duration', () => {
|
||||
if (effect.op !== 'pump') return
|
||||
assert.equal(effect.duration, 'until_end_of_your_next_turn')
|
||||
|
||||
const pseudo = formatAbility(ability)
|
||||
assert.match(pseudo, /until the end of your next turn/)
|
||||
assert.equal(formatAbility(parsePseudoCard(`# Test [supported]\n${pseudo}`).abilities[0]), pseudo)
|
||||
const source = formatAbility(ability)
|
||||
assert.match(source, /untilEndOfYourNextTurn/)
|
||||
assert.equal(formatAbility(parseCardSource(`export default [${source}]`).abilities[0]), source)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -315,7 +345,7 @@ test('parameterized keywords accept an em dash', () => {
|
||||
assert.deepEqual(fabricate, { kind: 'keyword', keyword: 'Fabricate', value: '1' })
|
||||
})
|
||||
|
||||
test('counter-removal costs parse and round-trip through pseudocode', () => {
|
||||
test('counter-removal costs parse and round-trip through card source', () => {
|
||||
const [self] = creature('{2}{U}, Remove a +1/+1 counter from this: Draw a card, then discard a card.')
|
||||
assert.equal(self.kind, 'activated')
|
||||
if (self.kind !== 'activated') return
|
||||
@@ -324,9 +354,9 @@ test('counter-removal costs parse and round-trip through pseudocode', () => {
|
||||
{ kind: 'remove_counters', counter: '+1/+1', amount: { kind: 'number', value: 1 } },
|
||||
])
|
||||
|
||||
const pseudo = formatAbility(self)
|
||||
assert.match(pseudo, /remove 1 \+1\/\+1 counter\(s\) from this/)
|
||||
assert.equal(formatAbility(parsePseudoCard(`# Test [supported]\n${pseudo}`).abilities[0]), pseudo)
|
||||
const source = formatAbility(self)
|
||||
assert.match(source, /removeCountersCost\('\+1\/\+1', 1\)/)
|
||||
assert.equal(formatAbility(parseCardSource(`export default [${source}]`).abilities[0]), source)
|
||||
|
||||
const [other] = creature('Remove three spore counters from a creature you control: Create a 1/1 green Saproling creature token.')
|
||||
assert.equal(other.kind, 'activated')
|
||||
@@ -520,7 +550,7 @@ test('spell cost reductions compile their conditions and mana symbols', () => {
|
||||
}])
|
||||
})
|
||||
|
||||
test('new abilities, effects and conditions round-trip through pseudocode', () => {
|
||||
test('new abilities, effects and conditions round-trip through card source', () => {
|
||||
const abilities: Ability[] = [
|
||||
...spell('If you control a commander, you may cast this without paying its mana cost.'),
|
||||
...spell('Overload {6}{U}'),
|
||||
@@ -541,9 +571,9 @@ test('new abilities, effects and conditions round-trip through pseudocode', () =
|
||||
),
|
||||
]
|
||||
for (const ability of abilities) {
|
||||
const pseudo = formatAbility(ability)
|
||||
const reparsed = parsePseudoCard(`# Test [supported]\n${pseudo}`).abilities[0]
|
||||
const source = formatAbility(ability)
|
||||
const reparsed = parseCardSource(`export default [${source}]`).abilities[0]
|
||||
assert.ok(reparsed)
|
||||
assert.equal(formatAbility(reparsed), pseudo)
|
||||
assert.equal(formatAbility(reparsed), source)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user