Skip to content

Commit b14ddd0

Browse files
committed
feat: add test cases for parsing all known functions (fixes #11)
1 parent f329054 commit b14ddd0

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

test-suite/parse.test.json

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,83 @@
8787
{ "input": "sort(get(), \"desc\")", "output": ["sort", ["get"], "desc"] }
8888
]
8989
},
90+
{
91+
"category": "function",
92+
"description": "should parse all built-in functions",
93+
"tests": [
94+
{
95+
"input": "pipe(.address, .city)",
96+
"output": ["pipe", ["get", "address"], ["get", "city"]]
97+
},
98+
{ "input": "{age: .age}", "output": ["object", { "age": ["get", "age"] }] },
99+
{ "input": "array(1, 2, 3)", "output": ["array", 1, 2, 3] },
100+
{ "input": "get(\"address\")", "output": ["get", "address"] },
101+
{ "input": "map(.address)", "output": ["map", ["get", "address"]] },
102+
{
103+
"input": "mapObject({key: .key, value: .value})",
104+
"output": ["mapObject", ["object", { "key": ["get", "key"], "value": ["get", "value"] }]]
105+
},
106+
{ "input": "mapKeys(\"#\" + get())", "output": ["mapKeys", ["add", "#", ["get"]]] },
107+
{ "input": "mapValues(get() * 2)", "output": ["mapValues", ["multiply", ["get"], 2]] },
108+
{ "input": "filter(.registered)", "output": ["filter", ["get", "registered"]] },
109+
{ "input": "sort(.name)", "output": ["sort", ["get", "name"]] },
110+
{ "input": "reverse()", "output": ["reverse"] },
111+
{ "input": "pick(.name, .city)", "output": ["pick", ["get", "name"], ["get", "city"]] },
112+
{ "input": "groupBy(.city)", "output": ["groupBy", ["get", "city"]] },
113+
{ "input": "keyBy(.city)", "output": ["keyBy", ["get", "city"]] },
114+
{ "input": "flatten()", "output": ["flatten"] },
115+
{ "input": "join(\", \")", "output": ["join", ", "] },
116+
{ "input": "split(.message)", "output": ["split", ["get", "message"]] },
117+
{
118+
"input": "substring(.message, 0, 10)",
119+
"output": ["substring", ["get", "message"], 0, 10]
120+
},
121+
{ "input": "uniq()", "output": ["uniq"] },
122+
{ "input": "uniqBy(.name)", "output": ["uniqBy", ["get", "name"]] },
123+
{ "input": "limit(100)", "output": ["limit", 100] },
124+
{ "input": "size()", "output": ["size"] },
125+
{ "input": "keys()", "output": ["keys"] },
126+
{ "input": "values()", "output": ["values"] },
127+
{ "input": "prod()", "output": ["prod"] },
128+
{ "input": "sum()", "output": ["sum"] },
129+
{ "input": "average()", "output": ["average"] },
130+
{ "input": "min()", "output": ["min"] },
131+
{ "input": "max()", "output": ["max"] },
132+
{ "input": "and(true, false)", "output": ["and", true, false] },
133+
{ "input": "or(true, false)", "output": ["or", true, false] },
134+
{ "input": "not(true)", "output": ["not", true] },
135+
{ "input": "exists(.address)", "output": ["exists", ["get", "address"]] },
136+
{
137+
"input": "if(.registered, true, false)",
138+
"output": ["if", ["get", "registered"], true, false]
139+
},
140+
{ "input": "in(.age, [16, 18])", "output": ["in", ["get", "age"], ["array", 16, 18]] },
141+
{
142+
"input": ".age not in [16, 18]",
143+
"output": ["not in", ["get", "age"], ["array", 16, 18]]
144+
},
145+
{
146+
"input": "regex(.message, \"like|awesome\", \"i\")",
147+
"output": ["regex", ["get", "message"], "like|awesome", "i"]
148+
},
149+
{ "input": "eq(2, 3)", "output": ["eq", 2, 3] },
150+
{ "input": "gt(2, 3)", "output": ["gt", 2, 3] },
151+
{ "input": "gte(2, 3)", "output": ["gte", 2, 3] },
152+
{ "input": "lt(2, 3)", "output": ["lt", 2, 3] },
153+
{ "input": "lte(2, 3)", "output": ["lte", 2, 3] },
154+
{ "input": "ne(2, 3)", "output": ["ne", 2, 3] },
155+
{ "input": "add(2, 3)", "output": ["add", 2, 3] },
156+
{ "input": "subtract(2, 3)", "output": ["subtract", 2, 3] },
157+
{ "input": "multiply(2, 3)", "output": ["multiply", 2, 3] },
158+
{ "input": "divide(2, 3)", "output": ["divide", 2, 3] },
159+
{ "input": "mod(2, 3)", "output": ["mod", 2, 3] },
160+
{ "input": "pow(2, 3)", "output": ["pow", 2, 3] },
161+
{ "input": "abs(-3)", "output": ["abs", -3] },
162+
{ "input": "round(3.14159, 2)", "output": ["round", 3.14159, 2] },
163+
{ "input": "number(\"42\")", "output": ["number", "42"] },
164+
{ "input": "string(42)", "output": ["string", 42] }
165+
]
166+
},
90167
{
91168
"category": "function",
92169
"description": "should throw an error in case of an unknown function name",

0 commit comments

Comments
 (0)