From 585f33b856345264b258df932c4412a445c178f9 Mon Sep 17 00:00:00 2001 From: hypercross Date: Wed, 22 Apr 2026 00:24:25 +0800 Subject: [PATCH] test: add encounter fixture and complex schema test case --- src/csv-loader/fixtures/encounter.csv | 7 +++ .../tests/parseCsv-combinators.test.ts | 56 ++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/csv-loader/fixtures/encounter.csv diff --git a/src/csv-loader/fixtures/encounter.csv b/src/csv-loader/fixtures/encounter.csv new file mode 100644 index 0000000..a12f429 --- /dev/null +++ b/src/csv-loader/fixtures/encounter.csv @@ -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]]], diff --git a/src/csv-loader/tests/parseCsv-combinators.test.ts b/src/csv-loader/tests/parseCsv-combinators.test.ts index 4b10875..50b7e66 100644 --- a/src/csv-loader/tests/parseCsv-combinators.test.ts +++ b/src/csv-loader/tests/parseCsv-combinators.test.ts @@ -1,7 +1,7 @@ import { describe, it, expect } from "vitest"; import { parseCsv } from "../loader"; import * as path from "path"; -import { fixturesDir } from "../test-utils"; +import { fixturesDir, readFixture } from "../test-utils"; describe("parseCsv - references in combinatory schemas", () => { it("should resolve reference inside a tuple", () => { @@ -161,4 +161,58 @@ describe("parseCsv - references in combinatory schemas", () => { }); 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 }, + ], + }); + }); });