-
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 normalize, not, numberformat, numberparse, object, or, pad, …
…partition functions
- Loading branch information
Showing
22 changed files
with
948 additions
and
17 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
50 changes: 50 additions & 0 deletions
50
javascript/json-transform/src/__tests__/functions/TransformerFunctionNormalize.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,50 @@ | ||
import { describe, test } from "vitest"; | ||
import { assertTransformation } from "../BaseTransformationTest"; | ||
|
||
describe("TransformerFunctionNormalize", () => { | ||
test("inline", async () => { | ||
var strVal = "Tĥïŝ ĩš â fůňķŷ Šťŕĭńġ abcABC…"; | ||
await assertTransformation(strVal, "$$normalize:$", "This is a funky String abcABC..."); | ||
await assertTransformation(strVal, "$$normalize(NFKD):$", "This is a funky String abcABC..."); | ||
await assertTransformation(strVal, "$$normalize(NFKD,NONE):$", "Tĥïŝ ĩš â fůňķŷ Šťŕĭńġ abcABC..."); | ||
await assertTransformation(strVal, "$$normalize(NFD):$", "This is a funky String abcABC…"); | ||
await assertTransformation(strVal, "$$normalize(NFD,NONE):$", "Tĥïŝ ĩš â fůňķŷ Šťŕĭńġ abcABC…"); | ||
|
||
// removeMarks on NFC/NFKC does not affect because marks are composed (and gone) before replacement | ||
await assertTransformation(strVal, "$$normalize(NFKC):$", "Tĥïŝ ĩš â fůňķŷ Šťŕĭńġ abcABC..."); | ||
await assertTransformation(strVal, "$$normalize(NFKC,NONE):$", "Tĥïŝ ĩš â fůňķŷ Šťŕĭńġ abcABC..."); | ||
await assertTransformation(strVal, "$$normalize(NFC):$", strVal); | ||
await assertTransformation(strVal, "$$normalize(NFC,NONE):$", strVal); | ||
}); | ||
|
||
test("unicodeTableBasicLatin", async () => { | ||
var strVal = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; | ||
await assertTransformation(strVal, "$$normalize:$", strVal); | ||
}); | ||
test("unicodeTableLatinExtendedA", async () => { | ||
var strVal = | ||
"ĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſ"; | ||
var expect = | ||
"AaAaAaCcCcCcCcDdDdEeEeEeEeEeGgGgGgGgHhHhIiIiIiIiIıIJijJjKkĸLlLlLlLlLlNnNnNnnNnOoOoOoOEoeRrRrRrSsSsSsSsTtTtTtUuUuUuUuUuUuWwYyYZzZzZzs"; | ||
await assertTransformation(strVal, "$$normalize:$", expect); | ||
}); | ||
|
||
test("unicodeTableLatinExtendedB", async () => { | ||
var strVal = | ||
"ƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴǵǶǷǸǹǺǻǼǽǾǿȀȁȂȃȄȅȆȇȈȉȊȋȌȍȎȏȐȑȒȓȔȕȖȗȘșȚțȜȝȞȟȠȡȢȣȤȥȦȧȨȩȪȫȬȭȮȯȰȱȲȳȴȵȶȷȸȹȺȻȼȽȾȿɀɁɂɃɄɅɆɇɈɉɊɋɌɍɎɏ"; | ||
var expect = | ||
"bBƂƃbbCCcDDƋƌƍƎƏƐFfGƔhƖIKklƛƜƝƞƟOoƢƣPpRSsƩƪtTtƮUuƱƲYyZzƷƸƹƺƻƼƽƾƿǀǁǂǃDZDzdzLJLjljNJNjnjAaIiOoUuUuUuUuUuǝAaAaAEaeGgGgKkOoOoƷʒjDZDzdzGgHpNnAaAEaeOoAaAaEeEeIiIiOoOoRrRrUuUuSsTtȜȝHhȠdȢȣZzAaEeOoOoOoOoYylntȷȸȹACcLTszɁɂBUAEeJjQqRrYy"; | ||
await assertTransformation(strVal, "$$normalize:$", expect); | ||
}); | ||
|
||
test("unicodeTableLatin1Supplement", async () => { | ||
var strVal = "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"; | ||
var expect = "AAAAAAAECEEEEIIIIDNOOOOO×OUUUUYÞßaaaaaaaeceeeeiiiiðnooooo÷ouuuuyþy"; | ||
await assertTransformation(strVal, "$$normalize:$", expect); | ||
}); | ||
test("exceptionsAeOe", async () => { | ||
var strVal = "ŒœÆæǢǣǼǽ"; | ||
var expect = "OEoeAEaeAEaeAEae"; | ||
await assertTransformation(strVal, "$$normalize:$", expect); | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
javascript/json-transform/src/__tests__/functions/TransformerFunctionNot.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,9 @@ | ||
import { describe, test } from "vitest"; | ||
import { assertTransformation } from "../BaseTransformationTest"; | ||
|
||
describe("TransformerFunctionNot", () => { | ||
test("inline", async () => { | ||
await assertTransformation(true, "$$not:$", false); | ||
await assertTransformation(false, "$$not:$", true); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
javascript/json-transform/src/__tests__/functions/TransformerFunctionNumberFormat.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,30 @@ | ||
import { describe, test } from "vitest"; | ||
import { assertTransformation } from "../BaseTransformationTest"; | ||
import { BigDecimal } from "../../functions/common/FunctionHelpers"; | ||
|
||
describe("TransformerFunctionNumberFormat", () => { | ||
test("inline", async () => { | ||
const decimals = "123456789.87654321"; | ||
const val = BigDecimal(decimals); | ||
// must supply type | ||
await assertTransformation(val, "$$numberformat:$", decimals); | ||
await assertTransformation(val, "$$numberformat():$", decimals); | ||
// literal | ||
await assertTransformation(val, "$$numberformat(DECIMAL):$", "123456789.88"); | ||
await assertTransformation(val, "$$numberformat(DECIMAL,en-US,'#,##0.00'):$", "123,456,789.88"); | ||
await assertTransformation(val, "$$numberformat(DECIMAL,en-US,'#,##0.00','.',','):$", "123.456.789,88"); | ||
|
||
// literal | ||
await assertTransformation(val, "$$numberformat(CURRENCY):$", "$123,456,789.88"); | ||
await assertTransformation(val, "$$numberformat(CURRENCY,en-GB,GBP):$", "£123,456,789.88"); | ||
await assertTransformation(val, "$$numberformat(PERCENT):$", "12,345,678,988%"); | ||
await assertTransformation(val, "$$numberformat(INTEGER):$", "123,456,790"); | ||
await assertTransformation(val, "$$numberformat(COMPACT):$", "123M"); | ||
await assertTransformation(val, "$$numberformat(COMPACT,en-US,LONG):$", "123 million"); | ||
await assertTransformation(val, "$$numberformat(COMPACT,he-IL,LONG):$", "\u200F123 מיליון"); | ||
|
||
// BASE | ||
await assertTransformation(val, "$$numberformat(BASE,16):$", "75bcd15"); | ||
await assertTransformation(val, "$$numberformat(BASE,2):$", "111010110111100110100010101"); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
javascript/json-transform/src/__tests__/functions/TransformerFunctionNumberParse.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,23 @@ | ||
import { describe, test } from "vitest"; | ||
import { assertTransformation } from "../BaseTransformationTest"; | ||
import { BigDecimal, DEFAULT_LOCALE } from "../../functions/common/FunctionHelpers"; | ||
|
||
describe("TransformerFunctionNumberParse", () => { | ||
test("inline", async () => { | ||
const decimals = "123456789.88"; | ||
const val = new BigDecimal(decimals); | ||
|
||
await assertTransformation(decimals, "$$numberparse:$", val); | ||
await assertTransformation(decimals, "$$numberparse():$", val); | ||
// literal | ||
await assertTransformation("123,456,789.88", "$$numberparse('#,##0.00'):$", val); | ||
await assertTransformation("123.456.789,88", "$$numberparse('#,##0.00',de):$", val); | ||
await assertTransformation("123.456.789,88", "$$numberparse('#,##0.00',en-US,'.',','):$", val); | ||
|
||
// HEX | ||
const hex = "75bcd15"; | ||
await assertTransformation(hex, "$$numberparse(BASE,16):$", BigDecimal("123456789")); | ||
const binary = "00001010"; | ||
await assertTransformation(binary, "$$numberparse(BASE,2):$", BigDecimal("10")); | ||
}); | ||
}); |
84 changes: 84 additions & 0 deletions
84
javascript/json-transform/src/__tests__/functions/TransformerFunctionObject.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,84 @@ | ||
import { describe, test } from "vitest"; | ||
import { assertTransformation } from "../BaseTransformationTest"; | ||
|
||
describe("TransformerFunctionObject", () => { | ||
test("inline", async () => { | ||
await assertTransformation( | ||
[ | ||
["a", 1], | ||
["b", true], | ||
["c", "C"], | ||
], | ||
"$$object:$", | ||
{ | ||
a: 1, | ||
b: true, | ||
c: "C", | ||
}, | ||
); | ||
await assertTransformation( | ||
[ | ||
[0, 1], | ||
[1, true], | ||
[2, "C"], | ||
], | ||
"$$object:$", | ||
{ 0: 1, 1: true, 2: "C" }, | ||
); | ||
|
||
// invalid input will yield an empty object | ||
await assertTransformation(null, "$$object", {}); | ||
await assertTransformation(0.5, "$$object:$", {}); | ||
await assertTransformation("test", "$$object:$", {}); | ||
await assertTransformation(false, "$$object:$", {}); | ||
}); | ||
|
||
test("object", async () => { | ||
await assertTransformation( | ||
[ | ||
["a", 1], | ||
["b", true], | ||
["c", "C"], | ||
], | ||
|
||
{ $$object: "$" }, | ||
{ | ||
a: 1, | ||
b: true, | ||
c: "C", | ||
}, | ||
); | ||
await assertTransformation( | ||
[ | ||
[0, 1], | ||
[1, true], | ||
[2, "C"], | ||
], | ||
|
||
{ $$object: "$" }, | ||
{ 0: 1, 1: true, 2: "C" }, | ||
); | ||
await assertTransformation(null, { $$object: "$" }, {}); | ||
await assertTransformation(0.5, { $$object: "$" }, {}); | ||
await assertTransformation(false, { $$object: "$" }, {}); | ||
// explicit | ||
|
||
await assertTransformation( | ||
{ | ||
key: 1, | ||
value: true, | ||
}, | ||
{ $$object: [["$.key", "$.value"]] }, | ||
{ 1: true }, | ||
); | ||
|
||
await assertTransformation( | ||
{ | ||
key: "a", | ||
value: 0.5, | ||
}, | ||
{ $$object: [["$.key", "$.value"]] }, | ||
{ a: 0.5 }, | ||
); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
javascript/json-transform/src/__tests__/functions/TransformerFunctionOr.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,25 @@ | ||
import { describe, test } from "vitest"; | ||
import { assertTransformation } from "../BaseTransformationTest"; | ||
|
||
describe("TransformerFunctionOr", () => { | ||
test("assertOr", async () => { | ||
const twoOrThree = { | ||
$$or: [ | ||
{ $$is: "$[0]", eq: 2 }, | ||
{ $$is: "$[1]", eq: 3 }, | ||
], | ||
}; | ||
await assertTransformation([2, 3], twoOrThree, true); | ||
await assertTransformation([1, 3], twoOrThree, true); | ||
await assertTransformation([2, 4], twoOrThree, true); | ||
await assertTransformation([1, 4], twoOrThree, false); | ||
const firstOrSecond = { $$or: ["$[0]", "$[1]"] }; | ||
await assertTransformation([null, 1], firstOrSecond, true); | ||
await assertTransformation([null, null], firstOrSecond, false); | ||
}); | ||
|
||
test("inline", async () => { | ||
await assertTransformation([null, 0], "$$or:$", false); | ||
await assertTransformation([1, 0], "$$or:$", true); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
javascript/json-transform/src/__tests__/functions/TransformerFunctionPad.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,23 @@ | ||
import { describe, test } from "vitest"; | ||
import { assertTransformation } from "../BaseTransformationTest"; | ||
|
||
describe("TransformerFunctionPad", () => { | ||
test("inline", async () => { | ||
const strVal = "text"; | ||
await assertTransformation(strVal, "$$pad(right,3,2):$", strVal); | ||
await assertTransformation(strVal, "$$pad(end,6):" + strVal, strVal + "00"); | ||
await assertTransformation(strVal, "$$pad(end,6):$", strVal + "00"); | ||
await assertTransformation(strVal, "$$pad(right,6,0):$", strVal + "00"); | ||
await assertTransformation(strVal, "$$pad(end,6,' '):$", strVal + " "); | ||
await assertTransformation(strVal, "$$pad(left,6,' '):$", " " + strVal); | ||
await assertTransformation(strVal, "$$pad(left,6,x):$", "xx" + strVal); | ||
await assertTransformation(strVal, "$$pad(start,6,xy):$", "xy" + strVal); | ||
await assertTransformation(strVal, "$$pad(start,9,xy):$", "xyxyx" + strVal); | ||
|
||
// bad inputs | ||
await assertTransformation(strVal, "$$pad:$", strVal); | ||
await assertTransformation(strVal, "$$pad:$", strVal); | ||
await assertTransformation(strVal, "$$pad():$", strVal); | ||
await assertTransformation(strVal, "$$pad(start):$", strVal); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
javascript/json-transform/src/__tests__/functions/TransformerFunctionPartition.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,22 @@ | ||
import { describe, test } from "vitest"; | ||
import { assertTransformation } from "../BaseTransformationTest"; | ||
|
||
describe("TransformerFunctionPartition", () => { | ||
test("inline", async () => { | ||
await assertTransformation([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "$$partition(3):$", [ | ||
[1, 2, 3], | ||
[4, 5, 6], | ||
[7, 8, 9], | ||
[10], | ||
]); | ||
}); | ||
|
||
test("object", async () => { | ||
await assertTransformation([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], { $$partition: "$", size: 3 }, [ | ||
[1, 2, 3], | ||
[4, 5, 6], | ||
[7, 8, 9], | ||
[10], | ||
]); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
javascript/json-transform/src/__tests__/functions/TransformerFunctionTest.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,16 @@ | ||
import { describe, test } from "vitest"; | ||
import { assertTransformation } from "../BaseTransformationTest"; | ||
|
||
describe("TransformerFunctionTest", () => { | ||
test("inline", async () => { | ||
const input = "hello"; | ||
await assertTransformation(input, "$$test([le]):$", true); | ||
await assertTransformation(input, "$$test(hell):$", true); | ||
await assertTransformation(input, "$$test(hello$):$", true); | ||
await assertTransformation(input, "$$test(hell$):$", false); | ||
await assertTransformation(input, "$$test('^hello$'):$", true); | ||
await assertTransformation(input, "$$test('^(hello|world)$'):$", true); | ||
await assertTransformation("HELLO", "$$test('^hello$'):$", false); | ||
await assertTransformation("HELLO", "$$test('(?i)^hello$'):$", true); | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
javascript/json-transform/src/__tests__/functions/TransformerFunctionUpper.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,10 @@ | ||
import { describe, test } from "vitest"; | ||
import { assertTransformation } from "../BaseTransformationTest"; | ||
|
||
describe("TransformerFunctionUpper", () => { | ||
test("uppercase", async () => { | ||
const strVal = "text"; | ||
await assertTransformation(strVal, "$$upper:$", strVal.toUpperCase()); | ||
await assertTransformation(strVal, "$$upper():$", strVal.toUpperCase()); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
javascript/json-transform/src/functions/TransformerFunctionMath.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
Oops, something went wrong.