@port-labs/jq-node-bindings 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/.editorconfig +5 -0
  2. package/.jshintignore +1 -0
  3. package/.jshintrc +23 -0
  4. package/binding.gyp +56 -0
  5. package/configure +26 -0
  6. package/deps/jq/.gitattributes +2 -0
  7. package/deps/jq/.travis.yml +53 -0
  8. package/deps/jq/AUTHORS +73 -0
  9. package/deps/jq/COPYING +70 -0
  10. package/deps/jq/ChangeLog +1349 -0
  11. package/deps/jq/Makefile.am +198 -0
  12. package/deps/jq/NEWS +88 -0
  13. package/deps/jq/README.md +64 -0
  14. package/deps/jq/builtin.c +1684 -0
  15. package/deps/jq/builtin.h +10 -0
  16. package/deps/jq/bytecode.c +161 -0
  17. package/deps/jq/bytecode.h +92 -0
  18. package/deps/jq/compile-ios.sh +102 -0
  19. package/deps/jq/compile.c +1210 -0
  20. package/deps/jq/compile.h +101 -0
  21. package/deps/jq/config/m4/check-math-func.m4 +4 -0
  22. package/deps/jq/config/m4/find-func-no-libs.m4 +8 -0
  23. package/deps/jq/config/m4/find-func-no-libs2.m4 +62 -0
  24. package/deps/jq/config/m4/find-func.m4 +9 -0
  25. package/deps/jq/config/m4/misc.m4 +3 -0
  26. package/deps/jq/configure.ac +221 -0
  27. package/deps/jq/docs/Gemfile +7 -0
  28. package/deps/jq/docs/Gemfile.lock +63 -0
  29. package/deps/jq/docs/README.md +25 -0
  30. package/deps/jq/docs/Rakefile +145 -0
  31. package/deps/jq/docs/content/1.tutorial/default.yml +327 -0
  32. package/deps/jq/docs/content/2.download/default.yml +117 -0
  33. package/deps/jq/docs/content/3.manual/manual.yml +2878 -0
  34. package/deps/jq/docs/content/3.manual/v1.3/manual.yml +1270 -0
  35. package/deps/jq/docs/content/3.manual/v1.4/manual.yml +1672 -0
  36. package/deps/jq/docs/content/index/index.yml +51 -0
  37. package/deps/jq/docs/default_manpage.md +22 -0
  38. package/deps/jq/docs/public/.htaccess +28 -0
  39. package/deps/jq/docs/public/bootstrap/css/bootstrap-responsive.css +1058 -0
  40. package/deps/jq/docs/public/bootstrap/css/bootstrap-responsive.min.css +9 -0
  41. package/deps/jq/docs/public/bootstrap/css/bootstrap.css +5224 -0
  42. package/deps/jq/docs/public/bootstrap/css/bootstrap.min.css +9 -0
  43. package/deps/jq/docs/public/bootstrap/img/glyphicons-halflings-white.png +0 -0
  44. package/deps/jq/docs/public/bootstrap/img/glyphicons-halflings.png +0 -0
  45. package/deps/jq/docs/public/bootstrap/js/bootstrap.js +2027 -0
  46. package/deps/jq/docs/public/bootstrap/js/bootstrap.min.js +6 -0
  47. package/deps/jq/docs/public/css/base.scss +99 -0
  48. package/deps/jq/docs/public/jq.png +0 -0
  49. package/deps/jq/docs/public/robots.txt +2 -0
  50. package/deps/jq/docs/site.yml +18 -0
  51. package/deps/jq/docs/templates/default.liquid +34 -0
  52. package/deps/jq/docs/templates/index.liquid +60 -0
  53. package/deps/jq/docs/templates/manual.liquid +122 -0
  54. package/deps/jq/docs/templates/shared/_footer.liquid +5 -0
  55. package/deps/jq/docs/templates/shared/_head.liquid +12 -0
  56. package/deps/jq/docs/templates/shared/_header.liquid +26 -0
  57. package/deps/jq/exec_stack.h +112 -0
  58. package/deps/jq/execute.c +1155 -0
  59. package/deps/jq/inject_errors.c +112 -0
  60. package/deps/jq/jq.1.default +39 -0
  61. package/deps/jq/jq.1.prebuilt +3075 -0
  62. package/deps/jq/jq.h +60 -0
  63. package/deps/jq/jq.spec +70 -0
  64. package/deps/jq/jq_parser.h +9 -0
  65. package/deps/jq/jq_test.c +346 -0
  66. package/deps/jq/jv.c +1333 -0
  67. package/deps/jq/jv.h +240 -0
  68. package/deps/jq/jv_alloc.c +179 -0
  69. package/deps/jq/jv_alloc.h +27 -0
  70. package/deps/jq/jv_aux.c +619 -0
  71. package/deps/jq/jv_dtoa.c +4275 -0
  72. package/deps/jq/jv_dtoa.h +22 -0
  73. package/deps/jq/jv_file.c +49 -0
  74. package/deps/jq/jv_parse.c +852 -0
  75. package/deps/jq/jv_print.c +348 -0
  76. package/deps/jq/jv_unicode.c +96 -0
  77. package/deps/jq/jv_unicode.h +11 -0
  78. package/deps/jq/jv_utf8_tables.h +37 -0
  79. package/deps/jq/lexer.c +2442 -0
  80. package/deps/jq/lexer.h +362 -0
  81. package/deps/jq/lexer.l +184 -0
  82. package/deps/jq/libm.h +160 -0
  83. package/deps/jq/linker.c +393 -0
  84. package/deps/jq/linker.h +7 -0
  85. package/deps/jq/locfile.c +91 -0
  86. package/deps/jq/locfile.h +29 -0
  87. package/deps/jq/m4/ax_compare_version.m4 +177 -0
  88. package/deps/jq/m4/ax_prog_bison_version.m4 +68 -0
  89. package/deps/jq/main.c +566 -0
  90. package/deps/jq/opcode_list.h +44 -0
  91. package/deps/jq/parser.c +3914 -0
  92. package/deps/jq/parser.h +193 -0
  93. package/deps/jq/parser.y +923 -0
  94. package/deps/jq/scripts/crosscompile +42 -0
  95. package/deps/jq/scripts/gen_utf8_tables.py +32 -0
  96. package/deps/jq/scripts/version +5 -0
  97. package/deps/jq/setup.sh +33 -0
  98. package/deps/jq/tests/jq.test +1235 -0
  99. package/deps/jq/tests/jqtest +5 -0
  100. package/deps/jq/tests/mantest +7 -0
  101. package/deps/jq/tests/modules/.jq +5 -0
  102. package/deps/jq/tests/modules/a.jq +2 -0
  103. package/deps/jq/tests/modules/b/b.jq +2 -0
  104. package/deps/jq/tests/modules/c/c.jq +16 -0
  105. package/deps/jq/tests/modules/c/d.jq +1 -0
  106. package/deps/jq/tests/modules/data.json +4 -0
  107. package/deps/jq/tests/modules/lib/jq/e/e.jq +1 -0
  108. package/deps/jq/tests/modules/lib/jq/f.jq +1 -0
  109. package/deps/jq/tests/modules/syntaxerror/syntaxerror.jq +1 -0
  110. package/deps/jq/tests/modules/test_bind_order.jq +4 -0
  111. package/deps/jq/tests/modules/test_bind_order0.jq +1 -0
  112. package/deps/jq/tests/modules/test_bind_order1.jq +2 -0
  113. package/deps/jq/tests/modules/test_bind_order2.jq +2 -0
  114. package/deps/jq/tests/onig.supp +21 -0
  115. package/deps/jq/tests/onig.test +85 -0
  116. package/deps/jq/tests/onigtest +5 -0
  117. package/deps/jq/tests/setup +36 -0
  118. package/deps/jq/tests/shtest +205 -0
  119. package/deps/jq/tests/torture/input0.json +7 -0
  120. package/deps/jq/util.c +462 -0
  121. package/deps/jq/util.h +64 -0
  122. package/deps/jq.gyp +35 -0
  123. package/index.d.ts +3 -0
  124. package/jest.config.js +10 -0
  125. package/lib/index.js +14 -0
  126. package/package.json +48 -0
  127. package/reports/jest-port-api.xml +35 -0
  128. package/src/binding.cc +177 -0
  129. package/src/binding.h +13 -0
  130. package/test/santiy.test.js +122 -0
  131. package/util/configure.js +27 -0
@@ -0,0 +1,1235 @@
1
+ # Tests are groups of three lines: program, input, expected output
2
+ # Blank lines and lines starting with # are ignored
3
+
4
+ #
5
+ # Simple value tests to check parser. Input is irrelevant
6
+ #
7
+
8
+ true
9
+ null
10
+ true
11
+
12
+ false
13
+ null
14
+ false
15
+
16
+ null
17
+ 42
18
+ null
19
+
20
+ 1
21
+ null
22
+ 1
23
+
24
+
25
+ -1
26
+ null
27
+ -1
28
+
29
+ # FIXME: much more number testing needed
30
+
31
+ {}
32
+ null
33
+ {}
34
+
35
+ []
36
+ null
37
+ []
38
+
39
+ {x: -1}
40
+ null
41
+ {"x": -1}
42
+
43
+ # The input line starts with a 0xFEFF (byte order mark) codepoint
44
+ # No, there is no reason to have a byte order mark in UTF8 text.
45
+ # But apparently people do, so jq shouldn't break on it.
46
+ .
47
+ "byte order mark"
48
+ "byte order mark"
49
+
50
+ # We test escapes by matching them against Unicode codepoints
51
+ # FIXME: more tests needed for weird unicode stuff (e.g. utf16 pairs)
52
+ "Aa\r\n\t\b\f\u03bc"
53
+ null
54
+ "Aa\u000d\u000a\u0009\u0008\u000c\u03bc"
55
+
56
+ .
57
+ "Aa\r\n\t\b\f\u03bc"
58
+ "Aa\u000d\u000a\u0009\u0008\u000c\u03bc"
59
+
60
+ "inter\("pol" + "ation")"
61
+ null
62
+ "interpolation"
63
+
64
+ @text,@json,([1,.] | (@csv, @tsv)),@html,@uri,@sh,@base64
65
+ "<>&'\"\t"
66
+ "<>&'\"\t"
67
+ "\"<>&'\\\"\\t\""
68
+ "1,\"<>&'\"\"\t\""
69
+ "1\t<>&'\"\\t"
70
+ "&lt;&gt;&amp;&apos;&quot;\t"
71
+ "%3C%3E%26'%22%09"
72
+ "'<>&'\\''\"\t'"
73
+ "PD4mJyIJ"
74
+
75
+ # regression test for #436
76
+ @base64
77
+ "foóbar\n"
78
+ "Zm/Ds2Jhcgo="
79
+
80
+ @uri
81
+ "\u03bc"
82
+ "%CE%BC"
83
+
84
+ @html "<b>\(.)</b>"
85
+ "<script>hax</script>"
86
+ "<b>&lt;script&gt;hax&lt;/script&gt;</b>"
87
+
88
+ [.[]|tojson|fromjson]
89
+ ["foo", 1, ["a", 1, "b", 2, {"foo":"bar"}]]
90
+ ["foo",1,["a",1,"b",2,{"foo":"bar"}]]
91
+
92
+ #
93
+ # Dictionary construction syntax
94
+ #
95
+
96
+ {a: 1}
97
+ null
98
+ {"a":1}
99
+
100
+ {a,b,(.d):.a,e:.b}
101
+ {"a":1, "b":2, "c":3, "d":"c"}
102
+ {"a":1, "b":2, "c":1, "e":2}
103
+
104
+ {"a",b,"a$\(1+1)"}
105
+ {"a":1, "b":2, "c":3, "a$2":4}
106
+ {"a":1, "b":2, "a$2":4}
107
+
108
+ #
109
+ # Field access, piping
110
+ #
111
+
112
+ .foo
113
+ {"foo": 42, "bar": 43}
114
+ 42
115
+
116
+ .foo | .bar
117
+ {"foo": {"bar": 42}, "bar": "badvalue"}
118
+ 42
119
+
120
+ .foo.bar
121
+ {"foo": {"bar": 42}, "bar": "badvalue"}
122
+ 42
123
+
124
+ .foo_bar
125
+ {"foo_bar": 2}
126
+ 2
127
+
128
+ .["foo"].bar
129
+ {"foo": {"bar": 42}, "bar": "badvalue"}
130
+ 42
131
+
132
+ ."foo"."bar"
133
+ {"foo": {"bar": 20}}
134
+ 20
135
+
136
+ [.[]|.foo?]
137
+ [1,[2],{"foo":3,"bar":4},{},{"foo":5}]
138
+ [3,null,5]
139
+
140
+ [.[]|.foo?.bar?]
141
+ [1,[2],[],{"foo":3},{"foo":{"bar":4}},{}]
142
+ [4,null]
143
+
144
+ [..]
145
+ [1,[[2]],{ "a":[1]}]
146
+ [[1,[[2]],{"a":[1]}],1,[[2]],[2],2,{"a":[1]},[1],1]
147
+
148
+ [.[]|.[]?]
149
+ [1,null,[],[1,[2,[[3]]]],[{}],[{"a":[1,[2]]}]]
150
+ [1,[2,[[3]]],{},{"a":[1,[2]]}]
151
+
152
+ [.[]|.[1:3]?]
153
+ [1,null,true,false,"abcdef",{},{"a":1,"b":2},[],[1,2,3,4,5],[1,2]]
154
+ [null,"bc",[],[2,3],[2]]
155
+
156
+ #
157
+ # Negative array indices
158
+ #
159
+
160
+ try (.foo[-1] = 0) catch .
161
+ null
162
+ "Out of bounds negative array index"
163
+
164
+ try (.foo[-2] = 0) catch .
165
+ null
166
+ "Out of bounds negative array index"
167
+
168
+ .[-1] = 5
169
+ [0,1,2]
170
+ [0,1,5]
171
+
172
+ .[-2] = 5
173
+ [0,1,2]
174
+ [0,5,2]
175
+
176
+ #
177
+ # Multiple outputs, iteration
178
+ #
179
+
180
+ .[]
181
+ [1,2,3]
182
+ 1
183
+ 2
184
+ 3
185
+
186
+ 1,1
187
+ []
188
+ 1
189
+ 1
190
+
191
+ 1,.
192
+ []
193
+ 1
194
+ []
195
+
196
+ [.]
197
+ [2]
198
+ [[2]]
199
+
200
+ [[2]]
201
+ [3]
202
+ [[2]]
203
+
204
+ [{}]
205
+ [2]
206
+ [{}]
207
+
208
+ [.[]]
209
+ ["a"]
210
+ ["a"]
211
+
212
+ [(.,1),((.,.[]),(2,3))]
213
+ ["a","b"]
214
+ [["a","b"],1,["a","b"],"a","b",2,3]
215
+
216
+ [([5,5][]),.,.[]]
217
+ [1,2,3]
218
+ [5,5,[1,2,3],1,2,3]
219
+
220
+ {x: (1,2)},{x:3} | .x
221
+ null
222
+ 1
223
+ 2
224
+ 3
225
+
226
+ .[-2]
227
+ [1,2,3]
228
+ 2
229
+
230
+ [range(0;10)]
231
+ null
232
+ [0,1,2,3,4,5,6,7,8,9]
233
+
234
+ [range(0;10;3)]
235
+ null
236
+ [0,3,6,9]
237
+
238
+ [range(0;10;-1)]
239
+ null
240
+ []
241
+
242
+ [range(0;-5;-1)]
243
+ null
244
+ [0,-1,-2,-3,-4]
245
+
246
+ [while(.<100; .*2)]
247
+ 1
248
+ [1,2,4,8,16,32,64]
249
+
250
+ [(label $here | .[] | if .>1 then break $here else . end), "hi!"]
251
+ [0,1,2]
252
+ [0,1,"hi!"]
253
+
254
+ [(label $here | .[] | if .>1 then break $here else . end), "hi!"]
255
+ [0,2,1]
256
+ [0,"hi!"]
257
+
258
+ %%FAIL
259
+ . as $foo | break $foo
260
+ jq: error: *label-foo/0 is not defined at <top-level>, line 1:
261
+
262
+ [.[]|[.,1]|until(.[0] < 1; [.[0] - 1, .[1] * .[0]])|.[1]]
263
+ [1,2,3,4,5]
264
+ [1,2,6,24,120]
265
+
266
+ [label $out | foreach .[] as $item ([3, null]; if .[0] < 1 then break $out else [.[0] -1, $item] end; .[1])]
267
+ [11,22,33,44,55,66,77,88,99]
268
+ [11,22,33]
269
+
270
+ [foreach range(5) as $item (0; $item)]
271
+ null
272
+ [0,1,2,3,4]
273
+
274
+ [foreach .[] as [$i, $j] (0; . + $i - $j)]
275
+ [[2,1], [5,3], [6,4]]
276
+ [1,3,5]
277
+
278
+ [foreach .[] as {a:$a} (0; . + $a; -.)]
279
+ [{"a":1}, {"b":2}, {"a":3, "b":4}]
280
+ [-1, -1, -4]
281
+
282
+ [limit(3; .[])]
283
+ [11,22,33,44,55,66,77,88,99]
284
+ [11,22,33]
285
+
286
+ [first(range(.)), last(range(.)), nth(0; range(.)), nth(5; range(.)), try nth(-1; range(.)) catch .]
287
+ 10
288
+ [0,9,0,5,"nth doesn't support negative indices"]
289
+
290
+ #
291
+ # Check that various builtins evalute all arguments where appropriate,
292
+ # doing cartesian products where appropriate.
293
+ #
294
+
295
+ # Check that limit does work for each value produced by n!
296
+ [limit(5,7; range(9))]
297
+ null
298
+ [0,1,2,3,4,0,1,2,3,4,5,6]
299
+
300
+ # Same check for nth
301
+ [nth(5,7; range(9;0;-1))]
302
+ null
303
+ [4,2]
304
+
305
+ # Same check for range/3
306
+ [range(0,1,2;4,3,2;2,3)]
307
+ null
308
+ [0,2,0,3,0,2,0,0,0,1,3,1,1,1,1,1,2,2,2,2]
309
+
310
+ # Same check for range/1
311
+ [range(3,5)]
312
+ null
313
+ [0,1,2,0,1,2,3,4]
314
+
315
+ # Same check for index/1, rindex/1, indices/1
316
+ [(index(",","|"), rindex(",","|")), indices(",","|")]
317
+ "a,b|c,d,e||f,g,h,|,|,i,j"
318
+ [1,3,22,19,[1,5,7,12,14,16,18,20,22],[3,9,10,17,19]]
319
+
320
+ # Same check for join/1
321
+ join(",","/")
322
+ ["a","b","c","d"]
323
+ "a,b,c,d"
324
+ "a/b/c/d"
325
+
326
+ [.[]|join("a")]
327
+ [[],[""],["",""],["","",""]]
328
+ ["","","a","aa"]
329
+
330
+ # Same check for flatten/1
331
+ flatten(3,2,1)
332
+ [0, [1], [[2]], [[[3]]]]
333
+ [0,1,2,3]
334
+ [0,1,2,[3]]
335
+ [0,1,[2],[[3]]]
336
+
337
+
338
+ #
339
+ # Slices
340
+ #
341
+
342
+ [.[3:2], .[-5:4], .[:-2], .[-2:], .[3:3][1:], .[10:]]
343
+ [0,1,2,3,4,5,6]
344
+ [[], [2,3], [0,1,2,3,4], [5,6], [], []]
345
+
346
+ [.[3:2], .[-5:4], .[:-2], .[-2:], .[3:3][1:], .[10:]]
347
+ "abcdefghi"
348
+ ["","","abcdefg","hi","",""]
349
+
350
+ del(.[2:4],.[0],.[-2:])
351
+ [0,1,2,3,4,5,6,7]
352
+ [1,4,5]
353
+
354
+ .[2:4] = ([], ["a","b"], ["a","b","c"])
355
+ [0,1,2,3,4,5,6,7]
356
+ [0,1,4,5,6,7]
357
+ [0,1,"a","b",4,5,6,7]
358
+ [0,1,"a","b","c",4,5,6,7]
359
+
360
+
361
+ #
362
+ # Variables
363
+ #
364
+
365
+ 1 as $x | 2 as $y | [$x,$y,$x]
366
+ null
367
+ [1,2,1]
368
+
369
+ [1,2,3][] as $x | [[4,5,6,7][$x]]
370
+ null
371
+ [5]
372
+ [6]
373
+ [7]
374
+
375
+ 42 as $x | . | . | . + 432 | $x + 1
376
+ 34324
377
+ 43
378
+
379
+ 1 as $x | [$x,$x,$x as $x | $x]
380
+ null
381
+ [1,1,1]
382
+
383
+ [1, {c:3, d:4}] as [$a, {c:$b, b:$c}] | $a, $b, $c
384
+ null
385
+ 1
386
+ 3
387
+ null
388
+
389
+ . as {as: $kw, "str": $str, ("e"+"x"+"p"): $exp} | [$kw, $str, $exp]
390
+ {"as": 1, "str": 2, "exp": 3}
391
+ [1, 2, 3]
392
+
393
+ .[] as [$a, $b] | [$b, $a]
394
+ [[1], [1, 2, 3]]
395
+ [null, 1]
396
+ [2, 1]
397
+
398
+ . as $i | . as [$i] | $i
399
+ [0]
400
+ 0
401
+
402
+ . as [$i] | . as $i | $i
403
+ [0]
404
+ [0]
405
+
406
+ %%FAIL
407
+ . as [] | null
408
+ jq: error: syntax error, unexpected ']', expecting '$' or '[' or '{' (Unix shell quoting issues?) at <top-level>, line 1:
409
+
410
+ %%FAIL
411
+ . as {} | null
412
+ jq: error: syntax error, unexpected '}' (Unix shell quoting issues?) at <top-level>, line 1:
413
+
414
+ # [.,(.[] | {x:.},.),.,.[]]
415
+
416
+ #
417
+ # Builtin functions
418
+ #
419
+
420
+ 1+1
421
+ null
422
+ 2
423
+
424
+ 1+1
425
+ "wtasdf"
426
+ 2.0
427
+
428
+ 2-1
429
+ null
430
+ 1
431
+
432
+ 2-(-1)
433
+ null
434
+ 3
435
+
436
+ 1e+0+0.001e3
437
+ "I wonder what this will be?"
438
+ 20e-1
439
+
440
+ .+4
441
+ 15
442
+ 19.0
443
+
444
+ .+null
445
+ {"a":42}
446
+ {"a":42}
447
+
448
+ null+.
449
+ null
450
+ null
451
+
452
+ .a+.b
453
+ {"a":42}
454
+ 42
455
+
456
+ [1,2,3] + [.]
457
+ null
458
+ [1,2,3,null]
459
+
460
+ {"a":1} + {"b":2} + {"c":3}
461
+ "asdfasdf"
462
+ {"a":1, "b":2, "c":3}
463
+
464
+ "asdf" + "jkl;" + . + . + .
465
+ "some string"
466
+ "asdfjkl;some stringsome stringsome string"
467
+
468
+ "\u0000\u0020\u0000" + .
469
+ "\u0000\u0020\u0000"
470
+ "\u0000 \u0000\u0000 \u0000"
471
+
472
+ 42 - .
473
+ 11
474
+ 31
475
+
476
+ [1,2,3,4,1] - [.,3]
477
+ 1
478
+ [2,4]
479
+
480
+ [10 * 20, 20 / .]
481
+ 4
482
+ [200, 5]
483
+
484
+ 1 + 2 * 2 + 10 / 2
485
+ null
486
+ 10
487
+
488
+ [16 / 4 / 2, 16 / 4 * 2, 16 - 4 - 2, 16 - 4 + 2]
489
+ null
490
+ [2, 8, 10, 14]
491
+
492
+ 25 % 7
493
+ null
494
+ 4
495
+
496
+ 49732 % 472
497
+ null
498
+ 172
499
+
500
+ 1 + tonumber + ("10" | tonumber)
501
+ 4
502
+ 15
503
+
504
+ [{"a":42},.object,10,.num,false,true,null,"b",[1,4]] | .[] as $x | [$x == .[]]
505
+ {"object": {"a":42}, "num":10.0}
506
+ [true, true, false, false, false, false, false, false, false]
507
+ [true, true, false, false, false, false, false, false, false]
508
+ [false, false, true, true, false, false, false, false, false]
509
+ [false, false, true, true, false, false, false, false, false]
510
+ [false, false, false, false, true, false, false, false, false]
511
+ [false, false, false, false, false, true, false, false, false]
512
+ [false, false, false, false, false, false, true, false, false]
513
+ [false, false, false, false, false, false, false, true, false]
514
+ [false, false, false, false, false, false, false, false, true ]
515
+
516
+ [.[] | length]
517
+ [[], {}, [1,2], {"a":42}, "asdf", "\u03bc"]
518
+ [0, 0, 2, 1, 4, 1]
519
+
520
+ map(keys)
521
+ [{}, {"abcd":1,"abc":2,"abcde":3}, {"x":1, "z": 3, "y":2}]
522
+ [[], ["abc","abcd","abcde"], ["x","y","z"]]
523
+
524
+ [1,2,empty,3,empty,4]
525
+ null
526
+ [1,2,3,4]
527
+
528
+ map(add)
529
+ [[], [1,2,3], ["a","b","c"], [[3],[4,5],[6]], [{"a":1}, {"b":2}, {"a":3}]]
530
+ [null, 6, "abc", [3,4,5,6], {"a":3, "b": 2}]
531
+
532
+ map_values(.+1)
533
+ [0,1,2]
534
+ [1,2,3]
535
+
536
+ #
537
+ # User-defined functions
538
+ # Oh god.
539
+ #
540
+
541
+ def f: . + 1; def g: def g: . + 100; f | g | f; (f | g), g
542
+ 3.0
543
+ 106.0
544
+ 105.0
545
+
546
+ def f: (1000,2000); f
547
+ 123412345
548
+ 1000
549
+ 2000
550
+
551
+ def f(a;b;c;d;e;f): [a+1,b,c,d,e,f]; f(.[0];.[1];.[0];.[0];.[0];.[0])
552
+ [1,2]
553
+ [2,2,1,1,1,1]
554
+
555
+ # Test precedence of 'def' vs '|'
556
+ def a: 0; . | a
557
+ null
558
+ 0
559
+
560
+ # Many arguments
561
+ def f(a;b;c;d;e;f;g;h;i;j): [j,i,h,g,f,e,d,c,b,a]; f(.[0];.[1];.[2];.[3];.[4];.[5];.[6];.[7];.[8];.[9])
562
+ [0,1,2,3,4,5,6,7,8,9]
563
+ [9,8,7,6,5,4,3,2,1,0]
564
+
565
+ ([1,2] + [4,5])
566
+ [1,2,3]
567
+ [1,2,4,5]
568
+
569
+ true
570
+ [1]
571
+ true
572
+
573
+ null,1,null
574
+ "hello"
575
+ null
576
+ 1
577
+ null
578
+
579
+ [1,2,3]
580
+ [5,6]
581
+ [1,2,3]
582
+
583
+ [.[]|floor]
584
+ [-1.1,1.1,1.9]
585
+ [-2, 1, 1]
586
+
587
+ [.[]|sqrt]
588
+ [4,9]
589
+ [2,3]
590
+
591
+ (add / length) as $m | map((. - $m) as $d | $d * $d) | add / length | sqrt
592
+ [2,4,4,4,5,5,7,9]
593
+ 2
594
+
595
+ # Should write a test that calls the -lm function from C (or bc(1)) to
596
+ # check that they match the corresponding jq functions. However,
597
+ # there's so little template code standing between that it suffices to
598
+ # test a handful of these. The results were checked by eye against
599
+ # bc(1).
600
+ atan * 4 * 1000000|floor / 1000000
601
+ 1
602
+ 3.141592
603
+
604
+ [(3.141592 / 2) * (range(0;20) / 20)|cos * 1000000|floor / 1000000]
605
+ null
606
+ [1,0.996917,0.987688,0.972369,0.951056,0.923879,0.891006,0.85264,0.809017,0.760406,0.707106,0.649448,0.587785,0.522498,0.45399,0.382683,0.309017,0.233445,0.156434,0.078459]
607
+
608
+ [(3.141592 / 2) * (range(0;20) / 20)|sin * 1000000|floor / 1000000]
609
+ null
610
+ [0,0.078459,0.156434,0.233445,0.309016,0.382683,0.45399,0.522498,0.587785,0.649447,0.707106,0.760405,0.809016,0.85264,0.891006,0.923879,0.951056,0.972369,0.987688,0.996917]
611
+
612
+
613
+ def f(x): x | x; f([.], . + [42])
614
+ [1,2,3]
615
+ [[[1,2,3]]]
616
+ [[1,2,3],42]
617
+ [[1,2,3,42]]
618
+ [1,2,3,42,42]
619
+
620
+ # test multiple function arities and redefinition
621
+ def f: .+1; def g: f; def f: .+100; def f(a):a+.+11; [(g|f(20)), f]
622
+ 1
623
+ [33,101]
624
+
625
+ # test closures and lexical scoping
626
+ def id(x):x; 2000 as $x | def f(x):1 as $x | id([$x, x, x]); def g(x): 100 as $x | f($x,$x+x); g($x)
627
+ "more testing"
628
+ [1,100,2100.0,100,2100.0]
629
+
630
+ # test def f($a) syntax
631
+ def x(a;b): a as $a | b as $b | $a + $b; def y($a;$b): $a + $b; def check(a;b): [x(a;b)] == [y(a;b)]; check(.[];.[]*2)
632
+ [1,2,3]
633
+ true
634
+
635
+ # test backtracking through function calls and returns
636
+ # this test is *evil*
637
+ [[20,10][1,0] as $x | def f: (100,200) as $y | def g: [$x + $y, .]; . + $x | g; f[0] | [f][0][1] | f]
638
+ 999999999
639
+ [[110.0, 130.0], [210.0, 130.0], [110.0, 230.0], [210.0, 230.0], [120.0, 160.0], [220.0, 160.0], [120.0, 260.0], [220.0, 260.0]]
640
+
641
+ # test recursion
642
+ def fac: if . == 1 then 1 else . * (. - 1 | fac) end; [.[] | fac]
643
+ [1,2,3,4]
644
+ [1,2,6,24]
645
+
646
+ # test stack overflow and reallocation
647
+ # this test is disabled for now, it takes a realllllly long time.
648
+ # def f: if length > 1000 then . else .+[1]|f end; f | length
649
+ # []
650
+ # 1001
651
+
652
+ reduce .[] as $x (0; . + $x)
653
+ [1,2,4]
654
+ 7
655
+
656
+ reduce .[] as [$i, {j:$j}] (0; . + $i - $j)
657
+ [[2,{"j":1}], [5,{"j":3}], [6,{"j":4}]]
658
+ 5
659
+
660
+ reduce [[1,2,10], [3,4,10]][] as [$i,$j] (0; . + $i * $j)
661
+ null
662
+ 14
663
+
664
+ . as $dot|any($dot[];not)
665
+ [1,2,3,4,true,false,1,2,3,4,5]
666
+ true
667
+
668
+ . as $dot|any($dot[];not)
669
+ [1,2,3,4,true]
670
+ false
671
+
672
+ . as $dot|all($dot[];.)
673
+ [1,2,3,4,true,false,1,2,3,4,5]
674
+ false
675
+
676
+ . as $dot|all($dot[];.)
677
+ [1,2,3,4,true]
678
+ true
679
+
680
+ #
681
+ # Paths
682
+ #
683
+
684
+ path(.foo[0,1])
685
+ null
686
+ ["foo", 0]
687
+ ["foo", 1]
688
+
689
+ path(.[] | select(.>3))
690
+ [1,5,3]
691
+ [1]
692
+
693
+ path(.)
694
+ 42
695
+ []
696
+
697
+ try path(.a | map(select(.b == 0))) catch .
698
+ {"a":[{"b":0}]}
699
+ "Invalid path expression with result [{\"b\":0}]"
700
+
701
+ try path(.a | map(select(.b == 0)) | .[0]) catch .
702
+ {"a":[{"b":0}]}
703
+ "Invalid path expression near attempt to access element 0 of [{\"b\":0}]"
704
+
705
+ try path(.a | map(select(.b == 0)) | .c) catch .
706
+ {"a":[{"b":0}]}
707
+ "Invalid path expression near attempt to access element \"c\" of [{\"b\":0}]"
708
+
709
+ try path(.a | map(select(.b == 0)) | .[]) catch .
710
+ {"a":[{"b":0}]}
711
+ "Invalid path expression near attempt to iterate through [{\"b\":0}]"
712
+
713
+ path(.a[path(.b)[0]])
714
+ {"a":{"b":0}}
715
+ ["a","b"]
716
+
717
+ [paths]
718
+ [1,[[],{"a":2}]]
719
+ [[0],[1],[1,0],[1,1],[1,1,"a"]]
720
+
721
+ [leaf_paths]
722
+ [1,[[],{"a":2}]]
723
+ [[0],[1,1,"a"]]
724
+
725
+ ["foo",1] as $p | getpath($p), setpath($p; 20), delpaths([$p])
726
+ {"bar": 42, "foo": ["a", "b", "c", "d"]}
727
+ "b"
728
+ {"bar": 42, "foo": ["a", 20, "c", "d"]}
729
+ {"bar": 42, "foo": ["a", "c", "d"]}
730
+
731
+ map(getpath([2])), map(setpath([2]; 42)), map(delpaths([[2]]))
732
+ [[0], [0,1], [0,1,2]]
733
+ [null, null, 2]
734
+ [[0,null,42], [0,1,42], [0,1,42]]
735
+ [[0], [0,1], [0,1]]
736
+
737
+ map(delpaths([[0,"foo"]]))
738
+ [[{"foo":2, "x":1}], [{"bar":2}]]
739
+ [[{"x":1}], [{"bar":2}]]
740
+
741
+ ["foo",1] as $p | getpath($p), setpath($p; 20), delpaths([$p])
742
+ {"bar":false}
743
+ null
744
+ {"bar":false, "foo": [null, 20]}
745
+ {"bar":false}
746
+
747
+ delpaths([[-200]])
748
+ [1,2,3]
749
+ [1,2,3]
750
+
751
+ del(.), del(empty), del((.foo,.bar,.baz) | .[2,3,0]), del(.foo[0], .bar[0], .foo, .baz.bar[0].x)
752
+ {"foo": [0,1,2,3,4], "bar": [0,1]}
753
+ null
754
+ {"foo": [0,1,2,3,4], "bar": [0,1]}
755
+ {"foo": [1,4], "bar": [1]}
756
+ {"bar": [1]}
757
+
758
+ #
759
+ # Assignment
760
+ #
761
+ .message = "goodbye"
762
+ {"message": "hello"}
763
+ {"message": "goodbye"}
764
+
765
+ .foo = .bar
766
+ {"bar":42}
767
+ {"foo":42, "bar":42}
768
+
769
+ .foo |= .+1
770
+ {"foo": 42}
771
+ {"foo": 43}
772
+
773
+ .[] += 2, .[] *= 2, .[] -= 2, .[] /= 2, .[] %=2
774
+ [1,3,5]
775
+ [3,5,7]
776
+ [2,6,10]
777
+ [-1,1,3]
778
+ [0.5, 1.5, 2.5]
779
+ [1,1,1]
780
+
781
+ [.[] % 7]
782
+ [-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7]
783
+ [0,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,0]
784
+
785
+ .foo += .foo
786
+ {"foo":2}
787
+ {"foo":4}
788
+
789
+ .[0].a |= {"old":., "new":(.+1)}
790
+ [{"a":1,"b":2}]
791
+ [{"a":{"old":1, "new":2},"b":2}]
792
+
793
+ def inc(x): x |= .+1; inc(.[].a)
794
+ [{"a":1,"b":2},{"a":2,"b":4},{"a":7,"b":8}]
795
+ [{"a":2,"b":2},{"a":3,"b":4},{"a":8,"b":8}]
796
+
797
+ .[2][3] = 1
798
+ [4]
799
+ [4, null, [null, null, null, 1]]
800
+
801
+ .foo[2].bar = 1
802
+ {"foo":[11], "bar":42}
803
+ {"foo":[11,null,{"bar":1}], "bar":42}
804
+
805
+ try ((map(select(.a == 1))[].b) = 10) catch .
806
+ [{"a":0},{"a":1}]
807
+ "Invalid path expression near attempt to iterate through [{\"a\":1}]"
808
+
809
+ try ((map(select(.a == 1))[].a) |= .+1) catch .
810
+ [{"a":0},{"a":1}]
811
+ "Invalid path expression near attempt to iterate through [{\"a\":1}]"
812
+
813
+ def x: .[1,2]; x=10
814
+ [0,1,2]
815
+ [0,10,10]
816
+
817
+ try (def x: reverse; x=10) catch .
818
+ [0,1,2]
819
+ "Invalid path expression with result [2,1,0]"
820
+
821
+ #
822
+ # Conditionals
823
+ #
824
+
825
+ [.[] | if .foo then "yep" else "nope" end]
826
+ [{"foo":0},{"foo":1},{"foo":[]},{"foo":true},{"foo":false},{"foo":null},{"foo":"foo"},{}]
827
+ ["yep","yep","yep","yep","nope","nope","yep","nope"]
828
+
829
+ [.[] | if .baz then "strange" elif .foo then "yep" else "nope" end]
830
+ [{"foo":0},{"foo":1},{"foo":[]},{"foo":true},{"foo":false},{"foo":null},{"foo":"foo"},{}]
831
+ ["yep","yep","yep","yep","nope","nope","yep","nope"]
832
+
833
+
834
+ # FIXME: define/test behaviour of 'if (.foo,.bar) then A else B end'
835
+
836
+ [.[] | [.foo[] // .bar]]
837
+ [{"foo":[1,2], "bar": 42}, {"foo":[1], "bar": null}, {"foo":[null,false,3], "bar": 18}, {"foo":[], "bar":42}, {"foo": [null,false,null], "bar": 41}]
838
+ [[1,2], [1], [3], [42], [41]]
839
+
840
+ .[] //= .[0]
841
+ ["hello",true,false,[false],null]
842
+ ["hello",true,"hello",[false],"hello"]
843
+
844
+ .[] | [.[0] and .[1], .[0] or .[1]]
845
+ [[true,[]], [false,1], [42,null], [null,false]]
846
+ [true,true]
847
+ [false,true]
848
+ [false,true]
849
+ [false,false]
850
+
851
+ [.[] | not]
852
+ [1,0,false,null,true,"hello"]
853
+ [false,false,true,true,false,false]
854
+
855
+ # Check numeric comparison binops
856
+ [10 > 0, 10 > 10, 10 > 20, 10 < 0, 10 < 10, 10 < 20]
857
+ {}
858
+ [true,false,false,false,false,true]
859
+
860
+ [10 >= 0, 10 >= 10, 10 >= 20, 10 <= 0, 10 <= 10, 10 <= 20]
861
+ {}
862
+ [true,true,false,false,true,true]
863
+
864
+ # And some in/equality tests
865
+ [ 10 == 10, 10 != 10, 10 != 11, 10 == 11]
866
+ {}
867
+ [true,false,true,false]
868
+
869
+ ["hello" == "hello", "hello" != "hello", "hello" == "world", "hello" != "world" ]
870
+ {}
871
+ [true,false,false,true]
872
+
873
+ [[1,2,3] == [1,2,3], [1,2,3] != [1,2,3], [1,2,3] == [4,5,6], [1,2,3] != [4,5,6]]
874
+ {}
875
+ [true,false,false,true]
876
+
877
+ [{"foo":42} == {"foo":42},{"foo":42} != {"foo":42}, {"foo":42} != {"bar":42}, {"foo":42} == {"bar":42}]
878
+ {}
879
+ [true,false,true,false]
880
+
881
+ # ugly complicated thing
882
+ [{"foo":[1,2,{"bar":18},"world"]} == {"foo":[1,2,{"bar":18},"world"]},{"foo":[1,2,{"bar":18},"world"]} == {"foo":[1,2,{"bar":19},"world"]}]
883
+ {}
884
+ [true,false]
885
+
886
+ # containment operator
887
+ [("foo" | contains("foo")), ("foobar" | contains("foo")), ("foo" | contains("foobar"))]
888
+ {}
889
+ [true, true, false]
890
+
891
+ # Try/catch and general `?` operator
892
+ [.[]|try if . == 0 then error("foo") elif . == 1 then .a elif . == 2 then empty else . end catch .]
893
+ [0,1,2,3]
894
+ ["foo","Cannot index number with string \"a\"",3]
895
+
896
+ [.[]|(.a, .a)?]
897
+ [null,true,{"a":1}]
898
+ [null,null,1,1]
899
+
900
+ [[.[]|[.a,.a]]?]
901
+ [null,true,{"a":1}]
902
+ []
903
+
904
+ try error("\($__loc__)") catch .
905
+ null
906
+ "{\"file\":\"<top-level>\",\"line\":1}"
907
+
908
+ # string operations
909
+ [.[]|startswith("foo")]
910
+ ["fo", "foo", "barfoo", "foobar", "barfoob"]
911
+ [false, true, false, true, false]
912
+
913
+ [.[]|endswith("foo")]
914
+ ["fo", "foo", "barfoo", "foobar", "barfoob"]
915
+ [false, true, true, false, false]
916
+
917
+ [.[] | split(", ")]
918
+ ["a,b, c, d, e,f",", a,b, c, d, e,f, "]
919
+ [["a,b","c","d","e,f"],["","a,b","c","d","e,f",""]]
920
+
921
+ split("")
922
+ "abc"
923
+ ["a","b","c"]
924
+
925
+ [.[]|ltrimstr("foo")]
926
+ ["fo", "foo", "barfoo", "foobar", "afoo"]
927
+ ["fo","","barfoo","bar","afoo"]
928
+
929
+ [.[]|rtrimstr("foo")]
930
+ ["fo", "foo", "barfoo", "foobar", "foob"]
931
+ ["fo","","bar","foobar","foob"]
932
+
933
+ [(index(","), rindex(",")), indices(",")]
934
+ "a,bc,def,ghij,klmno"
935
+ [1,13,[1,4,8,13]]
936
+
937
+ indices(1)
938
+ [0,1,1,2,3,4,1,5]
939
+ [1,2,6]
940
+
941
+ indices([1,2])
942
+ [0,1,2,3,1,4,2,5,1,2,6,7]
943
+ [1,8]
944
+
945
+ indices([1,2])
946
+ [1]
947
+ []
948
+
949
+ indices(", ")
950
+ "a,b, cd,e, fgh, ijkl"
951
+ [3,9,14]
952
+
953
+ [.[]|split(",")]
954
+ ["a, bc, def, ghij, jklmn, a,b, c,d, e,f", "a,b,c,d, e,f,g,h"]
955
+ [["a"," bc"," def"," ghij"," jklmn"," a","b"," c","d"," e","f"],["a","b","c","d"," e","f","g","h"]]
956
+
957
+ [.[]|split(", ")]
958
+ ["a, bc, def, ghij, jklmn, a,b, c,d, e,f", "a,b,c,d, e,f,g,h"]
959
+ [["a","bc","def","ghij","jklmn","a,b","c,d","e,f"],["a,b,c,d","e,f,g,h"]]
960
+
961
+ [.[] * 3]
962
+ ["a", "ab", "abc"]
963
+ ["aaa", "ababab", "abcabcabc"]
964
+
965
+ [.[] / ","]
966
+ ["a, bc, def, ghij, jklmn, a,b, c,d, e,f", "a,b,c,d, e,f,g,h"]
967
+ [["a"," bc"," def"," ghij"," jklmn"," a","b"," c","d"," e","f"],["a","b","c","d"," e","f","g","h"]]
968
+
969
+ [.[] / ", "]
970
+ ["a, bc, def, ghij, jklmn, a,b, c,d, e,f", "a,b,c,d, e,f,g,h"]
971
+ [["a","bc","def","ghij","jklmn","a,b","c,d","e,f"],["a,b,c,d","e,f,g,h"]]
972
+
973
+ map(.[1] as $needle | .[0] | contains($needle))
974
+ [[[],[]], [[1,2,3], [1,2]], [[1,2,3], [3,1]], [[1,2,3], [4]], [[1,2,3], [1,4]]]
975
+ [true, true, true, false, false]
976
+
977
+ map(.[1] as $needle | .[0] | contains($needle))
978
+ [[["foobar", "foobaz"], ["baz", "bar"]], [["foobar", "foobaz"], ["foo"]], [["foobar", "foobaz"], ["blap"]]]
979
+ [true, true, false]
980
+
981
+ [({foo: 12, bar:13} | contains({foo: 12})), ({foo: 12} | contains({})), ({foo: 12, bar:13} | contains({baz:14}))]
982
+ {}
983
+ [true, true, false]
984
+
985
+ {foo: {baz: 12, blap: {bar: 13}}, bar: 14} | contains({bar: 14, foo: {blap: {}}})
986
+ {}
987
+ true
988
+
989
+ {foo: {baz: 12, blap: {bar: 13}}, bar: 14} | contains({bar: 14, foo: {blap: {bar: 14}}})
990
+ {}
991
+ false
992
+
993
+ sort
994
+ [42,[2,5,3,11],10,{"a":42,"b":2},{"a":42},true,2,[2,6],"hello",null,[2,5,6],{"a":[],"b":1},"abc","ab",[3,10],{},false,"abcd",null]
995
+ [null,null,false,true,2,10,42,"ab","abc","abcd","hello",[2,5,3,11],[2,5,6],[2,6],[3,10],{},{"a":42},{"a":42,"b":2},{"a":[],"b":1}]
996
+
997
+ (sort_by(.b) | sort_by(.a)), sort_by(.a, .b), sort_by(.b, .c), group_by(.b), group_by(.a + .b - .c == 2)
998
+ [{"a": 1, "b": 4, "c": 14}, {"a": 4, "b": 1, "c": 3}, {"a": 1, "b": 4, "c": 3}, {"a": 0, "b": 2, "c": 43}]
999
+ [{"a": 0, "b": 2, "c": 43}, {"a": 1, "b": 4, "c": 14}, {"a": 1, "b": 4, "c": 3}, {"a": 4, "b": 1, "c": 3}]
1000
+ [{"a": 0, "b": 2, "c": 43}, {"a": 1, "b": 4, "c": 14}, {"a": 1, "b": 4, "c": 3}, {"a": 4, "b": 1, "c": 3}]
1001
+ [{"a": 4, "b": 1, "c": 3}, {"a": 0, "b": 2, "c": 43}, {"a": 1, "b": 4, "c": 3}, {"a": 1, "b": 4, "c": 14}]
1002
+ [[{"a": 4, "b": 1, "c": 3}], [{"a": 0, "b": 2, "c": 43}], [{"a": 1, "b": 4, "c": 14}, {"a": 1, "b": 4, "c": 3}]]
1003
+ [[{"a": 1, "b": 4, "c": 14}, {"a": 0, "b": 2, "c": 43}], [{"a": 4, "b": 1, "c": 3}, {"a": 1, "b": 4, "c": 3}]]
1004
+
1005
+ unique
1006
+ [1,2,5,3,5,3,1,3]
1007
+ [1,2,3,5]
1008
+
1009
+ unique
1010
+ []
1011
+ []
1012
+
1013
+ [min, max, min_by(.[1]), max_by(.[1]), min_by(.[2]), max_by(.[2])]
1014
+ [[4,2,"a"],[3,1,"a"],[2,4,"a"],[1,3,"a"]]
1015
+ [[1,3,"a"],[4,2,"a"],[3,1,"a"],[2,4,"a"],[4,2,"a"],[1,3,"a"]]
1016
+
1017
+ [min,max,min_by(.),max_by(.)]
1018
+ []
1019
+ [null,null,null,null]
1020
+
1021
+ .foo[.baz]
1022
+ {"foo":{"bar":4},"baz":"bar"}
1023
+ 4
1024
+
1025
+ .[] | .error = "no, it's OK"
1026
+ [{"error":true}]
1027
+ {"error": "no, it's OK"}
1028
+
1029
+ [{a:1}] | .[] | .a=999
1030
+ null
1031
+ {"a": 999}
1032
+
1033
+ to_entries
1034
+ {"a": 1, "b": 2}
1035
+ [{"key":"a", "value":1}, {"key":"b", "value":2}]
1036
+
1037
+ from_entries
1038
+ [{"key":"a", "value":1}, {"Key":"b", "value":2}]
1039
+ {"a": 1, "b": 2}
1040
+
1041
+ from_entries
1042
+ [{"key":"a", "Value":1}, {"Name":"b", "value":2}]
1043
+ {"a": 1, "b": 2}
1044
+
1045
+ with_entries(.key |= "KEY_" + .)
1046
+ {"a": 1, "b": 2}
1047
+ {"KEY_a": 1, "KEY_b": 2}
1048
+
1049
+ map(has("foo"))
1050
+ [{"foo": 42}, {}]
1051
+ [true, false]
1052
+
1053
+ map(has(2))
1054
+ [[0,1], ["a","b","c"]]
1055
+ [false, true]
1056
+
1057
+ keys
1058
+ [42,3,35]
1059
+ [0,1,2]
1060
+
1061
+ [][.]
1062
+ 1000000000000000000
1063
+ null
1064
+
1065
+ map([1,2][0:.])
1066
+ [-1, 1, 2, 3, 1000000000000000000]
1067
+ [[1], [1], [1,2], [1,2], [1,2]]
1068
+
1069
+ # Test recursive object merge
1070
+
1071
+ {"k": {"a": 1, "b": 2}} * .
1072
+ {"k": {"a": 0,"c": 3}}
1073
+ {"k": {"a": 0, "b": 2, "c": 3}}
1074
+
1075
+ {"k": {"a": 1, "b": 2}, "hello": {"x": 1}} * .
1076
+ {"k": {"a": 0,"c": 3}, "hello": 1}
1077
+ {"k": {"a": 0, "b": 2, "c": 3}, "hello": 1}
1078
+
1079
+ {"k": {"a": 1, "b": 2}, "hello": 1} * .
1080
+ {"k": {"a": 0,"c": 3}, "hello": {"x": 1}}
1081
+ {"k": {"a": 0, "b": 2, "c": 3}, "hello": {"x": 1}}
1082
+
1083
+ {"a": {"b": 1}, "c": {"d": 2}, "e": 5} * .
1084
+ {"a": {"b": 2}, "c": {"d": 3, "f": 9}}
1085
+ {"a": {"b": 2}, "c": {"d": 3, "f": 9}, "e": 5}
1086
+
1087
+ [.[]|arrays]
1088
+ [1,2,"foo",[],[3,[]],{},true,false,null]
1089
+ [[],[3,[]]]
1090
+
1091
+ [.[]|objects]
1092
+ [1,2,"foo",[],[3,[]],{},true,false,null]
1093
+ [{}]
1094
+
1095
+ [.[]|iterables]
1096
+ [1,2,"foo",[],[3,[]],{},true,false,null]
1097
+ [[],[3,[]],{}]
1098
+
1099
+ [.[]|scalars]
1100
+ [1,2,"foo",[],[3,[]],{},true,false,null]
1101
+ [1,2,"foo",true,false,null]
1102
+
1103
+ [.[]|values]
1104
+ [1,2,"foo",[],[3,[]],{},true,false,null]
1105
+ [1,2,"foo",[],[3,[]],{},true,false]
1106
+
1107
+ [.[]|booleans]
1108
+ [1,2,"foo",[],[3,[]],{},true,false,null]
1109
+ [true,false]
1110
+
1111
+ [.[]|nulls]
1112
+ [1,2,"foo",[],[3,[]],{},true,false,null]
1113
+ [null]
1114
+
1115
+ flatten
1116
+ [0, [1], [[2]], [[[3]]]]
1117
+ [0, 1, 2, 3]
1118
+
1119
+ flatten(0)
1120
+ [0, [1], [[2]], [[[3]]]]
1121
+ [0, [1], [[2]], [[[3]]]]
1122
+
1123
+ flatten(2)
1124
+ [0, [1], [[2]], [[[3]]]]
1125
+ [0, 1, 2, [3]]
1126
+
1127
+ flatten(2)
1128
+ [0, [1, [2]], [1, [[3], 2]]]
1129
+ [0, 1, 2, 1, [3], 2]
1130
+
1131
+ try flatten(-1) catch .
1132
+ [0, [1], [[2]], [[[3]]]]
1133
+ "flatten depth must not be negative"
1134
+
1135
+ transpose
1136
+ [[1], [2,3]]
1137
+ [[1,2],[null,3]]
1138
+
1139
+ ascii_upcase
1140
+ "useful but not for é"
1141
+ "USEFUL BUT NOT FOR é"
1142
+
1143
+ bsearch(4)
1144
+ [1,2,3]
1145
+ -4
1146
+
1147
+ [strptime("%Y-%m-%dT%H:%M:%SZ")|(.,mktime)]
1148
+ "2015-03-05T23:51:47Z"
1149
+ [[2015,2,5,23,51,47,4,63],1425599507]
1150
+
1151
+ strftime("%Y-%m-%dT%H:%M:%SZ")
1152
+ [2015,2,5,23,51,47,4,63]
1153
+ "2015-03-05T23:51:47Z"
1154
+
1155
+ strftime("%A, %B %e, %Y")
1156
+ 1435677542.822351
1157
+ "Tuesday, June 30, 2015"
1158
+
1159
+ gmtime
1160
+ 1425599507
1161
+ [2015,2,5,23,51,47,4,63]
1162
+
1163
+ # module system
1164
+ import "a" as foo; import "b" as bar; def fooa: foo::a; [fooa, bar::a, bar::b, foo::a]
1165
+ null
1166
+ ["a","b","c","a"]
1167
+
1168
+ import "c" as foo; [foo::a, foo::c]
1169
+ null
1170
+ [0,"acmehbah"]
1171
+
1172
+ include "c"; [a, c]
1173
+ null
1174
+ [0,"acmehbah"]
1175
+
1176
+ modulemeta
1177
+ "c"
1178
+ {"whatever":null,"deps":[{"as":"foo","is_data":false,"relpath":"a"},{"search":"./","as":"d","is_data":false,"relpath":"d"},{"search":"./","as":"d2","is_data":false,"relpath":"d"},{"search":"./../lib/jq","as":"e","is_data":false,"relpath":"e"},{"search":"./../lib/jq","as":"f","is_data":false,"relpath":"f"},{"as":"d","is_data":true,"relpath":"data"}]}
1179
+
1180
+ %%FAIL IGNORE MSG
1181
+ import "syntaxerror" as e; .
1182
+ jq: error: syntax error, unexpected ';', expecting $end (Unix shell quoting issues?) at /home/nico/ws/jq/tests/modules/syntaxerror/syntaxerror.jq, line 1:
1183
+
1184
+ %%FAIL
1185
+ %::wat
1186
+ jq: error: syntax error, unexpected '%', expecting $end (Unix shell quoting issues?) at <top-level>, line 1:
1187
+
1188
+ import "test_bind_order" as check; check::check
1189
+ null
1190
+ true
1191
+
1192
+ try -. catch .
1193
+ "very-long-string"
1194
+ "string (\"very-long-...) cannot be negated"
1195
+
1196
+ try join(",") catch .
1197
+ ["1",2]
1198
+ "string (\",\") and number (2) cannot be added"
1199
+
1200
+ try join(",") catch .
1201
+ ["1","2",{"a":{"b":{"c":33}}}]
1202
+ "string (\",\") and object ({\"a\":{\"b\":{...) cannot be added"
1203
+
1204
+ {if:0,and:1,or:2,then:3,else:4,elif:5,end:6,as:7,def:8,reduce:9,foreach:10,try:11,catch:12,label:13,import:14,include:15,module:16}
1205
+ null
1206
+ {"if":0,"and":1,"or":2,"then":3,"else":4,"elif":5,"end":6,"as":7,"def":8,"reduce":9,"foreach":10,"try":11,"catch":12,"label":13,"import":14,"include":15,"module":16}
1207
+
1208
+ try (1/.) catch .
1209
+ 0
1210
+ "number (1) and number (0) cannot be divided because the divisor is zero"
1211
+
1212
+ try (1%.) catch .
1213
+ 0
1214
+ "number (1) and number (0) cannot be divided (remainder) because the divisor is zero"
1215
+
1216
+ %%FAIL
1217
+ 1/0
1218
+ jq: error: Division by zero? at <top-level>, line 1:
1219
+
1220
+ # Basic numbers tests: integers, powers of two
1221
+ [range(-52;52;1)] as $powers | [$powers[]|pow(2;.)|log2] == $powers
1222
+ null
1223
+ true
1224
+
1225
+ [range(-99/2;99/2;1)] as $orig | [$orig[]|pow(2;.)|log2] as $back | ($orig|keys)[]|. as $k | (($orig|.[$k])-($back|.[$k]))|if . < 0 then . * -1 else . end|select(.>.00005)
1226
+ null
1227
+
1228
+ %%FAIL
1229
+ }
1230
+ jq: error: syntax error, unexpected INVALID_CHARACTER, expecting $end (Unix shell quoting issues?) at <top-level>, line 1:
1231
+
1232
+ (.[{}] = 0)?
1233
+ null
1234
+
1235
+