test: add encounter fixture and complex schema test case

This commit is contained in:
hypercross 2026-04-22 00:24:25 +08:00
parent 721544e7b2
commit 585f33b856
2 changed files with 62 additions and 1 deletions

View File

@ -0,0 +1,7 @@
# type EncounterType = 'minion'|'elite'|'event'|'shop'|'camp'|'curio'
# type EnemyList = [name: string; hp: int; effects: [effect: string;stacks: int][]][]
id,type,name,description,enemies,dialogue
string,EncounterType,string,string,EnemyList,string
cactus_pair,minion,仙人掌怪,概念:防+强化。【尖刺X】对攻击者造成X点伤害。,[仙人掌怪;12;[]];[仙人掌怪;12;[]],
snake_pair,minion,蛇,概念:攻+强化。给玩家塞入蛇毒牌1费打出时移除此牌。弃掉时受到3点伤害。,[蛇;10;[[poison;2];[quick;1]]],
1 # type EncounterType = 'minion'|'elite'|'event'|'shop'|'camp'|'curio'
2 # type EnemyList = [name: string; hp: int; effects: [effect: string;stacks: int][]][]
3 id,type,name,description,enemies,dialogue
4 string,EncounterType,string,string,EnemyList,string
5 cactus_pair,minion,仙人掌怪,概念:防+强化。【尖刺X】:对攻击者造成X点伤害。,[仙人掌怪;12;[]];[仙人掌怪;12;[]],
6 snake_pair,minion,蛇,概念:攻+强化。给玩家塞入蛇毒牌(1费:打出时移除此牌。弃掉时受到3点伤害)。,[蛇;10;[[poison;2];[quick;1]]],

View File

@ -1,7 +1,7 @@
import { describe, it, expect } from "vitest"; import { describe, it, expect } from "vitest";
import { parseCsv } from "../loader"; import { parseCsv } from "../loader";
import * as path from "path"; import * as path from "path";
import { fixturesDir } from "../test-utils"; import { fixturesDir, readFixture } from "../test-utils";
describe("parseCsv - references in combinatory schemas", () => { describe("parseCsv - references in combinatory schemas", () => {
it("should resolve reference inside a tuple", () => { it("should resolve reference inside a tuple", () => {
@ -161,4 +161,58 @@ describe("parseCsv - references in combinatory schemas", () => {
}); });
expect(details[1]).toBe(5); expect(details[1]).toBe(5);
}); });
it("should parse encounter fixture with custom type aliases and nested tuples/arrays", () => {
const encounterCsv = readFixture("encounter.csv");
const result = parseCsv(encounterCsv, {
emitTypes: false,
currentFilePath: path.join(fixturesDir, "encounter.csv"),
});
expect(result.data).toHaveLength(2);
// First row: cactus_pair
expect(result.data[0]).toMatchObject({
id: "cactus_pair",
type: "minion",
name: "仙人掌怪",
description: "概念:防+强化。【尖刺X】对攻击者造成X点伤害。",
dialogue: "",
});
const cactusEnemies = result.data[0].enemies as unknown[];
expect(cactusEnemies).toHaveLength(2);
expect(cactusEnemies[0]).toEqual({
name: "仙人掌怪",
hp: 12,
effects: [],
});
expect(cactusEnemies[1]).toEqual({
name: "仙人掌怪",
hp: 12,
effects: [],
});
// Second row: snake_pair
expect(result.data[1]).toMatchObject({
id: "snake_pair",
type: "minion",
name: "蛇",
description:
"概念:攻+强化。给玩家塞入蛇毒牌1费打出时移除此牌。弃掉时受到3点伤害。",
dialogue: "",
});
const snakeEnemies = result.data[1].enemies as unknown[];
expect(snakeEnemies).toHaveLength(1);
expect(snakeEnemies[0]).toEqual({
name: "蛇",
hp: 10,
effects: [
{ effect: "poison", stacks: 2 },
{ effect: "quick", stacks: 1 },
],
});
});
}); });