Skip to content
Myr

jq.test

This file

Path

tests/jq.test

2,846 lines · 57.2 KiB

Last changed by

landed by oscabriel6b53f80

History of this file

Take it

The walk stopped after 200 commits: lines older than fa6a2ff point at it.

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 1–38why, one step back
1# Tests are groups of three lines: program, input, expected output
2# Blank lines and lines starting with # are ignored34#5# Simple value tests to check parser. Input is irrelevant6#78true9null10true1112false13null14false1516null174218null1920121null221232425-126null27-12829# FIXME: much more number testing needed3031{}32null33{}3435[]36null37[]38

Fix unary operator precedence, allow some expressions as object values (#3053)itchynybefore adoption92daac9

lines 39–43why, one step back
39{x:-1},{x:-.},{x:-.|abs}
40141{"x":-1}42{"x":-1}43{"x":1}

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 44–54why, one step back
44
45# We test escapes by matching them against Unicode codepoints46# FIXME: more tests needed for weird unicode stuff (e.g. utf16 pairs)47"Aa\r\n\t\b\f\u03bc"48null49"Aa\u000d\u000a\u0009\u0008\u000c\u03bc"5051.52"Aa\r\n\t\b\f\u03bc"53"Aa\u000d\u000a\u0009\u0008\u000c\u03bc"54

Improve error messages to show problematic position in the filter (#3292)itchynybefore adoptionb733dfa

lines 55–60why, one step back
55%%FAIL
56"u\vw"57jq: error: Invalid escape at line 1, column 4 (while parsing '"\v"') at <top-level>, line 1, column 3:58 "u\vw"59 ^^60

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 61–102why, one step back
61"inter\("pol" + "ation")"
62null63"interpolation"6465@text,@json,([1,.]|@csv,@tsv),@html,(@uri|.,@urid),@sh,(@base64|.,@base64d)66"!()<>&'\"\t"67"!()<>&'\"\t"68"\"!()<>&'\\\"\\t\""69"1,\"!()<>&'\"\"\t\""70"1\t!()<>&'\"\\t"71"!()&lt;&gt;&amp;&apos;&quot;\t"72"%21%28%29%3C%3E%26%27%22%09"73"!()<>&'\"\t"74"'!()<>&'\\''\"\t'"75"ISgpPD4mJyIJ"76"!()<>&'\"\t"7778# regression test for #43679@base6480"foóbar\n"81"Zm/Ds2Jhcgo="8283@base64d84"Zm/Ds2Jhcgo="85"foóbar\n"8687@uri88"\u03bc"89"%CE%BC"9091@urid92"%CE%BC"93"\u03bc"9495@html "<b>\(.)</b>"96"<script>hax</script>"97"<b>&lt;script&gt;hax&lt;/script&gt;</b>"9899[.[]|tojson|fromjson]100["foo", 1, ["a", 1, "b", 2, {"foo":"bar"}]]101["foo",1,["a",1,"b",2,{"foo":"bar"}]]102

Improve performance of string output (#3643)Michiel van Slobbebefore adoptionb904884

lines 103–111why, one step back
103# Put escapes on both sides of runs of bytes that need no escaping
104map(tojson)105["abcdefg\"", "abcdefgh\\", "abcdefghi\u0001j", "abcdefghijklmno\u007f", "abcdefgh\té", "abcdefghijklmnop\n"]106["\"abcdefg\\\"\"","\"abcdefgh\\\\\"","\"abcdefghi\\u0001j\"","\"abcdefghijklmno\\u007f\"","\"abcdefgh\\té\"","\"abcdefghijklmnop\\n\""]107108[range(18) as $i | ("\"", "\\", "\u0001", "\u007f", "é", "😀") as $c | "abcdefghijklmnopq"[:$i] + $c + "abcdefghijklmnopq"[$i:] | (tojson | fromjson) == .] | all109null110true111

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 112–129why, one step back
112#
113# Dictionary construction syntax114#115116{a: 1}117null118{"a":1}119120{a,b,(.d):.a,e:.b}121{"a":1, "b":2, "c":3, "d":"c"}122{"a":1, "b":2, "c":1, "e":2}123124{"a",b,"a$\(1+1)"}125{"a":1, "b":2, "c":3, "a$2":4}126{"a":1, "b":2, "a$2":4}127128%%FAIL129{(0):1}

Improve error messages to show problematic position in the filter (#3292)itchynybefore adoptionb733dfa

lines 130–132why, one step back
130jq: error: Cannot use number (0) as object key at <top-level>, line 1, column 3:
131 {(0):1}132 ^

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 133–134why, one step back
133
134%%FAIL

Improve error messages to show problematic position in the filter (#3292)itchynybefore adoptionb733dfa

lines 135–140why, one step back
135{1+2:3}
136jq: error: May need parentheses around object key expression at <top-level>, line 1, column 2:137 {1+2:3}138 ^^^139140%%FAIL

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

line 141why, one step back
141{non_const:., (0):1}

Improve error messages to show problematic position in the filter (#3292)itchynybefore adoptionb733dfa

lines 142–144why, one step back
142jq: error: Cannot use number (0) as object key at <top-level>, line 1, column 16:
143 {non_const:., (0):1}144 ^

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 145–230why, one step back
145
146#147# Field access, piping148#149150.foo151{"foo": 42, "bar": 43}15242153154.foo | .bar155{"foo": {"bar": 42}, "bar": "badvalue"}15642157158.foo.bar159{"foo": {"bar": 42}, "bar": "badvalue"}16042161162.foo_bar163{"foo_bar": 2}1642165166.["foo"].bar167{"foo": {"bar": 42}, "bar": "badvalue"}16842169170."foo"."bar"171{"foo": {"bar": 20}}17220173174.e0, .E1, .E-1, .E+1175{"e0": 1, "E1": 2, "E": 3}1761177217821794180181[.[]|.foo?]182[1,[2],{"foo":3,"bar":4},{},{"foo":5}]183[3,null,5]184185[.[]|.foo?.bar?]186[1,[2],[],{"foo":3},{"foo":{"bar":4}},{}]187[4,null]188189[..]190[1,[[2]],{ "a":[1]}]191[[1,[[2]],{"a":[1]}],1,[[2]],[2],2,{"a":[1]},[1],1]192193[.[]|.[]?]194[1,null,[],[1,[2,[[3]]]],[{}],[{"a":[1,[2]]}]]195[1,[2,[[3]]],{},{"a":[1,[2]]}]196197[.[]|.[1:3]?]198[1,null,true,false,"abcdef",{},{"a":1,"b":2},[],[1,2,3,4,5],[1,2]]199[null,"bc",[],[2,3],[2]]200201# chaining/suffix-list, with and without dot202map(try .a[] catch ., try .a.[] catch ., .a[]?, .a.[]?)203[{"a": [1,2]}, {"a": 123}]204[1,2,1,2,1,2,1,2,"Cannot iterate over number (123)","Cannot iterate over number (123)"]205206# oss-fuzz #66070: objects[] leaks if a non-last element throws an error207try ["OK", (.[] | error)] catch ["KO", .]208{"a":["b"],"c":["d"]}209["KO",["b"]]210211#212# Negative array indices213#214215try (.foo[-1] = 0) catch .216null217"Out of bounds negative array index"218219try (.foo[-2] = 0) catch .220null221"Out of bounds negative array index"222223.[-1] = 5224[0,1,2]225[0,1,5]226227.[-2] = 5228[0,1,2]229[0,5,2]230

Fix signed integer overflow in jvp_array_write and jvp_object_rehashitchynybefore adoptionde21386

lines 231–234why, one step back
231try (.[999999999] = 0) catch .
232null233"Array index too large"234

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 235–308why, one step back
235#
236# Multiple outputs, iteration237#238239.[]240[1,2,3]2411242224332442451,1246[]247124812492501,.251[]2521253[]254255[.]256[2]257[[2]]258259[[2]]260[3]261[[2]]262263[{}]264[2]265[{}]266267[.[]]268["a"]269["a"]270271[(.,1),((.,.[]),(2,3))]272["a","b"]273[["a","b"],1,["a","b"],"a","b",2,3]274275[([5,5][]),.,.[]]276[1,2,3]277[5,5,[1,2,3],1,2,3]278279{x: (1,2)},{x:3} | .x280null281128222833284285[.[-4,-3,-2,-1,0,1,2,3]]286[1,2,3]287[null,1,2,3,1,2,3,null]288289[range(0;10)]290null291[0,1,2,3,4,5,6,7,8,9]292293[range(0,1;3,4)]294null295[0,1,2, 0,1,2,3, 1,2, 1,2,3]296297[range(0;10;3)]298null299[0,3,6,9]300301[range(0;10;-1)]302null303[]304305[range(0;-5;-1)]306null307[0,-1,-2,-3,-4]308

Implement `range/3` in C for consistent error handling (#3267)itchynybefore adoptione371bfa

lines 309–316why, one step back
309[range(0;-10;-3)]
310null311[0,-3,-6,-9]312313[range(0;10;0)]314null315[]316

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 317–319why, one step back
317[range(0,1;4,5;1,2)]
318null319[0,1,2,3,0,2, 0,1,2,3,4,0,2,4, 1,2,3,1,3, 1,2,3,4,1,3]

Implement `range/3` in C for consistent error handling (#3267)itchynybefore adoptione371bfa

lines 320–331why, one step back
320
321try range(.) catch .322null323"Range bounds and step must be numeric"324325try range(0;"") catch .326null327"Range bounds and step must be numeric"328329try range(0;1;[]) catch .330null331"Range bounds and step must be numeric"

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 332–346why, one step back
332
333[while(.<100; .*2)]3341335[1,2,4,8,16,32,64]336337[(label $here | .[] | if .>1 then break $here else . end), "hi!"]338[0,1,2]339[0,1,"hi!"]340341[(label $here | .[] | if .>1 then break $here else . end), "hi!"]342[0,2,1]343[0,"hi!"]344345%%FAIL346. as $foo | break $foo

Include column number in parser and compiler error messages (#3257)liviubobocubefore adoption4b84a6e

line 347why, one step back
347jq: error: $*label-foo is not defined at <top-level>, line 1, column 13:

Improve error messages to show problematic position in the filter (#3292)itchynybefore adoptionb733dfa

lines 348–349why, one step back
348 . as $foo | break $foo
349 ^^^^^^^^^^

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 350–370why, one step back
350
351[.[]|[.,1]|until(.[0] < 1; [.[0] - 1, .[1] * .[0]])|.[1]]352[1,2,3,4,5]353[1,2,6,24,120]354355[label $out | foreach .[] as $item ([3, null]; if .[0] < 1 then break $out else [.[0] -1, $item] end; .[1])]356[11,22,33,44,55,66,77,88,99]357[11,22,33]358359[foreach range(5) as $item (0; $item)]360null361[0,1,2,3,4]362363[foreach .[] as [$i, $j] (0; . + $i - $j)]364[[2,1], [5,3], [6,4]]365[1,3,5]366367[foreach .[] as {a:$a} (0; . + $a; -.)]368[{"a":1}, {"b":2}, {"a":3, "b":4}]369[-1, -1, -4]370

Fix unary operator precedence, allow some expressions as object values (#3053)itchynybefore adoption92daac9

lines 371–382why, one step back
371[-foreach -.[] as $x (0; . + $x)]
372[1,2,3]373[1,3,6]374375[foreach .[] / .[] as $i (0; . + $i)]376[1,2]377[1,3,3.5,4.5]378379[foreach .[] as $x (0; . + $x) as $x | $x]380[1,2,3]381[1,3,6]382

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 383–533why, one step back
383[limit(3; .[])]
384[11,22,33,44,55,66,77,88,99]385[11,22,33]386387[limit(0; error)]388"badness"389[]390391[limit(1; 1, error)]392"badness"393[1]394395try limit(-1; error) catch .396null397"limit doesn't support negative count"398399[skip(3; .[])]400[1,2,3,4,5,6,7,8,9]401[4,5,6,7,8,9]402403[skip(0,2,3,4; .[])]404[1,2,3]405[1,2,3,3]406407[skip(3; .[])]408[]409[]410411try skip(-1; error) catch .412null413"skip doesn't support negative count"414415nth(1; 0,1,error("foo"))416null4171418419[first(range(.)), last(range(.))]42010421[0,9]422423[first(range(.)), last(range(.))]4240425[]426427[nth(0,5,9,10,15; range(.)), try nth(-1; range(.)) catch .]42810429[0,5,9,"nth doesn't support negative indices"]430431# Check that first(g) does not extract more than one value from g432first(1,error("foo"))433null4341435436#437# Check that various builtins evaluate all arguments where appropriate,438# doing cartesian products where appropriate.439#440441# Check that limit does work for each value produced by n!442[limit(5,7; range(9))]443null444[0,1,2,3,4,0,1,2,3,4,5,6]445446# Same check for nth447[nth(5,7; range(9;0;-1))]448null449[4,2]450451# Same check for range/3452[range(0,1,2;4,3,2;2,3)]453null454[0,2,0,3,0,2,0,0,0,1,3,1,1,1,1,1,2,2,2,2]455456# Same check for range/1457[range(3,5)]458null459[0,1,2,0,1,2,3,4]460461# Same check for index/1, rindex/1, indices/1462[(index(",","|"), rindex(",","|")), indices(",","|")]463"a,b|c,d,e||f,g,h,|,|,i,j"464[1,3,22,19,[1,5,7,12,14,16,18,20,22],[3,9,10,17,19]]465466# Same check for join/1467join(",","/")468["a","b","c","d"]469"a,b,c,d"470"a/b/c/d"471472[.[]|join("a")]473[[],[""],["",""],["","",""]]474["","","a","aa"]475476# Same check for flatten/1477flatten(3,2,1)478[0, [1], [[2]], [[[3]]]]479[0,1,2,3]480[0,1,2,[3]]481[0,1,[2],[[3]]]482483484#485# Slices486#487488[.[3:2], .[-5:4], .[:-2], .[-2:], .[3:3][1:], .[10:]]489[0,1,2,3,4,5,6]490[[], [2,3], [0,1,2,3,4], [5,6], [], []]491492[.[3:2], .[-5:4], .[:-2], .[-2:], .[3:3][1:], .[10:]]493"abcdefghi"494["","","abcdefg","hi","",""]495496del(.[2:4],.[0],.[-2:])497[0,1,2,3,4,5,6,7]498[1,4,5]499500.[2:4] = ([], ["a","b"], ["a","b","c"])501[0,1,2,3,4,5,6,7]502[0,1,4,5,6,7]503[0,1,"a","b",4,5,6,7]504[0,1,"a","b","c",4,5,6,7]505506# Slices at large offsets (issue #1108)507#508# This is written this way because [range(<large number>)] is509# significantly slower under valgrind than .[<large number>] = value.510#511# We range down rather than up so that we have just one realloc.512reduce range(65540;65536;-1) as $i ([]; .[$i] = $i)|.[65536:]513null514[null,65537,65538,65539,65540]515516#517# Variables518#5195201 as $x | 2 as $y | [$x,$y,$x]521null522[1,2,1]523524[1,2,3][] as $x | [[4,5,6,7][$x]]525null526[5]527[6]528[7]52953042 as $x | . | . | . + 432 | $x + 15313432453243533

Fix parser to allow binary operators for binding syntax (#3326)itchynybefore adoptionaaace54

lines 534–541why, one step back
5341 + 2 as $x | -$x
535null536-3537538"x" as $x | "a"+"y" as $y | $x+","+$y539null540"x,ay"541

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 542–568why, one step back
5421 as $x | [$x,$x,$x as $x | $x]
543null544[1,1,1]545546[1, {c:3, d:4}] as [$a, {c:$b, b:$c}] | $a, $b, $c547null54815493550null551552. as {as: $kw, "str": $str, ("e"+"x"+"p"): $exp} | [$kw, $str, $exp]553{"as": 1, "str": 2, "exp": 3}554[1, 2, 3]555556.[] as [$a, $b] | [$b, $a]557[[1], [1, 2, 3]]558[null, 1]559[2, 1]560561. as $i | . as [$i] | $i562[0]5630564565. as [$i] | . as $i | $i566[0]567[0]568

Improve error messages to show problematic position in the filter (#3292)itchynybefore adoptionb733dfa

line 569why, one step back
569%%FAIL

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

line 570why, one step back
570. as [] | null

Improve error messages to show problematic position in the filter (#3292)itchynybefore adoptionb733dfa

lines 571–573why, one step back
571jq: error: syntax error, unexpected ']', expecting BINDING or '[' or '{' at <top-level>, line 1, column 7:
572 . as [] | null573 ^

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

line 574why, one step back
574

Improve error messages to show problematic position in the filter (#3292)itchynybefore adoptionb733dfa

line 575why, one step back
575%%FAIL

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

line 576why, one step back
576. as {} | null

Improve error messages to show problematic position in the filter (#3292)itchynybefore adoptionb733dfa

lines 577–579why, one step back
577jq: error: syntax error, unexpected '}' at <top-level>, line 1, column 7:
578 . as {} | null579 ^

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

line 580why, one step back
580

Improve error messages to show problematic position in the filter (#3292)itchynybefore adoptionb733dfa

lines 581–592why, one step back
581%%FAIL
582. as $foo | [$foo, $bar]583jq: error: $bar is not defined at <top-level>, line 1, column 20:584 . as $foo | [$foo, $bar]585 ^^^^586587%%FAIL588. as {(true):$foo} | $foo589jq: error: Cannot use boolean (true) as object key at <top-level>, line 1, column 8:590 . as {(true):$foo} | $foo591 ^^^^592

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 593–658why, one step back
593# [.,(.[] | {x:.},.),.,.[]]
594595#596# Builtin functions597#5985991+1600null60126026031+1604"wtasdf"6052.06066072-1608null60916106112-(-1)612null61336146151e+0+0.001e3616"I wonder what this will be?"61720e-1618619.+46201562119.0622623.+null624{"a":42}625{"a":42}626627null+.628null629null630631.a+.b632{"a":42}63342634635[1,2,3] + [.]636null637[1,2,3,null]638639{"a":1} + {"b":2} + {"c":3}640"asdfasdf"641{"a":1, "b":2, "c":3}642643"asdf" + "jkl;" + . + . + .644"some string"645"asdfjkl;some stringsome stringsome string"646647"\u0000\u0020\u0000" + .648"\u0000\u0020\u0000"649"\u0000 \u0000\u0000 \u0000"65065142 - .6521165331654655[1,2,3,4,1] - [.,3]6561657[2,4]658

Fix unary operator precedence, allow some expressions as object values (#3053)itchynybefore adoption92daac9

lines 659–662why, one step back
659[-1 as $x | 1,$x]
660null661[1,-1]662

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 663–722why, one step back
663[10 * 20, 20 / .]
6644665[200, 5]6666671 + 2 * 2 + 10 / 2668null66910670671[16 / 4 / 2, 16 / 4 * 2, 16 - 4 - 2, 16 - 4 + 2]672null673[2, 8, 10, 14]6746751e-19 + 1e-20 - 5e-21676null6771.05e-196786791 / 1e-17680null6811e+176826839E999999999, 9999999999E999999990, 1E-999999999, 0.000000001E-999999990684null6859E+9999999996869.999999999E+9999999996871E-9999999996881E-9999999996896905E500000000 > 5E-5000000000, 10000E500000000 > 10000E-5000000000691null692true693true694695# #2825696(1e999999999, 10e999999999) > (1e-1147483646, 0.1e-1147483646)697null698true699true700true701true70270325 % 7704null705470670749732 % 472708null709172710711[(infinite, -infinite) % (1, -1, infinite)]712null713[0,0,0,0,0,-1]714715[nan % 1, 1 % nan | isnan]716null717[true,true]7187191 + tonumber + ("10" | tonumber)720472115722

Fix tonumber and toboolean to reject strings with embedded null bytes (#3496)itchynybefore adoptioned3c7f2

lines 723–726why, one step back
723"123\u0000456" | try tonumber catch .
724null725"string (\"123\\u0000456\") cannot be parsed as a number"726

Adds "toboolean" builtin function for converting strings to booleans (#2098)Brahm Lowerbefore adoptionc350566

lines 727–740why, one step back
727map(toboolean)
728["false","true",false,true]729[false,true,false,true]730731.[] | try toboolean catch .732[null,0,"tru","truee","fals","falsee",[],{}]733"null (null) cannot be parsed as a boolean"734"number (0) cannot be parsed as a boolean"735"string (\"tru\") cannot be parsed as a boolean"736"string (\"truee\") cannot be parsed as a boolean"737"string (\"fals\") cannot be parsed as a boolean"738"string (\"falsee\") cannot be parsed as a boolean"739"array ([]) cannot be parsed as a boolean"740"object ({}) cannot be parsed as a boolean"

Fix tonumber and toboolean to reject strings with embedded null bytes (#3496)itchynybefore adoptioned3c7f2

lines 741–745why, one step back
741
742"true\u0000x", "false\u0000" | try toboolean catch .743null744"string (\"true\\u0000x\") cannot be parsed as a boolean"745"string (\"false\\u0000\") cannot be parsed as a boolean"

Adds "toboolean" builtin function for converting strings to booleans (#2098)Brahm Lowerbefore adoptionc350566

line 746why, one step back
746

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 747–932why, one step back
747[{"a":42},.object,10,.num,false,true,null,"b",[1,4]] | .[] as $x | [$x == .[]]
748{"object": {"a":42}, "num":10.0}749[true, true, false, false, false, false, false, false, false]750[true, true, false, false, false, false, false, false, false]751[false, false, true, true, false, false, false, false, false]752[false, false, true, true, false, false, false, false, false]753[false, false, false, false, true, false, false, false, false]754[false, false, false, false, false, true, false, false, false]755[false, false, false, false, false, false, true, false, false]756[false, false, false, false, false, false, false, true, false]757[false, false, false, false, false, false, false, false, true ]758759[.[] | length]760[[], {}, [1,2], {"a":42}, "asdf", "\u03bc"]761[0, 0, 2, 1, 4, 1]762763utf8bytelength764"asdf\u03bc"7656766767[.[] | try utf8bytelength catch .]768[[], {}, [1,2], 55, true, false]769["array ([]) only strings have UTF-8 byte length","object ({}) only strings have UTF-8 byte length","array ([1,2]) only strings have UTF-8 byte length","number (55) only strings have UTF-8 byte length","boolean (true) only strings have UTF-8 byte length","boolean (false) only strings have UTF-8 byte length"]770771772map(keys)773[{}, {"abcd":1,"abc":2,"abcde":3}, {"x":1, "z": 3, "y":2}]774[[], ["abc","abcd","abcde"], ["x","y","z"]]775776[1,2,empty,3,empty,4]777null778[1,2,3,4]779780map(add)781[[], [1,2,3], ["a","b","c"], [[3],[4,5],[6]], [{"a":1}, {"b":2}, {"a":3}]]782[null, 6, "abc", [3,4,5,6], {"a":3, "b": 2}]783784map_values(.+1)785[0,1,2]786[1,2,3]787788[add(null), add(range(range(10))), add(empty), add(10,range(10))]789null790[null,120,null,55]791792# Real-world use case for add(empty)793.sum = add(.arr[])794{"arr":[]}795{"arr":[],"sum":null}796797add({(.[]):1}) | keys798["a","a","b","a","d","b","d","a","d"]799["a","b","d"]800801#802# User-defined functions803# Oh god.804#805806def f: . + 1; def g: def g: . + 100; f | g | f; (f | g), g8073.0808106.0809105.0810811def f: (1000,2000); f81212341234581310008142000815816def f(a;b;c;d;e;f): [a+1,b,c,d,e,f]; f(.[0];.[1];.[0];.[0];.[0];.[0])817[1,2]818[2,2,1,1,1,1]819820def f: 1; def g: f, def f: 2; def g: 3; f, def f: g; f, g; def f: 4; [f, def f: g; def g: 5; f, g]+[f,g]821null822[4,1,2,3,3,5,4,1,2,3,3]823824# Test precedence of 'def' vs '|'825def a: 0; . | a826null8270828829# Many arguments830def 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])831[0,1,2,3,4,5,6,7,8,9]832[9,8,7,6,5,4,3,2,1,0]833834([1,2] + [4,5])835[1,2,3]836[1,2,4,5]837838true839[1]840true841842null,1,null843"hello"844null8451846null847848[1,2,3]849[5,6]850[1,2,3]851852[.[]|floor]853[-1.1,1.1,1.9]854[-2, 1, 1]855856[.[]|sqrt]857[4,9]858[2,3]859860(add / length) as $m | map((. - $m) as $d | $d * $d) | add / length | sqrt861[2,4,4,4,5,5,7,9]8622863864# Should write a test that calls the -lm function from C (or bc(1)) to865# check that they match the corresponding jq functions. However,866# there's so little template code standing between that it suffices to867# test a handful of these. The results were checked by eye against868# bc(1).869atan * 4 * 1000000|floor / 100000087018713.141592872873[(3.141592 / 2) * (range(0;20) / 20)|cos * 1000000|floor / 1000000]874null875[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]876877[(3.141592 / 2) * (range(0;20) / 20)|sin * 1000000|floor / 1000000]878null879[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]880881882def f(x): x | x; f([.], . + [42])883[1,2,3]884[[[1,2,3]]]885[[1,2,3],42]886[[1,2,3,42]]887[1,2,3,42,42]888889# test multiple function arities and redefinition890def f: .+1; def g: f; def f: .+100; def f(a):a+.+11; [(g|f(20)), f]8911892[33,101]893894# test closures and lexical scoping895def 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)896"more testing"897[1,100,2100.0,100,2100.0]898899# test def f($a) syntax900def 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)901[1,2,3]902true903904# test backtracking through function calls and returns905# this test is *evil*906[[20,10][1,0] as $x | def f: (100,200) as $y | def g: [$x + $y, .]; . + $x | g; f[0] | [f][0][1] | f]907999999999908[[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]]909910# test recursion911def fac: if . == 1 then 1 else . * (. - 1 | fac) end; [.[] | fac]912[1,2,3,4]913[1,2,6,24]914915# test stack overflow and reallocation916# this test is disabled for now, it takes a realllllly long time.917# def f: if length > 1000 then . else .+[1]|f end; f | length918# []919# 1001920921reduce .[] as $x (0; . + $x)922[1,2,4]9237924925reduce .[] as [$i, {j:$j}] (0; . + $i - $j)926[[2,{"j":1}], [5,{"j":3}], [6,{"j":4}]]9275928929reduce [[1,2,10], [3,4,10]][] as [$i,$j] (0; . + $i * $j)930null93114932

Fix unary operator precedence, allow some expressions as object values (#3053)itchynybefore adoption92daac9

lines 933–944why, one step back
933[-reduce -.[] as $x (0; . + $x)]
934[1,2,3]935[6]936937[reduce .[] / .[] as $i (0; . + $i)]938[1,2]939[4.5]940941reduce .[] as $x (0; . + $x) as $x | $x942[1,2,3]9436944

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 945–968why, one step back
945# This, while useless, should still compile.
946reduce . as $n (.; .)947null948null949950# Destructuring951. as {$a, b: [$c, {$d}]} | [$a, $c, $d]952{"a":1, "b":[2,{"d":3}]}953[1,2,3]954955. as {$a, $b:[$c, $d]}| [$a, $b, $c, $d]956{"a":1, "b":[2,{"d":3}]}957[1,[2,{"d":3}],2,{"d":3}]958959# Destructuring with alternation960.[] | . as {$a, b: [$c, {$d}]} ?// [$a, {$b}, $e] ?// $f | [$a, $b, $c, $d, $e, $f]961[{"a":1, "b":[2,{"d":3}]}, [4, {"b":5, "c":6}, 7, 8, 9], "foo"]962[1, null, 2, 3, null, null]963[4, 5, null, null, 7, null]964[null, null, null, null, null, "foo"]965966# Destructuring DUP/POP issues967.[] | . as {a:$a} ?// {a:$a} ?// {a:$a} | $a968[[3],[4],[5],6]

Improve error message truncation with closing delimiters (#3478)itchynybefore adoption22361cf

line 969why, one step back
969# Runtime error: "jq: Cannot index array with string (\"c\")"

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 970–972why, one step back
970
971.[] as {a:$a} ?// {a:$a} ?// {a:$a} | $a972[[3],[4],[5],6]

Improve error message truncation with closing delimiters (#3478)itchynybefore adoption22361cf

line 973why, one step back
973# Runtime error: "jq: Cannot index array with string (\"c\")"

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 974–976why, one step back
974
975[[3],[4],[5],6][] | . as {a:$a} ?// {a:$a} ?// {a:$a} | $a976null

Improve error message truncation with closing delimiters (#3478)itchynybefore adoption22361cf

line 977why, one step back
977# Runtime error: "jq: Cannot index array with string (\"c\")"

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 978–980why, one step back
978
979[[3],[4],[5],6] | .[] as {a:$a} ?// {a:$a} ?// {a:$a} | $a980null

Improve error message truncation with closing delimiters (#3478)itchynybefore adoption22361cf

line 981why, one step back
981# Runtime error: "jq: Cannot index array with string (\"c\")"

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 982–1209why, one step back
982
983.[] | . as {a:$a} ?// {a:$a} ?// $a | $a984[[3],[4],[5],6]985[3]986[4]987[5]9886989990.[] as {a:$a} ?// {a:$a} ?// $a | $a991[[3],[4],[5],6]992[3]993[4]994[5]9956996997[[3],[4],[5],6][] | . as {a:$a} ?// {a:$a} ?// $a | $a998null999[3]1000[4]1001[5]1002610031004[[3],[4],[5],6] | .[] as {a:$a} ?// {a:$a} ?// $a | $a1005null1006[3]1007[4]1008[5]1009610101011.[] | . as {a:$a} ?// $a ?// {a:$a} | $a1012[[3],[4],[5],6]1013[3]1014[4]1015[5]1016610171018.[] as {a:$a} ?// $a ?// {a:$a} | $a1019[[3],[4],[5],6]1020[3]1021[4]1022[5]1023610241025[[3],[4],[5],6][] | . as {a:$a} ?// $a ?// {a:$a} | $a1026null1027[3]1028[4]1029[5]1030610311032[[3],[4],[5],6] | .[] as {a:$a} ?// $a ?// {a:$a} | $a1033null1034[3]1035[4]1036[5]1037610381039.[] | . as $a ?// {a:$a} ?// {a:$a} | $a1040[[3],[4],[5],6]1041[3]1042[4]1043[5]1044610451046.[] as $a ?// {a:$a} ?// {a:$a} | $a1047[[3],[4],[5],6]1048[3]1049[4]1050[5]1051610521053[[3],[4],[5],6][] | . as $a ?// {a:$a} ?// {a:$a} | $a1054null1055[3]1056[4]1057[5]1058610591060[[3],[4],[5],6] | .[] as $a ?// {a:$a} ?// {a:$a} | $a1061null1062[3]1063[4]1064[5]1065610661067. as $dot|any($dot[];not)1068[1,2,3,4,true,false,1,2,3,4,5]1069true10701071. as $dot|any($dot[];not)1072[1,2,3,4,true]1073false10741075. as $dot|all($dot[];.)1076[1,2,3,4,true,false,1,2,3,4,5]1077false10781079. as $dot|all($dot[];.)1080[1,2,3,4,true]1081true10821083# Check short-circuiting1084any(true, error; .)1085"badness"1086true10871088all(false, error; .)1089"badness"1090false10911092any(not)1093[]1094false10951096all(not)1097[]1098true10991100any(not)1101[false]1102true11031104all(not)1105[false]1106true11071108[any,all]1109[]1110[false,true]11111112[any,all]1113[true]1114[true,true]11151116[any,all]1117[false]1118[false,false]11191120[any,all]1121[true,false]1122[true,false]11231124[any,all]1125[null,null,true]1126[true,false]11271128#1129# Paths1130#11311132path(.foo[0,1])1133null1134["foo", 0]1135["foo", 1]11361137path(.[] | select(.>3))1138[1,5,3]1139[1]11401141path(.)1142421143[]11441145try path(.a | map(select(.b == 0))) catch .1146{"a":[{"b":0}]}1147"Invalid path expression with result [{\"b\":0}]"11481149try path(.a | map(select(.b == 0)) | .[0]) catch .1150{"a":[{"b":0}]}1151"Invalid path expression near attempt to access element 0 of [{\"b\":0}]"11521153try path(.a | map(select(.b == 0)) | .c) catch .1154{"a":[{"b":0}]}1155"Invalid path expression near attempt to access element \"c\" of [{\"b\":0}]"11561157try path(.a | map(select(.b == 0)) | .[]) catch .1158{"a":[{"b":0}]}1159"Invalid path expression near attempt to iterate through [{\"b\":0}]"11601161path(.a[path(.b)[0]])1162{"a":{"b":0}}1163["a","b"]11641165[paths]1166[1,[[],{"a":2}]]1167[[0],[1],[1,0],[1,1],[1,1,"a"]]11681169["foo",1] as $p | getpath($p), setpath($p; 20), delpaths([$p])1170{"bar": 42, "foo": ["a", "b", "c", "d"]}1171"b"1172{"bar": 42, "foo": ["a", 20, "c", "d"]}1173{"bar": 42, "foo": ["a", "c", "d"]}11741175map(getpath([2])), map(setpath([2]; 42)), map(delpaths([[2]]))1176[[0], [0,1], [0,1,2]]1177[null, null, 2]1178[[0,null,42], [0,1,42], [0,1,42]]1179[[0], [0,1], [0,1]]11801181map(delpaths([[0,"foo"]]))1182[[{"foo":2, "x":1}], [{"bar":2}]]1183[[{"x":1}], [{"bar":2}]]11841185["foo",1] as $p | getpath($p), setpath($p; 20), delpaths([$p])1186{"bar":false}1187null1188{"bar":false, "foo": [null, 20]}1189{"bar":false}11901191delpaths([[-200]])1192[1,2,3]1193[1,2,3]11941195try delpaths(0) catch .1196{}1197"Paths must be specified as an array"11981199del(.), del(empty), del((.foo,.bar,.baz) | .[2,3,0]), del(.foo[0], .bar[0], .foo, .baz.bar[0].x)1200{"foo": [0,1,2,3,4], "bar": [0,1]}1201null1202{"foo": [0,1,2,3,4], "bar": [0,1]}1203{"foo": [1,4], "bar": [1]}1204{"bar": [1]}12051206del(.[1], .[-6], .[2], .[-3:9])1207[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]1208[0, 3, 5, 6, 9]1209

Fix infinite loop and undefined behavior in `del(.[nan])` (#3490)itchynybefore adoption0df54c8

lines 1210–1217why, one step back
1210del(.[nan])
1211[1,2,3]1212[1,2,3]12131214del(.[nan,nan])1215[1,2,3]1216[1,2,3]1217

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 1218–1283why, one step back
1218# negative index
1219setpath([-1]; 1)1220[0]1221[1]12221223pick(.a.b.c)1224null1225{"a":{"b":{"c":null}}}12261227pick(first)1228[1,2]1229[1]12301231pick(first|first)1232[[10,20],30]1233[[10]]12341235# negative indices in path expressions (since last/1 is .[-1])1236try pick(last) catch .1237[1,2]1238"Out of bounds negative array index"12391240#1241# Assignment1242#1243.message = "goodbye"1244{"message": "hello"}1245{"message": "goodbye"}12461247.foo = .bar1248{"bar":42}1249{"foo":42, "bar":42}12501251.foo |= .+11252{"foo": 42}1253{"foo": 43}12541255.[] += 2, .[] *= 2, .[] -= 2, .[] /= 2, .[] %=21256[1,3,5]1257[3,5,7]1258[2,6,10]1259[-1,1,3]1260[0.5, 1.5, 2.5]1261[1,1,1]12621263[.[] % 7]1264[-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7]1265[0,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,0]12661267.foo += .foo1268{"foo":2}1269{"foo":4}12701271.[0].a |= {"old":., "new":(.+1)}1272[{"a":1,"b":2}]1273[{"a":{"old":1, "new":2},"b":2}]12741275def inc(x): x |= .+1; inc(.[].a)1276[{"a":1,"b":2},{"a":2,"b":4},{"a":7,"b":8}]1277[{"a":2,"b":2},{"a":3,"b":4},{"a":8,"b":8}]12781279# #1358, getpath/1 should work in path expressions1280.[] | try (getpath(["a",0,"b"]) |= 5) catch .1281[null,{"b":0},{"a":0},{"a":null},{"a":[0,1]},{"a":{"b":1}},{"a":[{}]},{"a":[{"c":3}]}]1282{"a":[{"b":5}]}1283{"b":0,"a":[{"b":5}]}

Improve error message truncation with closing delimiters (#3478)itchynybefore adoption22361cf

line 1284why, one step back
1284"Cannot index number with number (0)"

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

line 1285why, one step back
1285{"a":[{"b":5}]}

Improve error message truncation with closing delimiters (#3478)itchynybefore adoption22361cf

lines 1286–1287why, one step back
1286"Cannot index number with string (\"b\")"
1287"Cannot index object with number (0)"

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 1288–1379why, one step back
1288{"a":[{"b":5}]}
1289{"a":[{"c":3,"b":5}]}12901291# #2051, deletion using assigning empty against arrays1292(.[] | select(. >= 2)) |= empty1293[1,5,3,0,7]1294[1,0]12951296.[] |= select(. % 2 == 0)1297[0,1,2,3,4,5]1298[0,2,4]12991300.foo[1,4,2,3] |= empty1301{"foo":[0,1,2,3,4,5]}1302{"foo":[0,5]}13031304.[2][3] = 11305[4]1306[4, null, [null, null, null, 1]]13071308.foo[2].bar = 11309{"foo":[11], "bar":42}1310{"foo":[11,null,{"bar":1}], "bar":42}13111312try ((map(select(.a == 1))[].b) = 10) catch .1313[{"a":0},{"a":1}]1314"Invalid path expression near attempt to iterate through [{\"a\":1}]"13151316try ((map(select(.a == 1))[].a) |= .+1) catch .1317[{"a":0},{"a":1}]1318"Invalid path expression near attempt to iterate through [{\"a\":1}]"13191320def x: .[1,2]; x=101321[0,1,2]1322[0,10,10]13231324try (def x: reverse; x=10) catch .1325[0,1,2]1326"Invalid path expression with result [2,1,0]"13271328.[] = 11329[1,null,Infinity,-Infinity,NaN,-NaN]1330[1,1,1,1,1,1]13311332#1333# Conditionals1334#13351336[.[] | if .foo then "yep" else "nope" end]1337[{"foo":0},{"foo":1},{"foo":[]},{"foo":true},{"foo":false},{"foo":null},{"foo":"foo"},{}]1338["yep","yep","yep","yep","nope","nope","yep","nope"]13391340[.[] | if .baz then "strange" elif .foo then "yep" else "nope" end]1341[{"foo":0},{"foo":1},{"foo":[]},{"foo":true},{"foo":false},{"foo":null},{"foo":"foo"},{}]1342["yep","yep","yep","yep","nope","nope","yep","nope"]13431344[if 1,null,2 then 3 else 4 end]1345null1346[3,4,3]13471348[if empty then 3 else 4 end]1349null1350[]13511352[if 1 then 3,4 else 5 end]1353null1354[3,4]13551356[if null then 3 else 5,6 end]1357null1358[5,6]13591360[if true then 3 end]136171362[3]13631364[if false then 3 end]136571366[7]13671368[if false then 3 else . end]136971370[7]13711372[if false then 3 elif false then 4 end]137371374[7]13751376[if false then 3 elif false then 4 else . end]137771378[7]1379

Fix unary operator precedence, allow some expressions as object values (#3053)itchynybefore adoption92daac9

lines 1380–1391why, one step back
1380[-if true then 1 else 2 end]
1381null1382[-1]13831384{x: if true then 1 else 2 end}1385null1386{"x":1}13871388if true then [.] else . end []1389null1390null1391

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 1392–1471why, one step back
1392[.[] | [.foo[] // .bar]]
1393[{"foo":[1,2], "bar": 42}, {"foo":[1], "bar": null}, {"foo":[null,false,3], "bar": 18}, {"foo":[], "bar":42}, {"foo": [null,false,null], "bar": 41}]1394[[1,2], [1], [3], [42], [41]]13951396.[] //= .[0]1397["hello",true,false,[false],null]1398["hello",true,"hello",[false],"hello"]13991400.[] | [.[0] and .[1], .[0] or .[1]]1401[[true,[]], [false,1], [42,null], [null,false]]1402[true,true]1403[false,true]1404[false,true]1405[false,false]14061407[.[] | not]1408[1,0,false,null,true,"hello"]1409[false,false,true,true,false,false]14101411# Check numeric comparison binops1412[10 > 0, 10 > 10, 10 > 20, 10 < 0, 10 < 10, 10 < 20]1413{}1414[true,false,false,false,false,true]14151416[10 >= 0, 10 >= 10, 10 >= 20, 10 <= 0, 10 <= 10, 10 <= 20]1417{}1418[true,true,false,false,true,true]14191420# And some in/equality tests1421[ 10 == 10, 10 != 10, 10 != 11, 10 == 11]1422{}1423[true,false,true,false]14241425["hello" == "hello", "hello" != "hello", "hello" == "world", "hello" != "world" ]1426{}1427[true,false,false,true]14281429[[1,2,3] == [1,2,3], [1,2,3] != [1,2,3], [1,2,3] == [4,5,6], [1,2,3] != [4,5,6]]1430{}1431[true,false,false,true]14321433[{"foo":42} == {"foo":42},{"foo":42} != {"foo":42}, {"foo":42} != {"bar":42}, {"foo":42} == {"bar":42}]1434{}1435[true,false,true,false]14361437# ugly complicated thing1438[{"foo":[1,2,{"bar":18},"world"]} == {"foo":[1,2,{"bar":18},"world"]},{"foo":[1,2,{"bar":18},"world"]} == {"foo":[1,2,{"bar":19},"world"]}]1439{}1440[true,false]14411442# containment operator1443[("foo" | contains("foo")), ("foobar" | contains("foo")), ("foo" | contains("foobar"))]1444{}1445[true, true, false]14461447# containment operator (embedded NULs!)1448[contains(""), contains("\u0000")]1449"\u0000"1450[true, true]14511452[contains(""), contains("a"), contains("ab"), contains("c"), contains("d")]1453"ab\u0000cd"1454[true, true, true, true, true]14551456[contains("cd"), contains("b\u0000"), contains("ab\u0000")]1457"ab\u0000cd"1458[true, true, true]14591460[contains("b\u0000c"), contains("b\u0000cd"), contains("b\u0000cd")]1461"ab\u0000cd"1462[true, true, true]14631464[contains("@"), contains("\u0000@"), contains("\u0000what")]1465"ab\u0000cd"1466[false, false, false]146714681469# Try/catch and general `?` operator1470[.[]|try if . == 0 then error("foo") elif . == 1 then .a elif . == 2 then empty else . end catch .]1471[0,1,2,3]

Improve error message truncation with closing delimiters (#3478)itchynybefore adoption22361cf

line 1472why, one step back
1472["foo","Cannot index number with string (\"a\")",3]

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 1473–1480why, one step back
1473
1474[.[]|(.a, .a)?]1475[null,true,{"a":1}]1476[null,null,1,1]14771478[[.[]|[.a,.a]]?]1479[null,true,{"a":1}]1480[]

Fix unary operator precedence, allow some expressions as object values (#3053)itchynybefore adoption92daac9

lines 1481–1489why, one step back
1481
1482[if error then 1 else 2 end?]1483"foo"1484[]14851486try error(0) // 11487null148811489

Parse `?//` as `?` and `//` outside destructuring patterns (#3593)A4-Tacksbefore adoptiona19efdd

lines 1490–1494why, one step back
1490# Lex token test #3589, like error(0)? // 1
1491error(0) ?// 11492null149311494

Fix unary operator precedence, allow some expressions as object values (#3053)itchynybefore adoption92daac9

lines 1495–1518why, one step back
14951, try error(2), 3
1496null1497114983149915001 + try 2 catch 3 + 41501null1502715031504[-try .]150511506[-1]15071508try -.? catch .1509"foo"1510"string (\"foo\") cannot be negated"15111512{x: try 1, y: try error catch 2, z: if true then 3 end}1513null1514{"x":1,"y":2,"z":3}15151516{x: 1 + 2, y: false or true, z: null // 3}1517null1518{"x":3,"y":true,"z":3}

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 1519–1554why, one step back
1519
1520.[] | try error catch .1521[1,null,2]152211523null1524215251526try error("\($__loc__)") catch .1527null1528"{\"file\":\"<top-level>\",\"line\":1}"15291530# string operations1531[.[]|startswith("foo")]1532["fo", "foo", "barfoo", "foobar", "barfoob"]1533[false, true, false, true, false]15341535[.[]|endswith("foo")]1536["fo", "foo", "barfoo", "foobar", "barfoob"]1537[false, true, true, false, false]15381539[.[] | split(", ")]1540["a,b, c, d, e,f",", a,b, c, d, e,f, "]1541[["a,b","c","d","e,f"],["","a,b","c","d","e,f",""]]15421543split("")1544"abc"1545["a","b","c"]15461547[.[]|ltrimstr("foo")]1548["fo", "foo", "barfoo", "foobar", "afoo"]1549["fo","","barfoo","bar","afoo"]15501551[.[]|rtrimstr("foo")]1552["fo", "foo", "barfoo", "foobar", "foob"]1553["fo","","bar","foobar","foob"]1554

Add trimstr/1 function (#3319)Gabriel Marinbefore adoption7d8c096

lines 1555–1558why, one step back
1555[.[]|trimstr("foo")]
1556["fo", "foo", "barfoo", "foobarfoo", "foob"]1557["fo","","bar","bar","b"]1558

Fix `rtrimstr("")` always output `""` (#3415)A4-Tacksbefore adoption1694573

lines 1559–1570why, one step back
1559[.[]|ltrimstr("")]
1560["a", "xx", ""]1561["a", "xx", ""]15621563[.[]|rtrimstr("")]1564["a", "xx", ""]1565["a", "xx", ""]15661567[.[]|trimstr("")]1568["a", "xx", ""]1569["a", "xx", ""]1570

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 1571–1578why, one step back
1571[(index(","), rindex(",")), indices(",")]
1572"a,bc,def,ghij,klmno"1573[1,13,[1,4,8,13]]15741575[ index("aba"), rindex("aba"), indices("aba") ]1576"xababababax"1577[1,7,[1,3,5,7]]1578

Add runtime type checks to f_string_indexestlsbolleibefore adoptionfdf8ef0

lines 1579–1587why, one step back
1579# _strindices is used by indices/1 but is callable
1580try _strindices("abc") catch .15811231582"number (123) cannot be searched, as it is not a string"15831584try _strindices(123) catch .1585"abc"1586"number (123) is not a string"1587

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 1588–1659why, one step back
1588# trim
1589# \u000b is vertical tab (\v not supported by json)1590map(trim), map(ltrim), map(rtrim)1591[" \n\t\r\f\u000b", ""," ", "a", " a ", "abc", " abc ", " abc", "abc "]1592["", "", "", "a", "a", "abc", "abc", "abc", "abc"]1593["", "", "", "a", "a ", "abc", "abc ", "abc", "abc "]1594["", "", "", "a", " a", "abc", " abc", " abc", "abc"]15951596trim, ltrim, rtrim1597"\u0009\u000A\u000B\u000C\u000D\u0020\u0085\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u2028\u2029\u202F\u205F\u3000abc\u0009\u000A\u000B\u000C\u000D\u0020\u0085\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u2028\u2029\u202F\u205F\u3000"1598"abc"1599"abc\u0009\u000A\u000B\u000C\u000D\u0020\u0085\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u2028\u2029\u202F\u205F\u3000"1600"\u0009\u000A\u000B\u000C\u000D\u0020\u0085\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u2028\u2029\u202F\u205F\u3000abc"16011602try trim catch ., try ltrim catch ., try rtrim catch .16031231604"trim input must be a string"1605"trim input must be a string"1606"trim input must be a string"16071608indices(1)1609[0,1,1,2,3,4,1,5]1610[1,2,6]16111612indices([1,2])1613[0,1,2,3,1,4,2,5,1,2,6,7]1614[1,8]16151616indices([1,2])1617[1]1618[]16191620indices(", ")1621"a,b, cd,e, fgh, ijkl"1622[3,9,14]16231624index("!")1625"здравствуй мир!"16261416271628.[:rindex("x")]1629"正xyz"1630"正"16311632indices("o")1633"🇬🇧oo"1634[2,3]16351636indices("o")1637"ƒoo"1638[1,2]16391640[.[]|split(",")]1641["a, bc, def, ghij, jklmn, a,b, c,d, e,f", "a,b,c,d, e,f,g,h"]1642[["a"," bc"," def"," ghij"," jklmn"," a","b"," c","d"," e","f"],["a","b","c","d"," e","f","g","h"]]16431644[.[]|split(", ")]1645["a, bc, def, ghij, jklmn, a,b, c,d, e,f", "a,b,c,d, e,f,g,h"]1646[["a","bc","def","ghij","jklmn","a,b","c,d","e,f"],["a,b,c,d","e,f,g,h"]]16471648[.[] * 3]1649["a", "ab", "abc"]1650["aaa", "ababab", "abcabcabc"]16511652[.[] * "abc"]1653[-1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 3.7, 10.0]1654[null,null,"","","abc","abc","abcabcabc","abcabcabcabcabcabcabcabcabcabc"]16551656[. * (nan,-nan)]1657"abc"1658[null,null]1659

Improve performance of repeating strings (#3272)itchynybefore adoptiondc849e9

lines 1660–1671why, one step back
1660. * 100000 | [.[:10],.[-10:]]
1661"abc"1662["abcabcabca","cabcabcabc"]16631664. * 10000000001665""1666""16671668try (. * 1000000000) catch .1669"abc"1670"Repeat string result too long"1671

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 1672–1763why, one step back
1672[.[] / ","]
1673["a, bc, def, ghij, jklmn, a,b, c,d, e,f", "a,b,c,d, e,f,g,h"]1674[["a"," bc"," def"," ghij"," jklmn"," a","b"," c","d"," e","f"],["a","b","c","d"," e","f","g","h"]]16751676[.[] / ", "]1677["a, bc, def, ghij, jklmn, a,b, c,d, e,f", "a,b,c,d, e,f,g,h"]1678[["a","bc","def","ghij","jklmn","a,b","c,d","e,f"],["a,b,c,d","e,f,g,h"]]16791680map(.[1] as $needle | .[0] | contains($needle))1681[[[],[]], [[1,2,3], [1,2]], [[1,2,3], [3,1]], [[1,2,3], [4]], [[1,2,3], [1,4]]]1682[true, true, true, false, false]16831684map(.[1] as $needle | .[0] | contains($needle))1685[[["foobar", "foobaz"], ["baz", "bar"]], [["foobar", "foobaz"], ["foo"]], [["foobar", "foobaz"], ["blap"]]]1686[true, true, false]16871688[({foo: 12, bar:13} | contains({foo: 12})), ({foo: 12} | contains({})), ({foo: 12, bar:13} | contains({baz:14}))]1689{}1690[true, true, false]16911692{foo: {baz: 12, blap: {bar: 13}}, bar: 14} | contains({bar: 14, foo: {blap: {}}})1693{}1694true16951696{foo: {baz: 12, blap: {bar: 13}}, bar: 14} | contains({bar: 14, foo: {blap: {bar: 14}}})1697{}1698false16991700sort1701[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]1702[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}]17031704(sort_by(.b) | sort_by(.a)), sort_by(.a, .b), sort_by(.b, .c), group_by(.b), group_by(.a + .b - .c == 2)1705[{"a": 1, "b": 4, "c": 14}, {"a": 4, "b": 1, "c": 3}, {"a": 1, "b": 4, "c": 3}, {"a": 0, "b": 2, "c": 43}]1706[{"a": 0, "b": 2, "c": 43}, {"a": 1, "b": 4, "c": 14}, {"a": 1, "b": 4, "c": 3}, {"a": 4, "b": 1, "c": 3}]1707[{"a": 0, "b": 2, "c": 43}, {"a": 1, "b": 4, "c": 14}, {"a": 1, "b": 4, "c": 3}, {"a": 4, "b": 1, "c": 3}]1708[{"a": 4, "b": 1, "c": 3}, {"a": 0, "b": 2, "c": 43}, {"a": 1, "b": 4, "c": 3}, {"a": 1, "b": 4, "c": 14}]1709[[{"a": 4, "b": 1, "c": 3}], [{"a": 0, "b": 2, "c": 43}], [{"a": 1, "b": 4, "c": 14}, {"a": 1, "b": 4, "c": 3}]]1710[[{"a": 1, "b": 4, "c": 14}, {"a": 0, "b": 2, "c": 43}], [{"a": 4, "b": 1, "c": 3}, {"a": 1, "b": 4, "c": 3}]]17111712unique1713[1,2,5,3,5,3,1,3]1714[1,2,3,5]17151716unique1717[]1718[]17191720[min, max, min_by(.[1]), max_by(.[1]), min_by(.[2]), max_by(.[2])]1721[[4,2,"a"],[3,1,"a"],[2,4,"a"],[1,3,"a"]]1722[[1,3,"a"],[4,2,"a"],[3,1,"a"],[2,4,"a"],[4,2,"a"],[1,3,"a"]]17231724[min,max,min_by(.),max_by(.)]1725[]1726[null,null,null,null]17271728.foo[.baz]1729{"foo":{"bar":4},"baz":"bar"}1730417311732.[] | .error = "no, it's OK"1733[{"error":true}]1734{"error": "no, it's OK"}17351736[{a:1}] | .[] | .a=9991737null1738{"a": 999}17391740to_entries1741{"a": 1, "b": 2}1742[{"key":"a", "value":1}, {"key":"b", "value":2}]17431744from_entries1745[{"key":"a", "value":1}, {"Key":"b", "Value":2}, {"name":"c", "value":3}, {"Name":"d", "Value":4}]1746{"a": 1, "b": 2, "c": 3, "d": 4}17471748with_entries(.key |= "KEY_" + .)1749{"a": 1, "b": 2}1750{"KEY_a": 1, "KEY_b": 2}17511752map(has("foo"))1753[{"foo": 42}, {}]1754[true, false]17551756map(has(2))1757[[0,1], ["a","b","c"]]1758[false, true]17591760has(nan)1761[0,1,2]1762false1763

Fix undefined behavior on out-of-range array index in has() and del() (#3560)omkar bhorbefore adoptiona8e6d5f

lines 1764–1795why, one step back
1764has(infinite)
1765[0,1,2]1766false17671768has(-infinite)1769[0,1,2]1770false17711772del(.[infinite])1773[1,2,3]1774[1,2,3]17751776del(.[-infinite])1777[1,2,3]1778[1,2,3]17791780has(1e10)1781[0,1,2]1782false17831784has(-1e10)1785[0,1,2]1786false17871788del(.[1e10])1789[1,2,3]1790[1,2,3]17911792del(.[-1e10])1793[1,2,3]1794[1,2,3]1795

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 1796–1921why, one step back
1796keys
1797[42,3,35]1798[0,1,2]17991800[][.]180110000000000000000001802null18031804map([1,2][0:.])1805[-1, 1, 2, 3, 1000000000000000000]1806[[1], [1], [1,2], [1,2], [1,2]]18071808# Test recursive object merge18091810{"k": {"a": 1, "b": 2}} * .1811{"k": {"a": 0,"c": 3}}1812{"k": {"a": 0, "b": 2, "c": 3}}18131814{"k": {"a": 1, "b": 2}, "hello": {"x": 1}} * .1815{"k": {"a": 0,"c": 3}, "hello": 1}1816{"k": {"a": 0, "b": 2, "c": 3}, "hello": 1}18171818{"k": {"a": 1, "b": 2}, "hello": 1} * .1819{"k": {"a": 0,"c": 3}, "hello": {"x": 1}}1820{"k": {"a": 0, "b": 2, "c": 3}, "hello": {"x": 1}}18211822{"a": {"b": 1}, "c": {"d": 2}, "e": 5} * .1823{"a": {"b": 2}, "c": {"d": 3, "f": 9}}1824{"a": {"b": 2}, "c": {"d": 3, "f": 9}, "e": 5}18251826[.[]|arrays]1827[1,2,"foo",[],[3,[]],{},true,false,null]1828[[],[3,[]]]18291830[.[]|objects]1831[1,2,"foo",[],[3,[]],{},true,false,null]1832[{}]18331834[.[]|iterables]1835[1,2,"foo",[],[3,[]],{},true,false,null]1836[[],[3,[]],{}]18371838[.[]|scalars]1839[1,2,"foo",[],[3,[]],{},true,false,null]1840[1,2,"foo",true,false,null]18411842[.[]|values]1843[1,2,"foo",[],[3,[]],{},true,false,null]1844[1,2,"foo",[],[3,[]],{},true,false]18451846[.[]|booleans]1847[1,2,"foo",[],[3,[]],{},true,false,null]1848[true,false]18491850[.[]|nulls]1851[1,2,"foo",[],[3,[]],{},true,false,null]1852[null]18531854flatten1855[0, [1], [[2]], [[[3]]]]1856[0, 1, 2, 3]18571858flatten(0)1859[0, [1], [[2]], [[[3]]]]1860[0, [1], [[2]], [[[3]]]]18611862flatten(2)1863[0, [1], [[2]], [[[3]]]]1864[0, 1, 2, [3]]18651866flatten(2)1867[0, [1, [2]], [1, [[3], 2]]]1868[0, 1, 2, 1, [3], 2]18691870try flatten(-1) catch .1871[0, [1], [[2]], [[[3]]]]1872"flatten depth must not be negative"18731874transpose1875[[1], [2,3]]1876[[1,2],[null,3]]18771878transpose1879[]1880[]18811882ascii_upcase1883"useful but not for é"1884"USEFUL BUT NOT FOR é"18851886bsearch(0,1,2,3,4)1887[1,2,3]1888-11889018901189121892-418931894bsearch({x:1})1895[{ "x": 0 },{ "x": 1 },{ "x": 2 }]1896118971898try ["OK", bsearch(0)] catch ["KO",.]1899"aa"1900["KO","string (\"aa\") cannot be searched from"]19011902strftime("%Y-%m-%dT%H:%M:%SZ")1903[2015,2,5,23,51,47,4,63]1904"2015-03-05T23:51:47Z"19051906strftime("%A, %B %d, %Y")19071435677542.8223511908"Tuesday, June 30, 2015"19091910strftime("%Y-%m-%dT%H:%M:%SZ")1911[2024,2,15]1912"2024-03-15T00:00:00Z"19131914mktime1915[2024,8,21]1916172687680019171918gmtime191914255995071920[2015,2,5,23,51,47,4,63]1921

Refactor tm2jv to handle fractional seconds removing duplicated code (#3489)itchynybefore adoption601a37f

lines 1922–1925why, one step back
1922gmtime[5]
19231425599507.25192447.251925

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 1926–1946why, one step back
1926# test invalid tm input
1927try strftime("%Y-%m-%dT%H:%M:%SZ") catch .1928["a",1,2,3,4,5,6,7]1929"strftime/1 requires parsed datetime inputs"19301931try strflocaltime("%Y-%m-%dT%H:%M:%SZ") catch .1932["a",1,2,3,4,5,6,7]1933"strflocaltime/1 requires parsed datetime inputs"19341935try mktime catch .1936["a",1,2,3,4,5,6,7]1937"mktime requires parsed datetime inputs"19381939# oss-fuzz #67403: non-string argument with number input fails assert1940try ["OK", strftime([])] catch ["KO", .]194101942["KO","strftime/1 requires a string format"]19431944try ["OK", strflocaltime({})] catch ["KO", .]194501946["KO","strflocaltime/1 requires a string format"]

Fix portability of strptime especially for Windows (#3342)itchynybefore adoption7cc202a

line 1947why, one step back
1947
1948[strftime("", " %Y ")]194901950["", " 1970 "]19511952try strftime("%c" * 10) catch .195301954"strftime/1: result too long"19551956[strflocaltime("", " %Y ")]1957[2015,2,5,23,51,47,4,63]1958["", " 2015 "]19591960try strflocaltime("%c" * 10) catch .1961[2015,2,5,23,51,47,4,63]1962"strflocaltime/1: result too long"1963

Fix portability of strptime especially for Windows (#3342)itchynybefore adoption7cc202a

lines 1964–1972why, one step back
1964[strptime("%Y-%m-%dT%H:%M:%SZ")|(.,mktime)]
1965"2015-03-05T23:51:47Z"1966[[2015,2,5,23,51,47,4,63],1425599507]19671968# Check day-of-week and day of year computations1969# (should trip an assert if this fails)1970last(range(365 * 67)|("1970-03-01T01:02:03Z"|strptime("%Y-%m-%dT%H:%M:%SZ")|mktime) + (86400 * .)|strftime("%Y-%m-%dT%H:%M:%SZ")|strptime("%Y-%m-%dT%H:%M:%SZ"))1971null1972[2037,1,11,1,2,3,3,41]

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

line 1973why, one step back
1973

Parse the full ISO 8601 grammar in `fromdateiso8601` (#3617)itchynybefore adoptionfd25c3e

lines 1974–2078why, one step back
1974# fromdateiso8601 accepts the calendar, ordinal and week date forms,
1975# in both the extended and the basic representation1976[("2015-03-05T23:51:47Z", "20150305T235147Z", "2015-064T23:51:47Z", "2015064T235147Z", "2015-W10-4T23:51:47Z", "2015W104T235147Z") | fromdateiso8601]1977null1978[1425599507,1425599507,1425599507,1425599507,1425599507,1425599507]19791980# fractional seconds, with either decimal sign1981[("2015-03-05T23:51:47.25Z", "2015-03-05T23:51:47,25Z", "20150305T235147.25Z") | fromdateiso8601]1982null1983[1425599507.25,1425599507.25,1425599507.25]19841985# UTC offsets; an absent offset means UTC1986[("2015-03-06T08:51:47+09:00", "2015-03-06T08:51:47+0900", "2015-03-06T08:51:47+09", "2015-03-05T18:21:47-05:30", "2015-03-05T23:51:47z", "2015-03-05T23:51:47") | fromdateiso8601]1987null1988[1425599507,1425599507,1425599507,1425599507,1425599507,1425599507]19891990# the date and the time may be separated by "T", "t" or a space1991[("2015-03-05t23:51:47Z", "2015-03-05 23:51:47Z") | fromdateiso8601]1992null1993[1425599507,1425599507]19941995# the W, T and Z designators may be written in lower case1996[("2015-w10-4t23:51:47z", "2015w104t235147z", "2015-03-05t23:51:47z") | fromdateiso8601]1997null1998[1425599507,1425599507,1425599507]19992000# expanded years carry a sign and exactly six digits

The first 2,000 of 2,846 lines.