-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TS - add map, match, matchall, math, max, min function
- Loading branch information
Showing
17 changed files
with
1,068 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
javascript/json-transform/src/__tests__/functions/TransformerFunctionMap.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { describe, test } from "vitest"; | ||
import { assertTransformation } from "../BaseTransformationTest"; | ||
|
||
describe("TransformerFunctionMap", () => { | ||
test("testObjectFunctionMap", async () => { | ||
const source = { | ||
value: 5, | ||
item: { | ||
foo: "aaa", | ||
id: "bbb", | ||
}, | ||
items: [ | ||
{ foo: "bar", id: "aaa" }, | ||
{ foo: "bar2", id: "bbb" }, | ||
], | ||
}; | ||
await assertTransformation( | ||
source, | ||
{ | ||
$$map: [ | ||
"$.items", | ||
{ | ||
id: "##current.id", | ||
map_foo: "##current.foo", | ||
idx: "##index", | ||
value: "$.value", | ||
}, | ||
], | ||
}, | ||
[ | ||
{ id: "aaa", map_foo: "bar", idx: 0, value: 5 }, | ||
{ id: "bbb", map_foo: "bar2", idx: 1, value: 5 }, | ||
], | ||
); | ||
|
||
await assertTransformation( | ||
source, | ||
{ | ||
$$map: "$.items", | ||
to: { | ||
id: "##current.id", | ||
map_foo: "##current.foo", | ||
idx: "##index", | ||
value: "$.value", | ||
}, | ||
}, | ||
[ | ||
{ id: "aaa", map_foo: "bar", idx: 0, value: 5 }, | ||
{ id: "bbb", map_foo: "bar2", idx: 1, value: 5 }, | ||
], | ||
); | ||
|
||
var valueLookup = { | ||
$$map: [ | ||
"$.item", | ||
{ | ||
id: "##current.id", | ||
map_foo: "##current.foo", | ||
idx: "##index", | ||
value: "$.value", | ||
}, | ||
], | ||
}; | ||
await assertTransformation(source, valueLookup, null); | ||
}); | ||
|
||
test("objectNonTransformed", async () => { | ||
await assertTransformation( | ||
{ | ||
a: [1, 2], | ||
b: [2, 4], | ||
}, | ||
{ | ||
$$map: [["$.a", "$.b"], "##current[1]"], | ||
}, | ||
[2, 4], | ||
); | ||
}); | ||
|
||
test("inline", async () => { | ||
await assertTransformation([{ a: 10 }, { a: 11 }, { a: 12 }], "$$map(##current.a):$", [10, 11, 12]); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
javascript/json-transform/src/__tests__/functions/TransformerFunctionMatch.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { describe, test } from "vitest"; | ||
import { assertTransformation } from "../BaseTransformationTest"; | ||
|
||
describe("TransformerFunctionMatch", () => { | ||
test("inline", async () => { | ||
const input = "hello"; | ||
await assertTransformation(input, "$$match([le]):$", "e"); | ||
await assertTransformation(input, "$$match([le]+):$", "ell"); | ||
await assertTransformation(input, "$$match(hell):$", "hell"); | ||
await assertTransformation(input, "$$match(hello$):$", "hello"); | ||
await assertTransformation(input, "$$match(hell$):$", null); | ||
}); | ||
|
||
test("inlineGroup", async () => { | ||
await assertTransformation("world", "$$match('w(\\\\w+)d',1):$", "orl"); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
javascript/json-transform/src/__tests__/functions/TransformerFunctionMatchAll.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { describe, test } from "vitest"; | ||
import { assertTransformation } from "../BaseTransformationTest"; | ||
|
||
describe("TransformerFunctionMatchAll", () => { | ||
test("inline", async () => { | ||
const input = "hello my helloKitty"; | ||
await assertTransformation(input, "$$matchall([el]):$", ["e", "l", "l", "e", "l", "l"]); | ||
await assertTransformation(input, "$$matchall([le]+):$", ["ell", "ell"]); | ||
await assertTransformation(input, "$$matchall(hell):$", ["hell", "hell"]); | ||
await assertTransformation(input, "$$matchall(^hello):$", ["hello"]); | ||
await assertTransformation(input, "$$matchall(hello$):$", null); | ||
}); | ||
|
||
test("inlineGroup", async () => { | ||
await assertTransformation("world to waterWorld", "$$matchall('w(\\\\w+)d',1):$", ["orl", "aterWorl"]); | ||
}); | ||
}); |
Oops, something went wrong.