diff --git a/src/csv-loader/tests/parseCsv-typeDeclarations.test.ts b/src/csv-loader/tests/parseCsv-typeDeclarations.test.ts index b2ed968..4070eb9 100644 --- a/src/csv-loader/tests/parseCsv-typeDeclarations.test.ts +++ b/src/csv-loader/tests/parseCsv-typeDeclarations.test.ts @@ -201,6 +201,54 @@ describe("parseCsv - type declarations", () => { // Column should use the declared type name, not expanded union expect(result.typeDefinition).toContain("readonly trigger: Trigger;"); }); + + it("should expand custom type names inside tuples and arrays", () => { + const csv = [ + "# type IntentEffectTarget = 'user' | 'eachEnemy' | 'randomEnemy' | 'player'", + "# type IntentEffect = [IntentEffectTarget; string; int]", + "# type IntentEffects = IntentEffect[]", + "id,effects", + "string,IntentEffects", + "boost,[user;spike;1];[user;defend;4]", + ].join("\n"); + + const result = parseCsv(csv, { emitTypes: false }); + + expect(result.typeDeclarations).toHaveLength(3); + const intentEffect = result.typeDeclarations.find( + (d) => d.name === "IntentEffect", + )!; + expect(intentEffect.schema.type).toBe("tuple"); + // First element should be resolved to union, not a string "IntentEffectTarget" + const firstEl = ( + intentEffect.schema as { elements: { schema: { type: string } }[] } + ).elements[0].schema; + expect(firstEl.type).toBe("union"); + }); + + it("should use declared type names in generated type definition for tuple arrays", () => { + const csv = [ + "# type IntentEffectTarget = 'user' | 'eachEnemy' | 'randomEnemy' | 'player'", + "# type IntentEffect = [IntentEffectTarget; string; int]", + "# type IntentEffects = IntentEffect[]", + "id,effects", + "string,IntentEffects", + "boost,[user;spike;1];[user;defend;4]", + ].join("\n"); + + const result = parseCsv(csv, { + emitTypes: true, + resourceName: "intent", + currentFilePath: path.join(fixturesDir, "intent.csv"), + }); + + expect(result.typeDefinition).toContain("type IntentEffectTarget ="); + expect(result.typeDefinition).toContain("type IntentEffect ="); + expect(result.typeDefinition).toContain("type IntentEffects ="); + + // Column should reference IntentEffects, not inline expansion + expect(result.typeDefinition).toContain("readonly effects: IntentEffects;"); + }); }); describe("parseCsv - type declarations with resolveReferences: false", () => {