@@ -429,6 +429,52 @@ func TestValidationExpressions(t *testing.T) {
429
429
"[1, 'a', false].filter(x, string(x) == 'a')" :"compilation failed: ERROR: <input>:1:5: expected type 'int' but found 'string'" ,
430
430
},
431
431
},
432
+ {name :"ext lists version 3" ,
433
+ obj :objs ([]interface {}{1 ,2 ,3 }, []interface {}{1 ,2 ,3 }),
434
+ schema :schemas (listType (& integerType ),listType (& integerType )),
435
+ valid : []string {
436
+ `lists.range(4) == [0,1,2,3]` ,
437
+ `lists.range(0) == []` ,
438
+ `[5,1,2,3].reverse() == [3,2,1,5]` ,
439
+ `[].reverse() == []` ,
440
+ `[1].reverse() == [1]` ,
441
+ `['are', 'you', 'as', 'bored', 'as', 'I', 'am'].reverse() == ['am', 'I', 'as', 'bored', 'as', 'you', 'are']` ,
442
+ `[false, true, true].reverse().reverse() == [false, true, true]` ,
443
+ `[1,2,3,4].slice(0, 4) == [1,2,3,4]` ,
444
+ `[1,2,3,4].slice(0, 0) == []` ,
445
+ `[1,2,3,4].slice(1, 1) == []` ,
446
+ `[1,2,3,4].slice(4, 4) == []` ,
447
+ `[1,2,3,4].slice(1, 3) == [2, 3]` ,
448
+ `dyn([]).flatten() == []` ,
449
+ `dyn([1,2,3,4]).flatten() == [1,2,3,4]` ,
450
+ `[].sort() == []` ,
451
+ `[1].sort() == [1]` ,
452
+ `[4, 3, 2, 1].sort() == [1, 2, 3, 4]` ,
453
+ `["d", "a", "b", "c"].sort() == ["a", "b", "c", "d"]` ,
454
+ `[].sortBy(e, e) == []` ,
455
+ `["a"].sortBy(e, e) == ["a"]` ,
456
+ `[-3, 1, -5, -2, 4].sortBy(e, -(e * e)) == [-5, 4, -3, -2, 1]` ,
457
+ `[-3, 1, -5, -2, 4].map(e, e * 2).sortBy(e, -(e * e)) == [-10, 8, -6, -4, 2]` ,
458
+ `lists.range(3).sortBy(e, -e) == [2, 1, 0]` ,
459
+ `["a", "c", "b", "first"].sortBy(e, e == "first" ? "" : e) == ["first", "a", "b", "c"]` ,
460
+ `[{'name': 'foo'}, {'name': 'bar'}, {'name': 'baz'}].sortBy(e, e.name) == [{'name': 'bar'}, {'name': 'baz'}, {'name': 'foo'}]` ,
461
+ `[].distinct() == []` ,
462
+ `[1].distinct() == [1]` ,
463
+ `[-2, 5, -2, 1, 1, 5, -2, 1].distinct() == [-2, 5, 1]` ,
464
+ `['c', 'a', 'a', 'b', 'a', 'b', 'c', 'c'].distinct() == ['c', 'a', 'b']` ,
465
+ `[[1], [1], [2]].distinct() == [[1], [2]]` ,
466
+ `[{'name': 'a'}, {'name': 'b'}, {'name': 'a'}].distinct() == [{'name': 'a'}, {'name': 'b'}]` ,
467
+ `[[1],[2],[3,4]].flatten() == [1,2,3,4]` ,
468
+ },
469
+ errors :map [string ]string {
470
+ `[1,2,3,4].slice(3, 0) != [1,2]` :"cannot slice(3, 0), start index must be less than or equal to end index" ,
471
+ `[1,2,3,4].slice(0, 10) != [1,2]` :"cannot slice(0, 10), list is length 4" ,
472
+ `[1,2,3,4].slice(-5, 10) != [1,2]` :"cannot slice(-5, 10), negative indexes not supported" ,
473
+ `[1,2,3,4].slice(-5, -3) != [1,2]` :"cannot slice(-5, -3), negative indexes not supported" ,
474
+ `[[1],[2],[3,4]].flatten(-1) == [1,2,3,4]` :"level must be non-negative evaluating rule: [[1],[2],[3,4]].flatten(-1) == [1,2,3,4]" ,
475
+ `["d", 3, 2, "c"].sort() == ["a", "b", "c", "d"]` :"expected type 'string' but found 'int'" ,
476
+ },
477
+ },
432
478
{name :"string lists" ,
433
479
obj :objs ([]interface {}{"a" ,"b" ,"c" }),
434
480
schema :schemas (listType (& stringType )),