summaryrefslogtreecommitdiff
path: root/src/serializers/to_object.test.ts
diff options
context:
space:
mode:
authorAsko Nõmm <asko@nmm.ee>2025-01-13 20:49:44 +0200
committerAsko Nõmm <asko@nmm.ee>2025-01-13 20:49:44 +0200
commit164c26c2f0525078352b3b3cd9b039e618ec6712 (patch)
treec77fd18ee91b622f9a71e5fdde9cc87e19d73d79 /src/serializers/to_object.test.ts
parent4e7dc3898e5cac5d5cf78687c25dcc0a342e7d9e (diff)
Add a lot of test coverage
Diffstat (limited to 'src/serializers/to_object.test.ts')
-rw-r--r--src/serializers/to_object.test.ts83
1 files changed, 79 insertions, 4 deletions
diff --git a/src/serializers/to_object.test.ts b/src/serializers/to_object.test.ts
index 24fc54f..7059458 100644
--- a/src/serializers/to_object.test.ts
+++ b/src/serializers/to_object.test.ts
@@ -48,7 +48,7 @@ test("Simple function usage", () => {
}
}
- const fm = new FlatMatter('a: (to-upper "value")', [new ToUpper()]);
+ const fm = new FlatMatter('a: (to-upper "value")', [new ToUpper]);
const config = fm.serialize(new ToObject());
expect(config).toStrictEqual({
@@ -65,7 +65,7 @@ test("Piped function by reference usage", () => {
}
}
- const fm = new FlatMatter('a: "value" / to-upper', [new ToUpper()]);
+ const fm = new FlatMatter('a: "value" / to-upper', [new ToUpper]);
const config = fm.serialize(new ToObject());
expect(config).toStrictEqual({
@@ -82,10 +82,85 @@ test("Piped function by call usage", () => {
}
}
- const fm = new FlatMatter('a: "value" / (to-upper 123)', [new ToUpper()]);
+ 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
+});
+
+test("Invalid value in pipe", () => {
+ const fm = new FlatMatter('a: "value" / / asd');
+ const config = fm.serialize(new ToObject());
+
+ expect(config).toStrictEqual({});
+})
+
+test("Invalid value in pipe, 2", () => {
+ const fm = new FlatMatter('a: "value" / asd');
+ const config = fm.serialize(new ToObject());
+
+ expect(config).toStrictEqual({
+ a: "value"
+ });
+})
+
+test("Only piped functions", () => {
+ class FirstFn implements FlatMatterFn {
+ name = "first-fn";
+
+ compute(input: string): unknown {
+ return input.toUpperCase();
+ }
+ }
+
+ class SecondFn implements FlatMatterFn {
+ name = "second-fn";
+
+ compute(input: string): unknown {
+ return `${input}-passed-by-second`;
+ }
+ }
+
+ const fm = new FlatMatter('a: (first-fn "value / here") / second-fn', [new FirstFn, new SecondFn]);
+ const config = fm.serialize(new ToObject());
+
+ expect(config).toStrictEqual({
+ a: "VALUE / HERE-passed-by-second"
+ });
+});
+
+test("Function call without any args", () => {
+ 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("Function call using multiple strings with spaces as arg", () => {
+ class ToUpper implements FlatMatterFn {
+ name = "to-upper";
+
+ compute(input: string): unknown {
+ return input.toUpperCase();
+ }
+ }
+
+ const fm = new FlatMatter('a: (to-upper "value goes here" "and here")', [new ToUpper]);
+ const config = fm.serialize(new ToObject());
+
+ expect(config).toStrictEqual({
+ a: "VALUE GOES HERE",
+ });
+}) \ No newline at end of file