1+ [
2+   " # Length operator tests" 
3+   {
4+     "description" : " Length of a basic array" 
5+     "rule" : { "length" : {"val" : " array" 
6+     "data" : { "array" : [1 , 2 , 3 , 4 , 5 ] },
7+     "result" : 5 
8+   },
9+   {
10+     "description" : " Length of an empty array returns 0" 
11+     "rule" : { "length" : {"val" : " emptyArray" 
12+     "data" : { "emptyArray" : [] },
13+     "result" : 0 
14+   },
15+   {
16+     "description" : " Length of a string counts characters" 
17+     "rule" : { "length" : {"val" : " str" 
18+     "data" : { "str" : " hello" 
19+     "result" : 5 
20+   },
21+   {
22+     "description" : " Length of an empty string returns 0" 
23+     "rule" : { "length" : {"val" : " empty" 
24+     "data" : { "empty" : " " 
25+     "result" : 0 
26+   },
27+   {
28+     "description" : " Length of missing variable returns null" 
29+     "rule" : { "length" : {"val" : " missing" 
30+     "data" : {},
31+     "error" : { "type" : " Invalid Arguments" 
32+   },
33+   {
34+     "description" : " Length operator with null argument throws error" 
35+     "rule" : { "length" : null  },
36+     "data" : {},
37+     "error" : { "type" : " Invalid Arguments" 
38+   },
39+   {
40+     "description" : " Length operator with numeric argument throws error" 
41+     "rule" : { "length" : 123  },
42+     "data" : {},
43+     "error" : { "type" : " Invalid Arguments" 
44+   },
45+   {
46+     "description" : " Length operator with boolean argument throws error" 
47+     "rule" : { "length" : true  },
48+     "data" : {},
49+     "error" : { "type" : " Invalid Arguments" 
50+   },
51+   {
52+     "description" : " Conditional based on array length (longer than 3)" 
53+     "rule" : { "if" : [{ ">" : [{ "length" : {"val" : " array" 3 ] }, " long" " short" 
54+     "data" : { "array" : [1 , 2 , 3 , 4 ] },
55+     "result" : " long" 
56+   },
57+   {
58+     "description" : " Conditional based on array length (not longer than 3)" 
59+     "rule" : { "if" : [{ ">" : [{ "length" : {"val" : " array" 3 ] }, " long" " short" 
60+     "data" : { "array" : [1 , 2 , 3 ] },
61+     "result" : " short" 
62+   },
63+   {
64+     "description" : " Length of nested array counts top level elements" 
65+     "rule" : { "length" : {"val" : " nestedArray" 
66+     "data" : { "nestedArray" : [[1 , 2 ], [3 , 4 ], [5 , 6 ]] },
67+     "result" : 3 
68+   },
69+   {
70+     "description" : " Length of array of objects counts objects" 
71+     "rule" : { "length" : {"val" : " objectArray" 
72+     "data" : { "objectArray" : [{"a" : 1 }, {"b" : 2 }, {"c" : 3 }] },
73+     "result" : 3 
74+   }
75+ ]
0 commit comments