From 4e7dc3898e5cac5d5cf78687c25dcc0a342e7d9e Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Mon, 13 Jan 2025 19:55:37 +0200 Subject: Add more test cases --- src/serializers/to_object.test.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/serializers/to_object.test.ts') diff --git a/src/serializers/to_object.test.ts b/src/serializers/to_object.test.ts index 9f13987..24fc54f 100644 --- a/src/serializers/to_object.test.ts +++ b/src/serializers/to_object.test.ts @@ -55,3 +55,37 @@ test("Simple function usage", () => { a: "VALUE", }); }); + +test("Piped function by reference usage", () => { + class ToUpper implements FlatMatterFn { + name = "to-upper"; + + compute(input: string): unknown { + return input.toUpperCase(); + } + } + + const fm = new FlatMatter('a: "value" / to-upper', [new ToUpper()]); + const config = fm.serialize(new ToObject()); + + expect(config).toStrictEqual({ + a: "VALUE", + }); +}); + +test("Piped function by call usage", () => { + class ToUpper implements FlatMatterFn { + name = "to-upper"; + + compute(input: string, additional: number): unknown { + return `${input.toUpperCase()}-${additional}`; + } + } + + const fm = new FlatMatter('a: "value" / (to-upper 123)', [new ToUpper()]); + const config = fm.serialize(new ToObject()); + + expect(config).toStrictEqual({ + a: "VALUE-123", + }); +}); \ No newline at end of file -- cgit v1.2.3