test
This commit is contained in:
@@ -29,6 +29,58 @@ test('enters trigger with a draw effect', () => {
|
||||
assert.equal(ability.effects[0].op, 'draw')
|
||||
})
|
||||
|
||||
test('compound effects resolve "it" through the previous target', () => {
|
||||
const [ability] = creature('When this enters, tap target creature an opponent controls and put a stun counter on it.')
|
||||
assert.equal(ability.kind, 'triggered')
|
||||
if (ability.kind !== 'triggered') return
|
||||
assert.deepEqual(ability.effects[1], {
|
||||
op: 'put_counters',
|
||||
target: { kind: 'previous_target' },
|
||||
counter: 'stun',
|
||||
amount: { kind: 'number', value: 1 },
|
||||
})
|
||||
})
|
||||
|
||||
test('compound effects share an explicit player subject', () => {
|
||||
const [ability] = spell('Target player draws two cards and loses 2 life.')
|
||||
assert.equal(ability.kind, 'spell')
|
||||
if (ability.kind !== 'spell') return
|
||||
assert.deepEqual(ability.effects[1], {
|
||||
op: 'life',
|
||||
player: 'target_player',
|
||||
amount: { kind: 'number', value: 2 },
|
||||
mode: 'lose',
|
||||
})
|
||||
})
|
||||
|
||||
test('damage triggers without a recipient use the event amount', () => {
|
||||
const [ability] = creature('Whenever this deals damage, you gain that much life.')
|
||||
assert.equal(ability.kind, 'triggered')
|
||||
if (ability.kind !== 'triggered') return
|
||||
assert.equal(ability.event.kind, 'deals_damage')
|
||||
assert.deepEqual(ability.effects[0], {
|
||||
op: 'life',
|
||||
player: 'you',
|
||||
amount: { kind: 'event_amount' },
|
||||
mode: 'gain',
|
||||
})
|
||||
})
|
||||
|
||||
test('a later sentence can refer to a token created by an earlier one', () => {
|
||||
const [ability] = creature(
|
||||
'When this enters, create a 0/0 green and blue Fractal creature token. Put three +1/+1 counters on it.',
|
||||
)
|
||||
assert.equal(ability.kind, 'triggered')
|
||||
if (ability.kind !== 'triggered') return
|
||||
assert.equal(ability.effects[0].op, 'create_token')
|
||||
assert.deepEqual(ability.effects[1], {
|
||||
op: 'put_counters',
|
||||
target: { kind: 'previous_target' },
|
||||
counter: '+1/+1',
|
||||
amount: { kind: 'number', value: 3 },
|
||||
})
|
||||
})
|
||||
|
||||
test('activated mana ability', () => {
|
||||
const [ability] = creature('{T}: Add {G}.')
|
||||
assert.equal(ability.kind, 'activated')
|
||||
@@ -149,11 +201,16 @@ test('"it" refers to the triggering object when unambiguous', () => {
|
||||
assert.deepEqual(effect.target, { kind: 'trigger_subject' })
|
||||
})
|
||||
|
||||
test('ambiguous "it" is left unsupported instead of guessed', () => {
|
||||
test('a target introduced in one clause is the "it" of the next', () => {
|
||||
const [ability] = creature(
|
||||
'When this creature enters, tap target creature an opponent controls and put a stun counter on it.',
|
||||
)
|
||||
assert.equal(ability.kind, 'unsupported')
|
||||
assert.equal(ability.kind, 'triggered')
|
||||
if (ability.kind !== 'triggered') return
|
||||
const effect = ability.effects[1]
|
||||
assert.equal(effect.op, 'put_counters')
|
||||
if (effect.op !== 'put_counters') return
|
||||
assert.deepEqual(effect.target, { kind: 'previous_target' })
|
||||
})
|
||||
|
||||
test('modal text is unsupported', () => {
|
||||
@@ -275,7 +332,7 @@ test('token-doubling replacement lines compile and round-trip', () => {
|
||||
const [ability] = creature(text)
|
||||
assert.equal(ability.kind, 'static')
|
||||
if (ability.kind !== 'static') return
|
||||
assert.deepEqual(ability.effects[0], expected)
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(ability.effects[0])), expected)
|
||||
|
||||
const source = formatAbility(ability)
|
||||
assert.equal(formatAbility(parseCardSource(`export default [${source}]`).abilities[0]), source)
|
||||
@@ -354,6 +411,172 @@ test('"When <subject>" triggers and bare "gain life" effects parse', () => {
|
||||
})
|
||||
})
|
||||
|
||||
test('"This ability triggers only once" marks the trigger', () => {
|
||||
const [ability] = creature('At the beginning of your second main phase, if this is tapped, put a flying counter on it. This ability triggers only once.')
|
||||
assert.equal(ability.kind, 'triggered')
|
||||
if (ability.kind !== 'triggered') return
|
||||
assert.deepEqual(ability.event, { kind: 'main_phase', who: 'you', phase: 'postcombat' })
|
||||
assert.equal(ability.oncePerTurn, true)
|
||||
assert.deepEqual(ability.effects[0], {
|
||||
op: 'put_counters',
|
||||
target: { kind: 'self' },
|
||||
counter: 'flying',
|
||||
amount: { kind: 'number', value: 1 },
|
||||
})
|
||||
})
|
||||
|
||||
test('impulse exiles the top cards and grants play permission', () => {
|
||||
const [ability] = spell('Exile the top three cards of your library. Until end of turn, you may play those cards.')
|
||||
assert.equal(ability.kind, 'spell')
|
||||
if (ability.kind !== 'spell') return
|
||||
assert.deepEqual(ability.effects[0], {
|
||||
op: 'impulse',
|
||||
player: 'you',
|
||||
amount: { kind: 'number', value: 3 },
|
||||
faceDown: false,
|
||||
})
|
||||
})
|
||||
|
||||
test('a mana ability can produce the chosen color', () => {
|
||||
const [ability] = creature('{T}: Add one mana of the chosen color.')
|
||||
assert.equal(ability.kind, 'activated')
|
||||
if (ability.kind !== 'activated') return
|
||||
assert.deepEqual(ability.effects[0], {
|
||||
op: 'add_mana',
|
||||
player: 'you',
|
||||
mana: {
|
||||
kind: 'any_color',
|
||||
amount: { kind: 'number', value: 1 },
|
||||
oneColor: true,
|
||||
restriction: 'chosen color',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
test('doubling counters compiles to its own effect', () => {
|
||||
const [ability] = spell('Double the number of +1/+1 counters on target creature.')
|
||||
assert.equal(ability.kind, 'spell')
|
||||
if (ability.kind !== 'spell') return
|
||||
assert.deepEqual(ability.effects[0], {
|
||||
op: 'double_counters',
|
||||
target: { kind: 'object', selector: { types: ['creature'] }, mode: 'target' },
|
||||
counter: '+1/+1',
|
||||
})
|
||||
})
|
||||
|
||||
test('damage prevention compiles with its shield and scope', () => {
|
||||
const [shield] = spell('Prevent the next 3 damage that would be dealt to target creature this turn.')
|
||||
assert.equal(shield.kind, 'spell')
|
||||
if (shield.kind !== 'spell') return
|
||||
assert.equal(shield.effects[0].op, 'prevent_damage')
|
||||
const first = shield.effects[0]
|
||||
if (first.op !== 'prevent_damage') return
|
||||
assert.deepEqual(first.target, { kind: 'object', selector: { types: ['creature'] }, mode: 'target' })
|
||||
assert.deepEqual(first.amount, { kind: 'number', value: 3 })
|
||||
assert.equal(first.duration, 'until_end_of_turn')
|
||||
assert.equal(first.global, undefined)
|
||||
|
||||
const [global] = spell('Prevent all combat damage that would be dealt this turn.')
|
||||
assert.equal(global.kind, 'spell')
|
||||
if (global.kind !== 'spell') return
|
||||
const second = global.effects[0]
|
||||
if (second.op !== 'prevent_damage') return
|
||||
assert.equal(second.amount, 'all')
|
||||
assert.equal(second.combatOnly, true)
|
||||
assert.equal(second.global, true)
|
||||
})
|
||||
|
||||
test('counter and energy replacement lines compile', () => {
|
||||
const [counters] = creature('If one or more +1/+1 counters would be put on a creature you control, twice that many +1/+1 counters are put on that creature instead.')
|
||||
assert.equal(counters.kind, 'static')
|
||||
if (counters.kind !== 'static') return
|
||||
assert.equal(counters.effects[0].op, 'counter_multiplier')
|
||||
if (counters.effects[0].op !== 'counter_multiplier') return
|
||||
assert.equal(counters.effects[0].counter, '+1/+1')
|
||||
assert.equal(counters.effects[0].multiplier, 2)
|
||||
|
||||
const [energy] = creature('If you would get one or more {E}, you get twice that many {E} instead.')
|
||||
assert.equal(energy.kind, 'static')
|
||||
if (energy.kind !== 'static') return
|
||||
assert.deepEqual(energy.effects[0], { op: 'replacement_amount', what: 'energy', multiplier: 2 })
|
||||
})
|
||||
|
||||
test('static source-filtered prevention compiles', () => {
|
||||
const [ability] = creature('Prevent all damage that would be dealt to this by artifact creatures.')
|
||||
assert.equal(ability.kind, 'static')
|
||||
if (ability.kind !== 'static') return
|
||||
assert.deepEqual(ability.effects[0], {
|
||||
op: 'prevent_damage',
|
||||
target: { kind: 'self' },
|
||||
amount: 'all',
|
||||
combatOnly: undefined,
|
||||
duration: 'permanent',
|
||||
sourceSelector: { types: ['artifact', 'creature'] },
|
||||
})
|
||||
})
|
||||
|
||||
test('source-scoped prevention compiles with its chosen source', () => {
|
||||
const [ability] = spell('Prevent all damage a red source of your choice would deal this turn.')
|
||||
assert.equal(ability.kind, 'spell')
|
||||
if (ability.kind !== 'spell') return
|
||||
const shield = ability.effects[0]
|
||||
assert.equal(shield.op, 'prevent_damage')
|
||||
if (shield.op !== 'prevent_damage') return
|
||||
assert.deepEqual(shield.source, { kind: 'object', selector: { colors: ['R'] }, mode: 'target' })
|
||||
assert.equal(shield.global, true)
|
||||
})
|
||||
|
||||
test('a prevention follow-up compiles into the shield', () => {
|
||||
const [ability] = spell('Prevent the next 3 damage that would be dealt to target creature this turn. If damage is prevented this way, this deals that much damage to any target.')
|
||||
assert.equal(ability.kind, 'spell')
|
||||
if (ability.kind !== 'spell') return
|
||||
const shield = ability.effects[0]
|
||||
assert.equal(shield.op, 'prevent_damage')
|
||||
if (shield.op !== 'prevent_damage') return
|
||||
assert.deepEqual(shield.then, [{
|
||||
op: 'damage',
|
||||
target: { kind: 'any' },
|
||||
amount: { kind: 'event_amount' },
|
||||
}])
|
||||
})
|
||||
|
||||
test('replacement amount lines compile', () => {
|
||||
const [life] = creature('If you would gain life, you gain twice that much life instead.')
|
||||
assert.equal(life.kind, 'static')
|
||||
if (life.kind !== 'static') return
|
||||
assert.deepEqual(life.effects[0], { op: 'replacement_amount', what: 'life_gain', multiplier: 2 })
|
||||
|
||||
const [plus] = creature('If you would gain life, you gain that much life plus 1 instead.')
|
||||
assert.equal(plus.kind, 'static')
|
||||
if (plus.kind !== 'static') return
|
||||
assert.deepEqual(plus.effects[0], { op: 'replacement_amount', what: 'life_gain', multiplier: 1, add: 1 })
|
||||
|
||||
const [draw] = creature('If you would draw a card, draw two cards instead.')
|
||||
assert.equal(draw.kind, 'static')
|
||||
if (draw.kind !== 'static') return
|
||||
assert.deepEqual(draw.effects[0], { op: 'replacement_amount', what: 'draw', multiplier: 2 })
|
||||
})
|
||||
|
||||
test('"skip your draw step" and attack-or-block restrictions compile', () => {
|
||||
const [skip] = creature('Skip your draw step.')
|
||||
assert.equal(skip.kind, 'static')
|
||||
if (skip.kind !== 'static') return
|
||||
assert.deepEqual(skip.effects[0], {
|
||||
op: 'restriction',
|
||||
target: { kind: 'player', who: 'you', mode: 'target' },
|
||||
rule: 'skip_draw_step',
|
||||
})
|
||||
|
||||
const [lock] = creature('Enchanted creature cannot attack or block, and its activated abilities cannot be activated.')
|
||||
assert.equal(lock.kind, 'static')
|
||||
if (lock.kind !== 'static') return
|
||||
assert.deepEqual(lock.effects.map(effect => effect.op === 'restriction' ? effect.rule : effect.op), [
|
||||
'cant_attack',
|
||||
'cant_block',
|
||||
'cant_activate',
|
||||
])
|
||||
})
|
||||
|
||||
test('a trailing condition becomes a static condition', () => {
|
||||
const [ability] = creature('This creature cannot attack if defending player controls an untapped land.')
|
||||
assert.equal(ability.kind, 'static')
|
||||
@@ -646,3 +869,51 @@ test('Role token creation compiles with the attachment target', () => {
|
||||
assert.equal(formatAbility(parseCardSource(`export default [${source}]`).abilities[0]), source)
|
||||
}
|
||||
})
|
||||
|
||||
test('token-creation replacement lines compile and round-trip', () => {
|
||||
const cases: Array<[string, object]> = [
|
||||
[
|
||||
'If you would create a Food token, instead create a Food token and a Treasure token.',
|
||||
{ op: 'token_replacement', from: ['food'], tokens: [{ types: ['artifact'], subtypes: ['food'], colors: [] }, { types: ['artifact'], subtypes: ['treasure'], colors: [] }], who: 'you' },
|
||||
],
|
||||
[
|
||||
'If you would create a Clue, Food, or Treasure token, instead create one of each.',
|
||||
{ op: 'token_replacement', from: ['clue', 'food', 'treasure'], tokens: [{ name: 'Clue', types: ['artifact'], subtypes: ['clue'], colors: [] }, { name: 'Food', types: ['artifact'], subtypes: ['food'], colors: [] }, { name: 'Treasure', types: ['artifact'], subtypes: ['treasure'], colors: [] }], who: 'you' },
|
||||
],
|
||||
]
|
||||
for (const [text, expected] of cases) {
|
||||
const [ability] = creature(text)
|
||||
assert.equal(ability.kind, 'static')
|
||||
if (ability.kind !== 'static') return
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(ability.effects[0])), expected)
|
||||
|
||||
const source = formatAbility(ability)
|
||||
assert.equal(formatAbility(parseCardSource(`export default [${source}]`).abilities[0]), source)
|
||||
}
|
||||
})
|
||||
|
||||
test('exile-instead-of-dying clauses compile', () => {
|
||||
const [damaged] = spell('This deals 3 damage to any target. If a creature dealt damage this way would die this turn, exile it instead.')
|
||||
assert.equal(damaged.kind, 'spell')
|
||||
if (damaged.kind !== 'spell') return
|
||||
assert.deepEqual(damaged.effects[1], { op: 'exile_instead_of_dying', target: { kind: 'damaged' } })
|
||||
|
||||
const [that] = spell('This deals 3 damage to target creature. If that creature would die this turn, exile it instead.')
|
||||
assert.equal(that.kind, 'spell')
|
||||
if (that.kind !== 'spell') return
|
||||
assert.deepEqual(that.effects[1], { op: 'exile_instead_of_dying', target: { kind: 'previous_target' } })
|
||||
})
|
||||
|
||||
test('equipped and enchanted conditions gate static abilities', () => {
|
||||
const [equipped] = creature('As long as this is equipped, it gets +2/+0 and has menace.')
|
||||
assert.equal(equipped.kind, 'static')
|
||||
if (equipped.kind !== 'static') return
|
||||
assert.equal(equipped.condition?.kind, 'source_equipped')
|
||||
assert.equal(equipped.effects[0].op, 'pump')
|
||||
assert.equal(equipped.effects[1].op, 'grant')
|
||||
|
||||
const [enchanted] = creature('As long as this is enchanted, it has flying.')
|
||||
assert.equal(enchanted.kind, 'static')
|
||||
if (enchanted.kind !== 'static') return
|
||||
assert.equal(enchanted.condition?.kind, 'source_enchanted')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user