Files
zen/core/expression/tests/data/standard.csv
T
stefan-gorules 53f3b5a430 feat: merge function (#438)
* feat: merge function

* add mergeDeep function

* default merge to return empty object instead of empty array
2026-03-15 14:44:32 +01:00

20 KiB

1expression (string);input (json 5);output (json 5)
2# Boolean
3true and true;;true
4true and false;;false
5false and true;;false
6false and false;;false
7true or true;;true
8true or false;;true
9false or true;;true
10false or false;;false
11not true;;false
12not false;;true
13# Numbers
141 == 1;;true
151 == 2;;false
161 != 2;;true
171 != 1;;false
181 < 2;;true
191 < 1;;false
201 <= 1;;true
212 <= 1;;false
222 > 1;;true
231 > 1;;false
241 >= 1;;true
251 >= 2;;false
26-1 == -1;;true
27-1 == 1;;false
28-1 != 1;;true
29-1 != -1;;false
30-1 < 1;;true
31-1 < -1;;false
32-1 <= -1;;true
331 <= -1;;false
341 > -1;;true
35-1 > -1;;false
36-1 >= -1;;true
37-1 >= 1;;false
381 + 2 == 3;;true
391 + 2 == 4;;false
401 - 2 == -1;;true
411 - 2 == 0;;false
422 * 3 == 6;;true
432 * 3 == 7;;false
446 / 3 == 2;;true
456 / 3 == 2.5;;false
465 % 2 == 1;;true
476 % 2 == 0;;true
48-5 + 5 == 0;;true
49-5 * 5 == -25;;true
50-5 * -5 == 25;;true
5110 / 0;;null
52abs(-5) == 5;;true
53abs(5) == 5;;true
542 ^ 3 == 8;;true
552 ^ -1 == 0.5;;true
56max([35]) == 5;;true
57max([-3-5]) == -3;;true
58min([35]) == 3;;true
59min([-3-5]) == -5;;true
603 + 4 * 2;;11
61(3 + 4) * 2;;14
62(10 - 4) / 2;;3
63abs(-5);;5
64sum([12345]);;15
65avg([102030]);;20
66min([582117]);;2
67max([582117]);;11
68floor(4.8);;4
69ceil(4.1);;5
70round(3.5);;4
71rand(100) >= 0 and rand(100) <= 100;;true
72median([42753]);;4
73mode([1223334444]);;4
745 % 2 == 1;;true
7510 % 4 == 2;;true
76true ? 10 == 10 : 20 == 30;;true
77false ? 10 == 10 : 20 == 30;;false
78true ? 10 == 20 : false ? 30 == 40 : true ? 50 == 60 : 70 == 80;;false
79# String
80# Template string
81`simple template`;;'simple template'
82`sum of numbers ${sum([123])}`;;'sum of numbers 6'
83`reference env: ${a}`;{a:'example'};'reference env: example'
84`uppercase inner ${upper('string')}`;;'uppercase inner STRING'
85# String Slice
86string[0:5];{string: 'sample_string'};'sample'
87string[7:12];{string: 'sample_string'};'string'
88string[7:];{string: 'sample_string'};'string'
89string[:5];{string: 'sample_string'};'sample'
90# Array
91len([12345]);; 5
92sum([12345]);; 15
93avg([102030]);; 20
94min([582117]);; 2
95max([582117]);; 11
96contains([12345]3);; true
97contains([12345]6);; false
98count([123452]# == 2);; 2
99filter([12345]# > 3);; [45]
100map([12345]# * 2);; [246810]
101one([12345]# == 3);; true
102one([12345]# == 6);; false
103none([12345]# > 5);; true
104some([12345]# > 3);; true
105flatMap([[12][34][56]]#);; [123456]
106keys([101112]);;[012]
107merge([[12][34][5]]);;[12345]
108merge([[12][][3]]);;[123]
109merge([]);;{}
110mergeDeep([]);;{}
111# Dates
112# Decimal precision
1130.1 + 0.2 == 0.3;; true
1140.1 + 0.2;; 0.3
1150.1 * 0.2 == 0.02;; true
1160.1 * 0.2;; 0.02
1170.3 - 0.1 == 0.2;; true
1180.3 - 0.1;; 0.2
1190.3 / 0.1 == 3.0;; true
1200.3 / 0.1;; 3
121# More complex formulas
122(10 + 5) * 3 / 2 > 15;; true
123(100 - 25) / (5 * 2) < 10;; true
1241000 / (10 - 2) + 50 == 175;; true
125(3 + 4) * (8 - 6) == 14;; true
12610^3 != 999;; true
1271000 / 10^3 <= 1.1;; true
128abs(-20) > 10;; true
129floor(8.9) == 8;; true
130ceil(8.1) == 9;; true
131round(7.6) == 8;; true
13210 % 3 != 0;; true
133-8 + 2^3 == 0;; true
1342 * -(-5) == 10;; true
13520 / (5 / 2) == 8.0;; true
136(4 + 2) * 3 - (5 / 2) + 1 < 18;; true
1375^2 + 3 * 4 - 6 / 2 > 20;; true
1384^3 - 2 * 5 + 7 / 2 == 57.5;; true
139abs(-7 + 4) * (8 - 6^2) < 34;; true
1405 in [1..10];; true
1415 in (1..10);; true
1425 not in [1..10);; false
1435 not in (1..10);; false
144-5 in [-10..-1];; true
145-5 in [-10..-1);; true
146-5 not in [-10..-1];; false
147-5 not in [-10..-1);; false
148-5 in [-5..5];; true
149-5 in (-5..5);; false
150-5 not in [-5..5);; false
151-5 not in (-5..5);; true
15210 > 5;; true
1535 < 10;; true
15410 >= 10;; true
1555 <= 5;; true
156(1 + 2) == 3;; true
157(1 + 2) != 4;; true
158(1 + 2) > 2;; true
159(1 + 2) < 5;; true
160# Date Functions
161dateString(startOf('2023-01-01 15:45:01''day'));;'2023-01-01 00:00:00'
162dateString(endOf('2023-01-01 15:45:01''d'));;'2023-01-01 23:59:59'
163dateString(startOf('2023-01-01 15:45:01''hour'));;'2023-01-01 15:00:00'
164dateString(endOf('2023-01-01 15:45:01''h'));;'2023-01-01 15:59:59'
165dateString(startOf('2023-01-01 15:45:01''minute'));;'2023-01-01 15:45:00'
166dateString(endOf('2023-01-01 15:45:01''m'));;'2023-01-01 15:45:59'
167dateString(startOf('2023-01-04 15:45:01''week'));;'2023-01-02 00:00:00'
168dateString(endOf('2023-01-04 15:45:01''w'));;'2023-01-08 23:59:59'
169dateString(startOf('2023-01-04 15:45:01''month'));;'2023-01-01 00:00:00'
170dateString(endOf('2023-01-04 15:45:01''M'));;'2023-01-31 23:59:59'
171dateString(startOf('2023-01-04 15:45:01''year'));;'2023-01-01 00:00:00'
172dateString(endOf('2023-01-04 15:45:01''y'));;'2023-12-31 23:59:59'
173# Type conversions
174string(123.123);;'123.123'
175string(123);;'123'
176string(true);;'true'
177string(false);;'false'
178string('already string');;'already string'
179number('123.123');;123.123
180number('123');;123
181number(123.123);;123.123
182number(123);;123
183number(true);;1
184number(false);;0
185# Type check
186isNumeric(123.123);;true
187isNumeric(123);;true
188isNumeric('123.123');;true
189isNumeric('123');;true
190isNumeric('string');;false
191isNumeric(true);;false
192# Types
193type('hello');;'string'
194type(123);;'number'
195type(true);;'bool'
196type(null);;'null'
197type([123]);;'array'
198# Object
199sum(values({a: 1b: 2c: 3}));;6
200keys({[`dynamic-${'key'}`]: 123});;['dynamic-key']
201{};;{}
202# Interval iterator
203map([0..3]#);[0123]
204map((0..3]#);[123]
205map([0..3)#);[012]
206map((0..3)#);[12]
207# Nullish coalescing
208null ?? 'hello';;'hello'
209null ?? 123 ?? 321;;123
210null ?? null ?? 321;;321
211false or true ? null ?? 'test' : false;;'test'
212# Array indexing and dot notation
213# Array functions
214len(['a''b''c']);;3
215contains(['a''b''c']'b');;true
216contains(['a''b''c']'d');;false
217some(['a''b''c']# == 'b');;true
218some(['a''b''c']# == 'd');;false
219all(['a''b''c']# in ['a''b''c''d']);;true
220all(['a''b''c']# in ['a''b']);;false
221filter(['a''b''c''d']# in ['a''c']);;['a''c']
222map(['a''b''c']# + '!');;['a!''b!''c!']
223# Array combinations
224map(filter([12345]# > 2)# * 2);;[6810]
225len(filter([12345]# % 2 == 0));;2
226sum(filter([12345]# % 2 == 0));;6
227sum(map(filter([12345]# > 3)# ^ 2));;41
228# Complex array operations
229some(map([123]# * 2)# > 5);;true
230all(map([123]# + 2)# > 2);;true
231contains(map([123]# * 2)6);;true
232contains(values({a: 1b: 2c: 3})2);;true
233# Array with objects
234map([{id: 1name: 'John'}{id: 2name: 'Jane'}]#.id);;[12]
235filter([{id: 1name: 'John'}{id: 2name: 'Jane'}]#.id > 1);;[{id: 2name: 'Jane'}]
236map(filter([{id: 1name: 'John'}{id: 2name: 'Jane'}]#.id > 1)#.name);;['Jane']
237# String concatenation
238'Hello' + ' ' + 'World' + '!';;'Hello World!'
239# String functions
240len('Hello');;5
241upper('Hello');;'HELLO'
242lower('HELLO');;'hello'
243trim(' hello ');;'hello'
244startsWith('Hello World''Hell');;true
245endsWith('Hello World''orld');;true
246contains('Hello World''lo Wo');;true
247matches('123-456-7890''[0-9]{3}-[0-9]{3}-[0-9]{4}');;true
248# String formatting
249`Total: ${sum([123])}`;;'Total: 6'
250# Nested object access
251# Dynamic keys
252# Date arithmetic
253date('2023-10-15') + duration('1d');;1697414400
254date('2023-10-15') - duration('7d');;1696723200
255dateString(date('2023-10-15') + duration('1d'));;'2023-10-16 00:00:00'
256dateString(date('2023-10-15') - duration('7d'));;'2023-10-08 00:00:00'
257# Date comparisons
258date('2023-10-15') > date('2023-10-14');;true
259date('2023-10-15') < date('2023-10-16');;true
260date('2023-10-15') + duration('1d') == date('2023-10-16');;true
261# Date parts
262year(date('2023-10-15'));;2023
263monthOfYear(date('2023-10-15'));;10
264dayOfMonth(date('2023-10-15'));;15
265dayOfWeek(date('2023-10-15'));;7
266weekOfYear(date('2023-10-15'));;41
267# Date formatting
268dateString(date('2023-10-15'));;'2023-10-15 00:00:00'
269dateString(date('2023-10-15') + duration('12h'));;'2023-10-15 12:00:00'
270# Ternary operators
271# Null handling
272# Type conversions
273string(123);;'123'
274string(true);;'true'
275number('123');;123
276number('12.3');;12.3
277number(true);;1
278number(false);;0
279bool(1);;true
280bool(0);;false
281bool('true');;true
282bool('false');;false
283# Complex nested expressions
284len(filter(map([12345]# * 2)# > 5));;3
285sum(map(filter([{id: 1val: 10}{id: 2val: 20}{id: 3val: 30}]#.id > 1)#.val));;50
286# Data transformation
287# Array-based conditions
288# Statistical calculations
289# Closures and the # symbol
290map([123]# * 2);;[246]
291filter([12345]# % 2 == 0);;[24]
292some([123]# > 2);;true
293all([123]# > 0);;true
294count([122333]# == 3);;3
295one([123]# == 2);;true
296none([123]# > 3);;true
297# Nested closures
298filter(map([1234]# * 2)# > 5);;[68]
299map(filter([1234]# % 2 == 0)# * 3);;[612]
300# Range tests
301# Interval iterator
302map([0..5]# * 2);;[0246810]
303filter([0..10]# % 2 == 0);;[0246810]
304# Rounding
305round(7.4);; 7
306round(7.5);; 8
307round(7.6);; 8
308round(-7.4);; -7
309round(-7.5);; -8
310round(-7.6);; -8
311round(0.5);;1
312round(-0.5);;-1
313round(1.5);;2
314round(-1.5);;-2
315round(0.4);;0
316round(-0.4);;0
317round(7.4440);; 7
318round(7.4441);; 7.4
319round(7.4442);; 7.44
320round(7.5550);; 8
321round(7.5551);; 7.6
322round(7.5552);; 7.56
323round(-7.4442);; -7.44
324round(-7.5552);; -7.56
325trunc(7.4);; 7
326trunc(7.5);; 7
327trunc(7.6);; 7
328trunc(-7.4);; -7
329trunc(-7.5);; -7
330trunc(-7.6);; -7
331trunc(7.4440);; 7
332trunc(7.4441);; 7.4
333trunc(7.4442);; 7.44
334trunc(7.9990);; 7
335trunc(7.9991);; 7.9
336trunc(7.9992);; 7.99
337trunc(-7.4442);; -7.44
338trunc(-7.9992);; -7.99
339# Scientific notation - basic parsing
3401e5;;100000
3412e3;;2000
3425e0;;5
3431e-2;;0.01
3442.5e2;;250
3453.14e1;;31.4
3461.23e-3;;0.00123
347-1e3;;-1000
348-2.5e-2;;-0.025
349# Scientific notation - arithmetic operations
3501e2 + 1e1;;110
3512e3 - 5e2;;1500
3523e2 * 2e1;;6000
3531e4 / 2e2;;50
3541e2 + 50;;150
3551e3 - 100;;900
3562e2 * 3;;600
3571e3 / 10;;100
358# Scientific notation - comparisons
3591e3 == 1000;;true
3601e3 != 999;;true
3611e2 > 50;;true
3621e2 < 200;;true
3631e2 >= 100;;true
3641e2 <= 100;;true
3652.5e2 == 250;;true
3661.5e-2 == 0.015;;true
367# Scientific notation - type conversions
368string(1e3);;'1000'
369string(2.5e2);;'250'
370string(1.23e-3);;'0.00123'
371number('1e3');;1000
372number('2.5e2');;250
373number('1.23e-3');;0.00123
374isNumeric('1e3');;true
375isNumeric('2.5e-2');;true
376isNumeric('1.23e-3');;true
377# Scientific notation - array operations
378sum([1e22e23e2]);;600
379max([1e12e13e1]);;30
380min([1e12e13e1]);;10
381avg([1e22e23e2]);;200
382contains([1e22e23e2]200);;true
383map([1e12e13e1]# * 2);;[204060]
384filter([1e12e13e14e1]# > 25);;[3040]
385# Scientific notation - edge cases
3861e+3;;1000
3871e-0;;1
3880e5;;0
3891.0e2;;100
39010e1;;100
3910.1e3;;100
3921.5e+2;;150
3932e-1;;0.2
394# Scientific notation - mixed with regular numbers
3951e2 + 50.5;;150.5
3961000 - 1e2;;900
39715 * 1e2;;1500
3981e3 / 2.5;;400
399# Scientific notation - complex expressions
400(1e2 + 2e2) * 1e1;;3000
4011e3 / (2e1 + 3e1);;20
402abs(-1e2);;100
403floor(1.23e2);;123
404ceil(1.23e2);;123
405round(1.234e2);;123
406# Scientific notation - in functions
4071e1 ^ 2;;100
408# Scientific notation - template strings
409`Value: ${1e3}`;; 'Value: 1000'
410`Scientific: ${2.5e2}`;; 'Scientific: 250'
411`Negative: ${-1e2}`;; 'Negative: -100'
412### Assignment
413# Basic assignment
414# Property assignment
415# Nested property assignment
416# Multiple assignments
417# Assignment with expressions
418# Assignment with function calls
419# Assignment with array operations
420# Assignment with conditional expressions
421# Assignment with object creation
422# Assignment with template strings
423# Assignment with return value
424# Closure 'as' alias syntax
425# Nested closures with 'as' aliases
426# Mixed # and 'as' alias
427# Backwards compatibility - # still works
428map([123]# * 2);;[246]
429filter([1234]# > 2);;[34]