forked from json-e/json-e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
specification.yml
4900 lines (4899 loc) · 107 KB
/
specification.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
################################################################################
# ### Specificaiton for json-e
# This document specifies the json-e template language through a series of
# test cases on the form: `{title, context, template, result}`
# Where `jsone.render(template, context) = result` and title is short name
# for the test case. If `error` property is specified as `true`, no result needs
# to be specified, as the test case must throw an error.
#
# Comments explaining the test cases is encouraged, additionally entries with
# {section: '...'} is encouraged to separate sections.
#
# Test conditions:
# 1) Time at test time is expected to be '2017-01-19T16:27:20.974Z'
################################################################################
---
section: Initial Minimal Subset
---
title: Identity
context: {}
template: {key: [1,2,{key2: 'val', key3: 1}, true], f: false}
result: {key: [1,2,{key2: 'val', key3: 1}, true], f: false}
---
title: fromNow
context: {}
template: {$fromNow: ''}
result: '2017-01-19T16:27:20.974Z'
---
title: fromNow 2 days 3 hours
context: {}
template: {$fromNow: '2 days 3 hours'}
result: '2017-01-21T19:27:20.974Z'
---
title: $eval
context: {key: ['value', 1, 2, true, {}]}
template: {$eval: 'key'}
result: ['value', 1, 2, true, {}]
---
title: $json
context: {}
template: {$json: [1,2,true,{},[]]}
result: '[1,2,true,{},[]]'
---
title: string interpolation
context: {key: 'world', num: 1}
template: {message: 'hello ${key}', 'k-${num}': true}
result: {message: 'hello world', 'k-1': true}
---
title: string interpolation with object evaluation
context: {key: 'world', num: 1}
template: {message: 'hello ${{a: "world"}.a}', 'k-${{a: 1}.a + {a: 0}.a}': true}
result: {message: 'hello world', 'k-1': true}
---
title: multiple string interpolation (1)
context: {a: 'hello', b: 'world'}
template: {message: '${a} ${b}'}
result: {message: 'hello world'}
---
title: multiple string interpolation (2)
context: {a: 'hello', b: 'world'}
template: {message: '${a}$$${b}'}
result: {message: 'hello$${b}'}
---
title: multiple string interpolation (3)
context: {a: 'hello', b: 'world'}
template: {message: '${a}##${b}'}
result: {message: 'hello##world'}
---
title: string interpolation escapes
context: {}
template: {message: 'a literal $${in a string}'}
result: {message: 'a literal ${in a string}'}
---
title: string interpolation of keys
context: {name: 'foo', value: 'bar'}
template: {"tc_${name}": "${value}"}
result: {"tc_foo": "bar"}
---
title: string interpolation with unbalanced }
context: {}
template: {message: 'tricky ${"}}}}"}'}
result: {message: 'tricky }}}}'}
---
title: can't interpolate arrays
context: {key: [1,2,3]}
template: {message: 'hello ${key}'}
error: "TemplateError at template.message: interpolation of 'key' produced an array or object"
---
title: can't interpolate objects
context: {key: {}}
template: 'hello ${key}'
error: "TemplateError: interpolation of 'key' produced an array or object"
---
title: booleans interpolate
context: {t: true, f: false}
template: '${t} or ${f}: yeast is a bacterium'
result: 'true or false: yeast is a bacterium'
---
title: numbers interpolate
context: {round: 3, decimal: 3.75}
template: '${round}, really ${decimal}'
result: '3, really 3.75'
---
title: nulls interpolate
context: {nothing: null}
template: 'big pile of ${nothing}'
result: 'big pile of '
---
title: invalid context
context: {'a b c': 1}
template: {}
error: 'TemplateError: top level keys of context must follow /[a-zA-Z_][a-zA-Z0-9_]*/'
################################################################################
---
section: $if operator
---
title: $if-then-else, true
context: {cond: true}
template: {$if: 'cond', then: 1, else: 2}
result: 1
---
title: $if-then-else, false
context: {cond: false}
template: {$if: 'cond', then: 1, else: 2}
result: 2
---
title: $if-then in array, true
context: {cond: true}
template: [0, {$if: 'cond', then: 1}]
result: [0, 1]
---
title: $if-then in array, false
context: {cond: false}
template: [0, {$if: 'cond', then: 1}]
result: [0] # missing else branch should return a delete-marker
---
title: $if-then in object, true
context: {cond: true}
template: {key: {$if: 'cond', then: 1}, k2: 3}
result: {key: 1, k2: 3}
---
title: $if-then in object, false
context: {cond: false}
template: {key: {$if: 'cond', then: 1}, k2: 3}
result: {k2: 3} # missing else branch should return a delete-marker
---
title: $if -> delete-marker, true
context: {cond: true}
template: {key: {$if: 'cond'}, k2: 3}
result: {k2: 3} # missing then/else branches should return a delete-marker
---
title: $if -> delete-marker, false
context: {cond: false}
template: {key: {$if: 'cond'}, k2: 3}
result: {k2: 3} # missing then/else branches should return a delete-marker
---
title: $if->then, then => $eval, true
context: {key: {b: 1}}
template: {$if: 'true', then: {$eval: 'key'}}
result: {b: 1}
---
title: $if->else, else => $eval, false
context: {key: {b: 1}}
template: {$if: 'false', else: {$eval: 'key'}}
result: {b: 1}
---
title: $if->then, then => ${}, true
context: {key: 'one'}
template: {$if: 'true', then: '${key}'}
result: 'one'
---
title: $if->else, else => ${}, false
context: {key: 'one'}
template: {$if: 'false', else: '${key}'}
result: 'one'
---
title: $if->then, then => object, true
context: {cond: true}
template: {$if: 'cond', then: {key: 'hello world'}}
result: {key: 'hello world'}
---
title: $if->else, else => object, false
context: {cond: false}
template: {$if: 'cond', else: {key: 'hello world'}}
result: {key: 'hello world'}
---
title: $if->then, then => object, $eval, true
context: {cond: true, key: 'hello world'}
template: {$if: 'cond', then: {key: {$eval: 'key'}}}
result: {key: 'hello world'}
---
title: $if->else, else => object, $eval, false
context: {cond: false, key: 'hello world'}
template: {$if: 'cond', else: {key: {$eval: 'key'}}}
result: {key: 'hello world'}
---
title: $if->then, then => object, interpolation, true
context: {cond: true, key: 'world'}
template: {$if: 'cond', then: {key: 'hello ${key}'}}
result: {key: 'hello world'}
---
title: $if->else, else => object, interpolation, false
context: {cond: false, key: 'world'}
template: {$if: 'cond', else: {key: 'hello ${key}'}}
result: {key: 'hello world'}
---
title: $if->then->else, empty string
context: {cond: "", key: 'world'}
template: {$if: 'cond', then: "t", else: "f"}
result: f
---
title: $if->then->else, nonempty string
context: {cond: "stuff", key: 'world'}
template: {$if: 'cond', then: "t", else: "f"}
result: t
---
title: $if->then->else, string "0" # once upon a time, this was false in PHP.. maybe still is
context: {cond: "0", key: 'world'}
template: {$if: 'cond', then: "t", else: "f"}
result: t
---
title: $if->then->else, zero
context: {cond: 0, key: 'world'}
template: {$if: 'cond', then: "t", else: "f"}
result: f
---
title: $if->then->else, one
context: {cond: 1, key: 'world'}
template: {$if: 'cond', then: "t", else: "f"}
result: t
---
title: $if->then->else, null
context: {cond: null, key: 'world'}
template: {$if: 'cond', then: "t", else: "f"}
result: f
---
title: $if->then->else, empty array
context: {cond: [], key: 'world'}
template: {$if: 'cond', then: "t", else: "f"}
result: f
---
title: $if->then->else, nonempty array
context: {cond: [1, 2], key: 'world'}
template: {$if: 'cond', then: "t", else: "f"}
result: t
---
title: $if->then->else, empty object
context: {cond: {}, key: 'world'}
template: {$if: 'cond', then: "t", else: "f"}
result: f
---
title: $if->then->else, nonempty object
context: {cond: {a: 2}, key: 'world'}
template: {$if: 'cond', then: "t", else: "f"}
result: t
---
title: $if->then->else, function
context: {}
template: {$if: 'min', then: "t", else: "f"}
result: t
---
title: $if->then evaluating to nothing at the top level is null
context: {cond: false}
template: {$if: 'cond', then: "t"}
result: null
---
title: $if-then-else with undefined properties
context: {cond: true}
template: {$if: 'cond', then: 1, foo: 'bar', else: 2, bing: 'baz'}
error: 'TemplateError: $if has undefined properties: bing foo'
################################################################################
---
section: escape operators
---
title: escape $eval
context: {}
template: {$$eval: "1+2"}
result: {$eval: "1+2"}
---
title: escape $flatten
context: {}
template: {$$flatten: [[1, 2], [3, 4], [5]]}
result: {$flatten: [[1, 2], [3, 4], [5]]}
---
title: escape $fromNow
context: {}
template: {$$fromNow: "2 days"}
result: {$fromNow: "2 days"}
---
title: escape $if
context: {}
template: {$$if: false}
result: {$if: false}
---
title: escape $json
context: {}
template: {$$json: [1, 2, 3]}
result: {$json: [1, 2, 3]}
---
title: escape $let
context: {}
template: {$$let: {ts: 100, foo: 200}, in: [{$$eval: "ts+foo"}]}
result: {$let: {ts: 100, foo: 200}, in: [{$eval: "ts+foo"}]}
---
title: escape $map
context: {}
template: {$$map: [2, 4, 6], each(x): {$$eval: "x + a"}}
result: {$map: [2, 4, 6], each(x): {$eval: "x + a"}}
---
title: escape $merge
context: {}
template: {$$merge: [{a: 1}, {a: 2}]}
result: {$merge: [{a: 1}, {a: 2}]}
---
title: escape $reverse
context: {}
template: {$$reverse: [3, 2, 1]}
result: {$reverse: [3, 2, 1]}
---
title: escape $sort
context: {}
template: {$$sort: [3, 2, 1]}
result: {$sort: [3, 2, 1]}
---
title: reserved $-keywords
context: {}
template: {$nothing: 1}
error: 'TemplateError: $<identifier> is reserved; ues $$<identifier>'
---
title: escape non-json-e operator
context: {}
template: {$$nothing: 1}
result: {$nothing: 1}
################################################################################
---
section: $flatten
---
title: simple flatten
context: {}
template: {$flatten: [[1, 2], [3, 4], [5]]}
result: [1, 2, 3, 4, 5]
---
title: flatten empty array
context: {}
template: {$flatten: []}
result: []
---
title: flatten empty array of arrays
context: {}
template: {$flatten: [[]]}
result: []
---
title: flatten evaluated value
context: {}
template: {$flatten: {$eval: '[[1], [2, 3]]'}}
result: [1, 2, 3]
---
title: flatten null
context: {}
template: {$flatten: null}
error: 'TemplateError: $flatten value must evaluate to an array'
---
title: flatten an object
context: {}
template: {$flatten: {a: 1, b: 2}}
error: 'TemplateError: $flatten value must evaluate to an array'
---
title: flatten an array of strings
context: {}
template: {$flatten: ["a", "b"]}
result: ["a", "b"]
---
title: flatten an array of numbers
context: {}
template: {$flatten: [1, 2]}
result: [1, 2]
---
title: flatten mixed types
context: {}
template: {$flatten: [[1, 2], [['a', 'b']], [{}], [[]]]}
result: [1, 2, ['a', 'b'], {}, []]
---
title: flatten mixed levels
context: {}
template: {$flatten: [[1, [2, 3]], [4], 5]}
result: [1, [2, 3], 4, 5]
---
title: flatten with undefined properties
context: {}
template: {$flatten: {$eval: '[[1], [2, 3]]'}, foo: 'bar'}
error: 'TemplateError: $flatten has undefined properties: foo'
################################################################################
---
section: $flattenDeep
---
title: simple flattenDeep
context: {}
template: {$flattenDeep: [[1, [2, [3]]]]}
result: [1, 2, 3]
---
title: flattenDeep empty array
context: {}
template: {$flattenDeep: []}
result: []
---
title: evaluated value
context: {}
template: {$flattenDeep: {$eval: '[[1], [2, [3]]]'}}
result: [1, 2, 3]
---
title: flattenDeep empty array of arrays
context: {}
template: {$flattenDeep: [[]]}
result: []
---
title: flattenDeep null
context: {}
template: {$flattenDeep: null}
error: 'TemplateError: $flattenDeep value must evaluate to an array'
---
title: flattenDeep an object
context: {}
template: {$flattenDeep: {a: 1, b: 2}}
error: 'TemplateError: $flattenDeep value must evaluate to an array'
---
title: flattenDeep an array of strings
context: {}
template: {$flattenDeep: ["a", "b"]}
result: ["a", "b"]
---
title: flattenDeep an array of numbers
context: {}
template: {$flattenDeep: [1, 2]}
result: [1, 2]
---
title: flattenDeep mixed types
context: {}
template: {$flattenDeep: [[1, 2], [['a', 'b']], [{}], [[]]]}
result: [1, 2, 'a', 'b', {}]
---
title: flattenDeep mixed levels
context: {}
template: {$flattenDeep: [[1, [2, 3]], [4], 5]}
result: [1, 2, 3, 4, 5]
---
title: flattenDeep with undefined properties
context: {}
template: {$flattenDeep: [[1, [2, 3]], [4], 5], foo: 'bar'}
error: 'TemplateError: $flattenDeep has undefined properties: foo'
################################################################################
---
section: fromNow
---
title: fromNow 1 hour
context: {}
template: {$fromNow: '1 hour'}
result: '2017-01-19T17:27:20.974Z'
---
title: fromNow 2 hours
context: {}
template: {$fromNow: '2 hours'}
result: '2017-01-19T18:27:20.974Z'
---
title: fromNow 3h
context: {}
template: {$fromNow: '3h'}
result: '2017-01-19T19:27:20.974Z'
---
title: fromNow 1 hours
context: {}
template: {$fromNow: '1 hours'}
result: '2017-01-19T17:27:20.974Z'
---
title: fromNow -1 hour
context: {}
template: {$fromNow: '-1 hour'}
result: '2017-01-19T15:27:20.974Z'
---
title: fromNow 1 m
context: {}
template: {$fromNow: '1 m'}
result: '2017-01-19T16:28:20.974Z'
---
title: fromNow 1m
context: {}
template: {$fromNow: '1m'}
result: '2017-01-19T16:28:20.974Z'
---
title: fromNow 12 min
context: {}
template: {$fromNow: '12 min'}
result: '2017-01-19T16:39:20.974Z'
---
title: fromNow 12min
context: {}
template: {$fromNow: '12min'}
result: '2017-01-19T16:39:20.974Z'
---
title: fromNow 11m
context: {}
template: {$fromNow: '11m'}
result: '2017-01-19T16:38:20.974Z'
---
title: fromNow 11 m
context: {}
template: {$fromNow: '11 m'}
result: '2017-01-19T16:38:20.974Z'
---
title: fromNow 1 day
context: {}
template: {$fromNow: '1 day'}
result: '2017-01-20T16:27:20.974Z'
---
title: fromNow 2 days
context: {}
template: {$fromNow: '2 days'}
result: '2017-01-21T16:27:20.974Z'
---
title: fromNow 1 second
context: {}
template: {$fromNow: '1 second'}
result: '2017-01-19T16:27:21.974Z'
---
title: fromNow 1 week
context: {}
template: {$fromNow: '1 week'}
result: '2017-01-26T16:27:20.974Z'
---
title: fromNow 1 month
context: {}
template: {$fromNow: '1 month'}
result: '2017-02-18T16:27:20.974Z'
---
title: fromNow 30 mo
context: {}
template: {$fromNow: '30 mo'}
result: '2019-07-08T16:27:20.974Z'
---
title: fromNow -30 mo
context: {}
template: {$fromNow: '-30 mo'}
result: '2014-08-03T16:27:20.974Z'
---
title: fromNow 1 year
context: {}
template: {$fromNow: '1 year'}
result: '2018-01-19T16:27:20.974Z'
---
title: fromNow of non-string
context: {}
template: {$fromNow: 13}
error: 'TemplateError: $fromNow expects a string'
---
title: fromNow with eval
context: {ttl: 24}
template: {$fromNow: {$eval: 'str(ttl) + " hours"'}}
result: '2017-01-20T16:27:20.974Z'
---
title: fromNow with reference
context: {now: '2019-01-01T01:00:00.123Z'}
template: {$fromNow: '3 mo', from: {$eval: now}}
result: '2019-04-01T01:00:00.123Z'
---
title: fromNow with undefined properties
context: {now: '2019-01-01T01:00:00.123Z'}
template: {$fromNow: '3 mo', from: {$eval: now}, foo: 'bar'}
error: 'TemplateError: $fromNow has undefined properties: foo'
################################################################################
---
section: $json
---
title: wrap expressions with $eval
context: {a: 1, b: 2}
template: {$json: {$eval: 'a + b + 7'}}
result: '10'
---
title: unwrap expressions not evaluated
context: {a: 1, b: 2}
template: {$json: 'a + b + 7'}
result: '"a + b + 7"'
---
title: $eval inside array
context: {a: 1, b: 2}
template: {$json: [2, 5, {$eval: 'a + b + 7'}]}
result: '[2,5,10]'
---
title: $json with undefined properties
context: {}
template: {$json: [1,2,true,{},[]], foo: 'bar'}
error: 'TemplateError: $json has undefined properties: foo'
################################################################################
---
section: accessing nested objects => context
---
title: $eval
context: {key: {key2: ['value', 1, 2, true, {}]}}
template: {$eval: 'key.key2'}
result: ['value', 1, 2, true, {}]
---
title: $json
context: {key: {key2: [1,2,true,{},[]]}}
template: {$json: {$eval: 'key.key2'}}
result: '[1,2,true,{},[]]'
---
title: string interpolation
context: {key: {key2: 'world', key3: 1}}
template: {message: 'hello ${key.key2}', 'k-${key.key3}': true}
result: {message: 'hello world', 'k-1': true}
---
title: string interpolation, first character
context: {somevalue: 13}
template: {message: '${somevalue}'}
result: {message: '13'}
---
title: no string interpolation with $$
context: {somevalue: 13}
template: {message: '$${somevalue}'}
result: {message: '${somevalue}'}
################################################################################
---
section: $let
---
title: simple let
template: {$let: {ts: 100, foo: 200,}, in: [{$eval: "ts+foo"}, {$eval: "ts-foo"}, {$eval: "ts*foo"}]}
context: {}
result: [300, -100, 20000]
---
title: let with evaluated values
template: {$let: {thirty: {$eval: "10 + 20"}}, in: {$eval: "thirty+5"}}
context: {}
result: 35
---
title: let with evaluated context
template: {$let: {$eval: '{"thirty": 10 + 20}'}, in: {$eval: "thirty+5"}}
context: {}
result: 35
---
title: context overriding
template: {$let: {x: 20}, in: {$eval: "x + y"}}
context: {x: 10, y: 1}
result: 21
---
title: nested let
template: {$let: {x: 20, y: 10}, in: {$let: {x: 30}, in: {$eval: "x + y + z"}}}
context: {x: 1, y: 2, z: 3}
result: 43
---
title: let with undefined properties
template: {$let: {x: 1, y: 2}, a: {$eval: "x + y"}}
context: {}
error: 'TemplateError: $let has undefined properties: a'
---
title: let array
template: {$let: [1, 2], in: {$eval: "1 + 2"}}
context: {}
error: 'TemplateError: $let value must evaluate to an object'
---
title: let null
template: {$let: null, in: {$eval: "1 + 2"}}
context: {}
error: 'TemplateError: $let value must evaluate to an object'
################################################################################
---
section: $map
---
title: simple map
context: {a: 1}
template:
$map: [2, 4, 6]
each(x): {$eval: 'x + a'}
result: [3, 5, 7]
---
title: map to objects
context: {a: 1}
template:
$map: [2, 4, 6]
each(x):
asText: '${x + a}'
integer: {$eval: 'x + a'}
result:
- {asText: '3', integer: 3}
- {asText: '5', integer: 5}
- {asText: '7', integer: 7}
---
title: complex identifier
context: {a: 1}
template:
$map: [2, 4, 6]
each(my_identifier97): {$eval: 'my_identifier97 + a'}
result: [3, 5, 7]
---
title: must wrap expressions with $eval
context: {a: 1}
template:
$map: [2, 4, 6]
each(my_identifier97): 'my_identifier97 + a'
result: ['my_identifier97 + a', 'my_identifier97 + a', 'my_identifier97 + a']
---
title: can take from objects
context: {a: 1}
template:
$map: [{k: 1}, {k: 2}, {k: 3}]
each(y): {$eval: 'y.k'}
result: [1, 2, 3]
---
title: value is rendered
context: {a: 1}
template:
$map: {$eval: '[{k: 1}, {k: 2}, {k: 3}]'}
each(y): {$eval: 'y.k'}
result: [1, 2, 3]
---
title: can make objects too
context: {a: 1}
template:
$map: [{k: 1}, {k: 2}, {k: 3}]
each(y):
k: {$eval: 'y.k + 1'}
v: 'before=${y.k}'
result:
- k: 2
v: 'before=1'
- k: 3
v: 'before=2'
- k: 4
v: 'before=3'
---
title: respects delete-marker from $if
context: {a: 1}
template:
$map: [{k: 1}, {k: 2}, {k: 3}]
each(y):
$if: 'y.k != 2'
then: {$eval: 'y.k'}
result: [1, 3]
---
title: $map works on array or object
context: {}
template:
$map: {a: 1, b: 2, c: 3}
each(y): {'${y.key}x': {$eval: 'y.val + 1'}}
result: {ax: 2, bx: 3, cx: 4}
---
title: $map can add new keys to object
context: {}
template:
$map: {a: 1, b: 2, c: 3}
each(y): {'${y.key}': {$eval: 'y.val'}, '${y.key}x': {$eval: 'y.val + 1'}}
result: {a: 1, b: 2, c: 3, ax: 2, bx: 3, cx: 4}
---
title: $map requires an array, not string
context: {}
template:
$map: "a, b, c"
each(y): {$eval: 'y.k'}
error: 'TemplateError: $map value must evaluate to an array or object'
---
title: $map requires an array, not number
context: {}
template:
$map: 10.1
each(y): {$eval: 'y.k'}
error: 'TemplateError: $map value must evaluate to an array or object'
---
title: $map requires an array, not null
context: {}
template:
$map: null
each(y): {$eval: 'y.k'}
error: 'TemplateError: $map value must evaluate to an array or object'
---
title: map with undefined properties
context: {a: 1}
template:
$map: [2, 4, 6]
each(x): {$eval: 'x + a'}
foo: 'bar'
error: 'TemplateError: $map has undefined properties: foo'
################################################################################
---
section: $merge
---
title: simple merge
context: {}
template: {$merge: [{a: 1, b: 1}, {b: 2, c: 3}, {d: 4}]}
result: {a: 1, b: 2, c: 3, d: 4}
---
title: value is evaluated
context: {defaults: {d: 4}}
template: {$merge: [{a: 1, b: 1}, {b: 2, c: 3}, {$eval: defaults}]}
result: {a: 1, b: 2, c: 3, d: 4}
---
title: merge empty array
context: {}
template: {$merge: []}
result: {}
---
title: merge empty array with empty object
context: {}
template: {$merge: [{}]}
result: {}
---
title: merge null
context: {}
template: {$merge: null}
error: 'TemplateError: $merge value must evaluate to an array of objects'
---
title: $merge [null]
template: {$merge: [null]}
context: {}
error: 'TemplateError: $merge value must evaluate to an array of objects'
---
title: merge with undefined properties
template: {$merge: [{a: 1}, {b: 2, c: 3}, {d: 4}], foo: "bar", bing: "baz"}
context: {}
error: 'TemplateError: $merge has undefined properties: bing foo'
################################################################################
---
section: $mergeDeep
---
title: simple non-deep mergeDeep matches merge
context: {}
template: {$mergeDeep: [{a: 1, b: 1}, {b: 2, c: 3}, {d: 4}]}
result: {a: 1, b: 2, c: 3, d: 4}
---
title: deep merge of lists appends
context: {}
template: {$mergeDeep: [{a: [1, 2]}, {a: [3, 4]}]}
result: {a: [1, 2, 3, 4]}
---
title: deep merge of objects merges
context: {}
template: {$mergeDeep: [{a: {x: 1, y: 2}}, {a: {y: 3, z: 4}}]}
result: {a: {x: 1, y: 3, z: 4}}
---
title: very deep merge
context: {}
template:
$mergeDeep:
- task:
payload:
command: [a, b]
- task:
extra:
foo: bar
- task:
payload:
command: [c]
result:
task:
extra:
foo: bar
payload:
command: [a, b, c]
---
title: value is evaluated
context: {defaults: {d: 4}}
template: {$mergeDeep: [{a: 1, b: 1}, {b: 2, c: 3}, {$eval: defaults}]}
result: {a: 1, b: 2, c: 3, d: 4}
---
title: mergeDeep empty array
context: {}
template: {$mergeDeep: []}
result: {}
---
title: mergeDeep empty array with empty object
context: {}
template: {$mergeDeep: [{}]}
result: {}
---
title: mergeDeep null
context: {}
template: {$mergeDeep: null}
error: 'TemplateError: $mergeDeep value must evaluate to an array of objects'
---
title: $mergeDeep [null]
template: {$mergeDeep: [null]}
context: {}
error: 'TemplateError: $mergeDeep value must evaluate to an array of objects'
---
title: mergeDeep with undefined properties
template: {$mergeDeep: [{a: {x: 1, y: 2}}, {a: {y: 3, z: 4}}], foo: "bar", bing: "baz"}
context: {}
error: 'TemplateError: $mergeDeep has undefined properties: bing foo'
################################################################################
---
section: $sort
---
title: simple sort
context: {}
template: {$sort: [3, 4, 1, 2]}
result: [1, 2, 3, 4]
---
title: simple sort of strings (shortest first)
context: {}
template: {$sort: ['android', 'aardvark', 'add', 'adderall']}
result: ['aardvark', 'add', 'adderall', 'android']
---
title: simple sort of multi-digit numbers
context: {}
template: {$sort: [111, 22, 3]}
result: [3, 22, 111]
---
title: sort of mixed array
context: {}
template: {$sort: [1, "2", 2, 3, "111", "112"]}
error: true
---
title: simple sort with $eval
context: {array: [3, 4, 1, 2]}
template: {$sort: {$eval: 'array'}}
result: [1, 2, 3, 4]
---
title: sort by, returning number
context: {}
template:
$sort: [{a: 20}, {a: 10, b: []}, {a: 3}]
by(x): 'x.a'
result: [{a: 3}, {a: 10, b: []}, {a: 20}]
---
title: sort by, returning string
context: {}
template:
$sort: [{s: 'android'}, {s: 'add'}, {s: 'adderall'}]
by(x): 'x.s'
result: [{s: 'add'}, {s: 'adderall'}, {s: 'android'}]
---
title: cannot sort objects without by
context: {}
template:
$sort: [{a: 2}, {a: 1, b: []}, {a: 3}]
error: true
---
title: by cannot return objects
context: {}
template:
$sort: [{a: 2}, {a: 1, b: []}, {a: 3}]
by(x): x
error: true
---
title: cannot sort arrays without by
context: {}
template:
$sort: [[1,2,3], [4,5], [], [8,9,10]]
error: true
---
title: by cannot return arrays
context: {}
template:
$sort: [[1,2,3], [4,5], [], [8,9,10]]
by(x): x
error: true
---
title: cannot sort nulls
context: {}
template: {$sort: [null, null]}
error: true
---
title: cannot sort nulls, even with by
context: {}
template: {$sort: [null, null], 'by(x)': 'x'}
error: true
---
title: cannot sort booleans
context: {}
template: {$sort: [false, true]}
error: true
---
title: cannot sort booleans, even with by
context: {}
template: {$sort: [false, true], 'by(x)': 'x'}
error: true
---
title: cannot sort numbers and strings together
context: {}
template: {$sort: [1, 'a']}
error: true
---
title: cannot sort numbers and strings together even with by
context: {}
template: {$sort: [1, 'a'], 'by(x)': 'x'}
error: true
---
title: sort requires an array (string)
context: {}
template:
$sort: "some string"
error: true # $sort must be given an array
---
title: sort requires an array (number)
context: {}
template:
$sort: 34
error: true # $sort must be given an array
---
title: sort requires an array (object)
context: {}
template:
$sort: {k: 1, b: 4, x: 8}
error: true # $sort must be given an array
---