Skip to content

Commit

Permalink
Merge pull request #809 from plural/some-small-test-cleanups
Browse files Browse the repository at this point in the history
Small formatting and error improvements for tests.
  • Loading branch information
plural authored Feb 9, 2024
2 parents d7fd1f6 + d1f8943 commit aac0af4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 41 deletions.
66 changes: 34 additions & 32 deletions test/validate_v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('Packs', () => {
it('packs have valid cycle codes', () => {
const cycleCodes = new Set<string>(getCyclesJson().map(a => a.code));
packs.forEach(pack => {
expect(cycleCodes).to.include(pack.cycle_code, `Pack ${pack.name} has bad cycle ${pack.cycle_code}`);
expect(cycleCodes).to.include(pack.cycle_code, `Pack ${pack.name} has bad cycle ${pack.cycle_code}`);
});
});
});
Expand All @@ -74,7 +74,7 @@ describe('Rotations', () => {
const cycleCodes = new Set<string>(getCyclesJson().map(a => a.code));
rotations.forEach(rotation => {
rotation.rotated.forEach(cycle_code => {
expect(cycleCodes).to.include(cycle_code, `Rotation ${rotation.name} has bad cycle ${cycle_code}`);
expect(cycleCodes).to.include(cycle_code, `Rotation ${rotation.name} has bad cycle ${cycle_code}`);
});
});
});
Expand All @@ -99,7 +99,7 @@ describe('Cards', () => {
it('cards have valid pack codes', () => {
const packCodes = new Set<string>(getPacksJson().map(a => a.code));
cards.forEach(card => {
expect(packCodes).to.include(card.pack_code, `Card ${card.title} has bad pack ${card.pack_code}`);
expect(packCodes).to.include(card.pack_code, `Card ${card.title} has bad pack ${card.pack_code}`);
});
});

Expand All @@ -113,40 +113,42 @@ describe('Cards', () => {
}
set.add(getter(card));
});

map.forEach((set, title) => {
expect(set.size).to.equal(1, `card ${title} has varying ${attribute} across printings:\n\t${Array.from(set).join('\n\t')}`);
if (set.size > 1) {
expect.fail(`card ${title} has varying ${attribute} across printings:\n\t${Array.from(set).join('\n\t')}`)
}
});
}

it('cards with multiple printings have identical required attributes', () => {
validateAttributeAcrossPrintings(cards, 'advancement_cost', function(card) { return card.advancement_cost });
validateAttributeAcrossPrintings(cards, 'agenda_points', function(card) { return card.agenda_points });
validateAttributeAcrossPrintings(cards, 'base_link', function(card) { return card.base_link });
validateAttributeAcrossPrintings(cards, 'cost', function(card) { return card.cost });
validateAttributeAcrossPrintings(cards, 'deck_limit', function(card) { return card.deck_limit });
validateAttributeAcrossPrintings(cards, 'faction_code', function(card) { return card.faction_code });
validateAttributeAcrossPrintings(cards, 'faction_cost', function(card) { return card.faction_cost });
validateAttributeAcrossPrintings(cards, 'influence_limit', function(card) { return card.influence_limit });
validateAttributeAcrossPrintings(cards, 'keywords', function(card) { return card.keywords });
validateAttributeAcrossPrintings(cards, 'memory_cost', function(card) { return card.memory_cost });
validateAttributeAcrossPrintings(cards, 'minimum_deck_size', function(card) { return card.minimum_deck_size });
validateAttributeAcrossPrintings(cards, 'side_code', function(card) { return card.side_code });
validateAttributeAcrossPrintings(cards, 'strength', function(card) { return card.strength });
validateAttributeAcrossPrintings(cards, 'stripped_text', function(card) { return card.stripped_text });
validateAttributeAcrossPrintings(cards, 'stripped_title', function(card) { return card.stripped_title });
validateAttributeAcrossPrintings(cards, 'text', function(card) { return card.text });
validateAttributeAcrossPrintings(cards, 'trash_cost', function(card) { return card.trash_cost });
validateAttributeAcrossPrintings(cards, 'type_code', function(card) { return card.type_code });
validateAttributeAcrossPrintings(cards, 'type_uniqueness', function(card) { return card.type_uniqueness });
validateAttributeAcrossPrintings(cards, 'advancement_cost', function (card) { return card.advancement_cost });
validateAttributeAcrossPrintings(cards, 'agenda_points', function (card) { return card.agenda_points });
validateAttributeAcrossPrintings(cards, 'base_link', function (card) { return card.base_link });
validateAttributeAcrossPrintings(cards, 'cost', function (card) { return card.cost });
validateAttributeAcrossPrintings(cards, 'deck_limit', function (card) { return card.deck_limit });
validateAttributeAcrossPrintings(cards, 'faction_code', function (card) { return card.faction_code });
validateAttributeAcrossPrintings(cards, 'faction_cost', function (card) { return card.faction_cost });
validateAttributeAcrossPrintings(cards, 'influence_limit', function (card) { return card.influence_limit });
validateAttributeAcrossPrintings(cards, 'keywords', function (card) { return card.keywords });
validateAttributeAcrossPrintings(cards, 'memory_cost', function (card) { return card.memory_cost });
validateAttributeAcrossPrintings(cards, 'minimum_deck_size', function (card) { return card.minimum_deck_size });
validateAttributeAcrossPrintings(cards, 'side_code', function (card) { return card.side_code });
validateAttributeAcrossPrintings(cards, 'strength', function (card) { return card.strength });
validateAttributeAcrossPrintings(cards, 'stripped_text', function (card) { return card.stripped_text });
validateAttributeAcrossPrintings(cards, 'stripped_title', function (card) { return card.stripped_title });
validateAttributeAcrossPrintings(cards, 'text', function (card) { return card.text });
validateAttributeAcrossPrintings(cards, 'trash_cost', function (card) { return card.trash_cost });
validateAttributeAcrossPrintings(cards, 'type_code', function (card) { return card.type_code });
validateAttributeAcrossPrintings(cards, 'type_uniqueness', function (card) { return card.type_uniqueness });
});

it('stripped text and title are ascii only', () => {
cards.forEach(card => {
if (card.text) {
expect(card.stripped_text, `${card.title} stripped_text missing`).to.exist;
expect(card.stripped_text, `${card.title} stripped_text missing`).to.exist;
expect(card.stripped_text, `${card.title} stripped_text should be ascii only`).to.equal(
Buffer.from(card.stripped_text.toString()).toString("ascii"));
Buffer.from(card.stripped_text.toString()).toString("ascii"));
}
expect(card.stripped_title, `${card.title} stripped_title should be ascii only`).to.equal(
Buffer.from(card.stripped_title.toString()).toString("ascii"));
Expand All @@ -159,12 +161,12 @@ describe('Cards', () => {
const textMatches = card.text.match(/Interface(..)?/g);
for (const m in textMatches) {
expect(textMatches[m], `${card.title} has incorrect interface formatting in text`)
.to.equal('Interface →');
.to.equal('Interface →');
}
const strippedTextMatches = card.stripped_text.match(/Interface(...)?/g);
for (const m in strippedTextMatches) {
expect(strippedTextMatches[m], `${card.title} has incorrect interface formatting in stripped_text`)
.to.equal('Interface ->');
.to.equal('Interface ->');
}
}
});
Expand All @@ -176,12 +178,12 @@ describe('Cards', () => {
const textMatches = card.text.match(/\[interrupt\](..)?/g);
for (const m in textMatches) {
expect(textMatches[m], `${card.title} has incorrect interrupt formatting in text`)
.to.equal('[interrupt] →');
.to.equal('[interrupt] →');
}
const strippedTextMatches = card.stripped_text.match(/Interrupt(...)?/gi);
for (const m in strippedTextMatches) {
expect(strippedTextMatches[m], `${card.title} has incorrect interrupt formatting in stripped_text`)
.to.equal('Interrupt ->');
.to.equal('Interrupt ->');
}
}
});
Expand Down Expand Up @@ -225,13 +227,13 @@ describe('Translations', () => {
describe('Prebuilts', () => {
it('prebuilts.json is correct JSON', () => {
const prebuilts = getPrebuiltsJson();
expect(prebuilts).to.exist;
expect(prebuilts).to.exist;
});
});

describe('Mwl', () => {
it('mwl.json is correct JSON', () => {
const mwl = getMwlJson();
expect(mwl).to.exist;
expect(mwl).to.exist;
});
});
3 changes: 3 additions & 0 deletions test/validate_v1_v2_equality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,10 @@ describe('Printings v1/v2 equality', () => {
return;
}
const v2Printing = printingsById.get(v1.code);
expect(v2Printing, `Could not find v2 printing with code ${v1.code}`);
const v2Card = v2CardsByTitle.get(v1.title);
expect(v2Card !== undefined, `Could not find v2 card with title ${v1.title}`);

let v2Flavor = v2Printing.faces ? [v2Printing.flavor].concat(v2Printing.faces.map(s => s.flavor)).filter(f => !!f).join('\n') : v2Printing.flavor;
if (!v2Flavor) {
v2Flavor = v2Printing.flavor;
Expand Down
18 changes: 9 additions & 9 deletions test/validate_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe('SetTypes', () => {
});

it('cardSetTypes have proper name/id format', () => {
cardSetTypes.forEach(function(st) {
cardSetTypes.forEach(function (st) {
expect(st.id).to.equal(st.name.toLowerCase().replaceAll(' ', '_'));
});
});
Expand All @@ -128,7 +128,7 @@ describe('Types', () => {
});

it('cardTypes have proper name/id format', () => {
cardTypes.forEach(function(t) {
cardTypes.forEach(function (t) {
expect(t.id).to.equal(textToId(t.name));
});
});
Expand All @@ -141,7 +141,7 @@ describe('Card Subtypes', () => {
});

it('subtypes have proper name/id format', () => {
subtypes.forEach(function(s) {
subtypes.forEach(function (s) {
expect(s.id).to.equal(textToId(s.name));
});
});
Expand All @@ -161,7 +161,7 @@ describe('Card Sets', () => {

it('has valid cycle ids', () => {
cardSets.forEach(s => {
expect(cardCycleIds, `Card set ${s.name} has invalid card_cycle_id ${s.card_cycle_id}`).to.include(s.card_cycle_id);
expect(cardCycleIds, `Card set ${s.name} has invalid card_cycle_id ${s.card_cycle_id}`).to.include(s.card_cycle_id);
});
});
});
Expand Down Expand Up @@ -218,7 +218,7 @@ describe('Printings', () => {
});

it('printing files have valid ids', () => {
const printingIds = new Set<string>();
const printingIds = new Set<string>();
printingsByFilename.forEach((printing, file) => {
const positions = new Set<number>();

Expand Down Expand Up @@ -355,7 +355,7 @@ describe('Card Pools', () => {
cardSetsByCycleId.get(set.card_cycle_id)?.add(set.id);
});
cardPoolsByFilename.forEach((cardPool, file) => {
cardPool.forEach(p => {
cardPool.forEach(p => {
p.card_cycle_ids?.forEach(card_cycle_id => {
cardSetsByCycleId.get(card_cycle_id)?.forEach(card_set_id => {
expect(p.card_set_ids, `card_set_ids for card pool ${p.id} in ${file} should have set ${card_set_id} for cycle ${card_cycle_id}`).includes(card_set_id);
Expand Down Expand Up @@ -471,7 +471,7 @@ describe('Restrictions', () => {
if ('restricted' in restriction) {
expect(restriction.restricted, `restricted list should be sorted for restriction ${restriction.name} in ${file}`).to.deep.equal(restriction.restricted.map((e) => e).sort());
}
});
});
});
});

Expand Down Expand Up @@ -504,8 +504,8 @@ describe('Formats', () => {
for (const format of formatsByFilename.values()) {
const dateStart = new Set<string>();
format.snapshots.forEach(s => {
expect(dateStart, `Format ${format.name} has a snapshot with a duplicate date_start: ${s.date_start}.`).to.not.include(s.date_start);
dateStart.add(s.date_start);
expect(dateStart, `Format ${format.name} has a snapshot with a duplicate date_start: ${s.date_start}.`).to.not.include(s.date_start);
dateStart.add(s.date_start);
});
}
});
Expand Down

0 comments on commit aac0af4

Please sign in to comment.