Files
zen/core/expression/tests/data/standard.csv
T

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([null[12][3]]);;[123]
110merge([[12]null[3]]);;[123]
111merge([null]);;{}
112merge([nullnull]);;{}
113merge([]);;{}
114mergeDeep([]);;{}
115# Dates
116# Decimal precision
1170.1 + 0.2 == 0.3;; true
1180.1 + 0.2;; 0.3
1190.1 * 0.2 == 0.02;; true
1200.1 * 0.2;; 0.02
1210.3 - 0.1 == 0.2;; true
1220.3 - 0.1;; 0.2
1230.3 / 0.1 == 3.0;; true
1240.3 / 0.1;; 3
125# More complex formulas
126(10 + 5) * 3 / 2 > 15;; true
127(100 - 25) / (5 * 2) < 10;; true
1281000 / (10 - 2) + 50 == 175;; true
129(3 + 4) * (8 - 6) == 14;; true
13010^3 != 999;; true
1311000 / 10^3 <= 1.1;; true
132abs(-20) > 10;; true
133floor(8.9) == 8;; true
134ceil(8.1) == 9;; true
135round(7.6) == 8;; true
13610 % 3 != 0;; true
137-8 + 2^3 == 0;; true
1382 * -(-5) == 10;; true
13920 / (5 / 2) == 8.0;; true
140(4 + 2) * 3 - (5 / 2) + 1 < 18;; true
1415^2 + 3 * 4 - 6 / 2 > 20;; true
1424^3 - 2 * 5 + 7 / 2 == 57.5;; true
143abs(-7 + 4) * (8 - 6^2) < 34;; true
1445 in [1..10];; true
1455 in (1..10);; true
1465 not in [1..10);; false
1475 not in (1..10);; false
148-5 in [-10..-1];; true
149-5 in [-10..-1);; true
150-5 not in [-10..-1];; false
151-5 not in [-10..-1);; false
152-5 in [-5..5];; true
153-5 in (-5..5);; false
154-5 not in [-5..5);; false
155-5 not in (-5..5);; true
15610 > 5;; true
1575 < 10;; true
15810 >= 10;; true
1595 <= 5;; true
160(1 + 2) == 3;; true
161(1 + 2) != 4;; true
162(1 + 2) > 2;; true
163(1 + 2) < 5;; true
164# Date Functions
165dateString(startOf('2023-01-01 15:45:01''day'));;'2023-01-01 00:00:00'
166dateString(endOf('2023-01-01 15:45:01''d'));;'2023-01-01 23:59:59'
167dateString(startOf('2023-01-01 15:45:01''hour'));;'2023-01-01 15:00:00'
168dateString(endOf('2023-01-01 15:45:01''h'));;'2023-01-01 15:59:59'
169dateString(startOf('2023-01-01 15:45:01''minute'));;'2023-01-01 15:45:00'
170dateString(endOf('2023-01-01 15:45:01''m'));;'2023-01-01 15:45:59'
171dateString(startOf('2023-01-04 15:45:01''week'));;'2023-01-02 00:00:00'
172dateString(endOf('2023-01-04 15:45:01''w'));;'2023-01-08 23:59:59'
173dateString(startOf('2023-01-04 15:45:01''month'));;'2023-01-01 00:00:00'
174dateString(endOf('2023-01-04 15:45:01''M'));;'2023-01-31 23:59:59'
175dateString(startOf('2023-01-04 15:45:01''year'));;'2023-01-01 00:00:00'
176dateString(endOf('2023-01-04 15:45:01''y'));;'2023-12-31 23:59:59'
177# Type conversions
178string(123.123);;'123.123'
179string(123);;'123'
180string(true);;'true'
181string(false);;'false'
182string('already string');;'already string'
183number('123.123');;123.123
184number('123');;123
185number(123.123);;123.123
186number(123);;123
187number(true);;1
188number(false);;0
189# Type check
190isNumeric(123.123);;true
191isNumeric(123);;true
192isNumeric('123.123');;true
193isNumeric('123');;true
194isNumeric('string');;false
195isNumeric(true);;false
196# Types
197type('hello');;'string'
198type(123);;'number'
199type(true);;'bool'
200type(null);;'null'
201type([123]);;'array'
202# Object
203sum(values({a: 1b: 2c: 3}));;6
204keys({[`dynamic-${'key'}`]: 123});;['dynamic-key']
205{};;{}
206# Interval iterator
207map([0..3]#);[0123]
208map((0..3]#);[123]
209map([0..3)#);[012]
210map((0..3)#);[12]
211# Nullish coalescing
212null ?? 'hello';;'hello'
213null ?? 123 ?? 321;;123
214null ?? null ?? 321;;321
215false or true ? null ?? 'test' : false;;'test'
216# Array indexing and dot notation
217# Array functions
218len(['a''b''c']);;3
219contains(['a''b''c']'b');;true
220contains(['a''b''c']'d');;false
221some(['a''b''c']# == 'b');;true
222some(['a''b''c']# == 'd');;false
223all(['a''b''c']# in ['a''b''c''d']);;true
224all(['a''b''c']# in ['a''b']);;false
225filter(['a''b''c''d']# in ['a''c']);;['a''c']
226map(['a''b''c']# + '!');;['a!''b!''c!']
227# Array combinations
228map(filter([12345]# > 2)# * 2);;[6810]
229len(filter([12345]# % 2 == 0));;2
230sum(filter([12345]# % 2 == 0));;6
231sum(map(filter([12345]# > 3)# ^ 2));;41
232# Complex array operations
233some(map([123]# * 2)# > 5);;true
234all(map([123]# + 2)# > 2);;true
235contains(map([123]# * 2)6);;true
236contains(values({a: 1b: 2c: 3})2);;true
237# Array with objects
238map([{id: 1name: 'John'}{id: 2name: 'Jane'}]#.id);;[12]
239filter([{id: 1name: 'John'}{id: 2name: 'Jane'}]#.id > 1);;[{id: 2name: 'Jane'}]
240map(filter([{id: 1name: 'John'}{id: 2name: 'Jane'}]#.id > 1)#.name);;['Jane']
241# String concatenation
242'Hello' + ' ' + 'World' + '!';;'Hello World!'
243# String functions
244len('Hello');;5
245upper('Hello');;'HELLO'
246lower('HELLO');;'hello'
247trim(' hello ');;'hello'
248startsWith('Hello World''Hell');;true
249endsWith('Hello World''orld');;true
250contains('Hello World''lo Wo');;true
251matches('123-456-7890''[0-9]{3}-[0-9]{3}-[0-9]{4}');;true
252# String formatting
253`Total: ${sum([123])}`;;'Total: 6'
254# Nested object access
255# Dynamic keys
256# Date arithmetic
257date('2023-10-15') + duration('1d');;1697414400
258date('2023-10-15') - duration('7d');;1696723200
259dateString(date('2023-10-15') + duration('1d'));;'2023-10-16 00:00:00'
260dateString(date('2023-10-15') - duration('7d'));;'2023-10-08 00:00:00'
261# Date comparisons
262date('2023-10-15') > date('2023-10-14');;true
263date('2023-10-15') < date('2023-10-16');;true
264date('2023-10-15') + duration('1d') == date('2023-10-16');;true
265# Date parts
266year(date('2023-10-15'));;2023
267monthOfYear(date('2023-10-15'));;10
268dayOfMonth(date('2023-10-15'));;15
269dayOfWeek(date('2023-10-15'));;7
270weekOfYear(date('2023-10-15'));;41
271# Date formatting
272dateString(date('2023-10-15'));;'2023-10-15 00:00:00'
273dateString(date('2023-10-15') + duration('12h'));;'2023-10-15 12:00:00'
274# Ternary operators
275# Null handling
276# Type conversions
277string(123);;'123'
278string(true);;'true'
279number('123');;123
280number('12.3');;12.3
281number(true);;1
282number(false);;0
283bool(1);;true
284bool(0);;false
285bool('true');;true
286bool('false');;false
287# Complex nested expressions
288len(filter(map([12345]# * 2)# > 5));;3
289sum(map(filter([{id: 1val: 10}{id: 2val: 20}{id: 3val: 30}]#.id > 1)#.val));;50
290# Data transformation
291# Array-based conditions
292# Statistical calculations
293# Closures and the # symbol
294map([123]# * 2);;[246]
295filter([12345]# % 2 == 0);;[24]
296some([123]# > 2);;true
297all([123]# > 0);;true
298count([122333]# == 3);;3
299one([123]# == 2);;true
300none([123]# > 3);;true
301# Nested closures
302filter(map([1234]# * 2)# > 5);;[68]
303map(filter([1234]# % 2 == 0)# * 3);;[612]
304# Range tests
305# Interval iterator
306map([0..5]# * 2);;[0246810]
307filter([0..10]# % 2 == 0);;[0246810]
308# Rounding
309round(7.4);; 7
310round(7.5);; 8
311round(7.6);; 8
312round(-7.4);; -7
313round(-7.5);; -8
314round(-7.6);; -8
315round(0.5);;1
316round(-0.5);;-1
317round(1.5);;2
318round(-1.5);;-2
319round(0.4);;0
320round(-0.4);;0
321round(7.4440);; 7
322round(7.4441);; 7.4
323round(7.4442);; 7.44
324round(7.5550);; 8
325round(7.5551);; 7.6
326round(7.5552);; 7.56
327round(-7.4442);; -7.44
328round(-7.5552);; -7.56
329trunc(7.4);; 7
330trunc(7.5);; 7
331trunc(7.6);; 7
332trunc(-7.4);; -7
333trunc(-7.5);; -7
334trunc(-7.6);; -7
335trunc(7.4440);; 7
336trunc(7.4441);; 7.4
337trunc(7.4442);; 7.44
338trunc(7.9990);; 7
339trunc(7.9991);; 7.9
340trunc(7.9992);; 7.99
341trunc(-7.4442);; -7.44
342trunc(-7.9992);; -7.99
343# Scientific notation - basic parsing
3441e5;;100000
3452e3;;2000
3465e0;;5
3471e-2;;0.01
3482.5e2;;250
3493.14e1;;31.4
3501.23e-3;;0.00123
351-1e3;;-1000
352-2.5e-2;;-0.025
353# Scientific notation - arithmetic operations
3541e2 + 1e1;;110
3552e3 - 5e2;;1500
3563e2 * 2e1;;6000
3571e4 / 2e2;;50
3581e2 + 50;;150
3591e3 - 100;;900
3602e2 * 3;;600
3611e3 / 10;;100
362# Scientific notation - comparisons
3631e3 == 1000;;true
3641e3 != 999;;true
3651e2 > 50;;true
3661e2 < 200;;true
3671e2 >= 100;;true
3681e2 <= 100;;true
3692.5e2 == 250;;true
3701.5e-2 == 0.015;;true
371# Scientific notation - type conversions
372string(1e3);;'1000'
373string(2.5e2);;'250'
374string(1.23e-3);;'0.00123'
375number('1e3');;1000
376number('2.5e2');;250
377number('1.23e-3');;0.00123
378isNumeric('1e3');;true
379isNumeric('2.5e-2');;true
380isNumeric('1.23e-3');;true
381# Scientific notation - array operations
382sum([1e22e23e2]);;600
383max([1e12e13e1]);;30
384min([1e12e13e1]);;10
385avg([1e22e23e2]);;200
386contains([1e22e23e2]200);;true
387map([1e12e13e1]# * 2);;[204060]
388filter([1e12e13e14e1]# > 25);;[3040]
389# Scientific notation - edge cases
3901e+3;;1000
3911e-0;;1
3920e5;;0
3931.0e2;;100
39410e1;;100
3950.1e3;;100
3961.5e+2;;150
3972e-1;;0.2
398# Scientific notation - mixed with regular numbers
3991e2 + 50.5;;150.5
4001000 - 1e2;;900
40115 * 1e2;;1500
4021e3 / 2.5;;400
403# Scientific notation - complex expressions
404(1e2 + 2e2) * 1e1;;3000
4051e3 / (2e1 + 3e1);;20
406abs(-1e2);;100
407floor(1.23e2);;123
408ceil(1.23e2);;123
409round(1.234e2);;123
410# Scientific notation - in functions
4111e1 ^ 2;;100
412# Scientific notation - template strings
413`Value: ${1e3}`;; 'Value: 1000'
414`Scientific: ${2.5e2}`;; 'Scientific: 250'
415`Negative: ${-1e2}`;; 'Negative: -100'
416### Assignment
417# Basic assignment
418# Property assignment
419# Nested property assignment
420# Multiple assignments
421# Assignment with expressions
422# Assignment with function calls
423# Assignment with array operations
424# Assignment with conditional expressions
425# Assignment with object creation
426# Assignment with template strings
427# Assignment with return value
428# Closure 'as' alias syntax
429# Nested closures with 'as' aliases
430# Mixed # and 'as' alias
431# Backwards compatibility - # still works
432map([123]# * 2);;[246]
433filter([1234]# > 2);;[34]