93 lines
3.2 KiB
TypeScript
93 lines
3.2 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
import type { Card } from '../src/cards.js'
|
|
import { matchesCardFilters } from '../src/cards.js'
|
|
import { cardDefinitionFromCard } from '../src/game/catalog.js'
|
|
|
|
function card(overrides: Partial<Card> = {}): Card {
|
|
return {
|
|
oracle_id: 'test',
|
|
name: 'Test Card',
|
|
layout: 'normal',
|
|
cmc: 3,
|
|
type_line: 'Legendary Creature — Human',
|
|
colors: ['G', 'U'],
|
|
color_identity: ['G', 'U'],
|
|
keywords: [],
|
|
rarity: 'rare',
|
|
legal_formats: ['commander', 'legacy'],
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
const cardByIdentity = card({ color_identity: ['G', 'U'] })
|
|
|
|
test('card filters match format legality, color identity, type, rarity, and mana value', () => {
|
|
assert.equal(matchesCardFilters(cardByIdentity, { format: 'legacy' }), true)
|
|
assert.equal(matchesCardFilters(cardByIdentity, { format: 'standard' }), false)
|
|
assert.equal(matchesCardFilters(cardByIdentity, {}), true)
|
|
|
|
assert.equal(matchesCardFilters(cardByIdentity, { color: 'U' }), true)
|
|
assert.equal(matchesCardFilters(cardByIdentity, { color: 'M' }), true)
|
|
assert.equal(matchesCardFilters(cardByIdentity, { color: 'C' }), false)
|
|
assert.equal(matchesCardFilters(card({ color_identity: [] }), { color: 'C' }), true)
|
|
|
|
assert.equal(matchesCardFilters(cardByIdentity, { type: 'legendary' }), true)
|
|
assert.equal(matchesCardFilters(cardByIdentity, { type: 'creature' }), true)
|
|
assert.equal(matchesCardFilters(cardByIdentity, { type: 'land' }), false)
|
|
|
|
const modalCard = card({
|
|
type_line: 'Sorcery',
|
|
card_faces: [
|
|
{ name: 'Front', type_line: 'Sorcery', colors: [] },
|
|
{ name: 'Back', type_line: 'Land', colors: [] },
|
|
],
|
|
})
|
|
assert.equal(matchesCardFilters(modalCard, { type: 'land' }), true)
|
|
|
|
assert.equal(matchesCardFilters(cardByIdentity, { rarity: 'rare' }), true)
|
|
assert.equal(matchesCardFilters(cardByIdentity, { rarity: 'common' }), false)
|
|
|
|
assert.equal(matchesCardFilters(cardByIdentity, { cmcMin: 3, cmcMax: 3 }), true)
|
|
assert.equal(matchesCardFilters(cardByIdentity, { cmcMin: 4 }), false)
|
|
assert.equal(matchesCardFilters(cardByIdentity, { cmcMax: 2 }), false)
|
|
})
|
|
|
|
test('compiled card types reach the engine definition', () => {
|
|
const definition = cardDefinitionFromCard(card(), {
|
|
oracle_id: 'test',
|
|
name: 'Test Card',
|
|
typeLine: 'Artifact Creature — Golem',
|
|
status: 'supported',
|
|
abilities: [],
|
|
})
|
|
assert.equal(definition.typeLine, 'Artifact Creature — Golem')
|
|
})
|
|
|
|
test('lands with basic land types get one intrinsic mana ability for their colors', () => {
|
|
const vents = cardDefinitionFromCard(card({
|
|
name: 'Steam Vents',
|
|
type_line: 'Land — Island Mountain',
|
|
colors: [],
|
|
color_identity: ['U', 'R'],
|
|
}))
|
|
assert.deepEqual(vents.abilities, [{
|
|
kind: 'activated',
|
|
costs: [{ kind: 'tap' }],
|
|
effects: [{
|
|
op: 'add_mana',
|
|
player: 'you',
|
|
mana: { kind: 'symbols', symbols: ['{U}', '{R}'], oneOf: true },
|
|
}],
|
|
optional: false,
|
|
text: '{T}: Add {U} or {R}.',
|
|
}])
|
|
|
|
const forest = cardDefinitionFromCard(card({ name: 'Forest', type_line: 'Basic Land — Forest' }))
|
|
assert.deepEqual(forest.abilities?.[0]?.effects, [{
|
|
op: 'add_mana',
|
|
player: 'you',
|
|
mana: { kind: 'symbols', symbols: ['{G}'] },
|
|
}])
|
|
})
|