|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { |
| 3 | + buildValueVariableKey, |
| 4 | + parseValueToken, |
| 5 | +} from "./valueSyntax"; |
| 6 | + |
| 7 | +describe("parseValueToken", () => { |
| 8 | + it("ignores empty label values", () => { |
| 9 | + const parsed = parseValueToken("title|label:"); |
| 10 | + expect(parsed).not.toBeNull(); |
| 11 | + expect(parsed?.label).toBeUndefined(); |
| 12 | + expect(parsed?.variableKey).toBe("title"); |
| 13 | + }); |
| 14 | + |
| 15 | + it("uses the last label when multiple are provided", () => { |
| 16 | + const parsed = parseValueToken("title|label:First|label:Second"); |
| 17 | + expect(parsed?.label).toBe("Second"); |
| 18 | + }); |
| 19 | + |
| 20 | + it("scopes list variables by label", () => { |
| 21 | + const parsed = parseValueToken("a,b|label:Priority"); |
| 22 | + expect(parsed?.hasOptions).toBe(true); |
| 23 | + const expectedKey = buildValueVariableKey("a,b", "Priority", true); |
| 24 | + expect(parsed?.variableKey).toBe(expectedKey); |
| 25 | + }); |
| 26 | + |
| 27 | + it("treats bare label option as legacy default", () => { |
| 28 | + const parsed = parseValueToken("title|label"); |
| 29 | + expect(parsed?.label).toBeUndefined(); |
| 30 | + expect(parsed?.defaultValue).toBe("label"); |
| 31 | + }); |
| 32 | + |
| 33 | + it("parses custom boolean values", () => { |
| 34 | + expect(parseValueToken("a,b|custom:")?.allowCustomInput).toBe(true); |
| 35 | + expect(parseValueToken("a,b|custom:false")?.allowCustomInput).toBe(false); |
| 36 | + expect(parseValueToken("a,b|custom:0")?.allowCustomInput).toBe(false); |
| 37 | + }); |
| 38 | + |
| 39 | + it("allows custom plus explicit default", () => { |
| 40 | + const parsed = parseValueToken("a,b|custom|default:High"); |
| 41 | + expect(parsed?.allowCustomInput).toBe(true); |
| 42 | + expect(parsed?.defaultValue).toBe("High"); |
| 43 | + }); |
| 44 | +}); |
0 commit comments