Skip to content
Myr

Update tests/man.test

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nicolas Williams · committed by Nicolas Williams · parent 2a67fc3 · Browse files · 1 file+906 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+906 added−0 removed

  • tests:+906 added−0 removed

1 file+906 added−0 removed

modified:tests/man.test+906 added
894 unmodified lines
895(.a, .b) |= range(3)896null897{"a":0,"b":0}898899.900"Hello, world!"901"Hello, world!"902903. | tojson90412345678909876543212345905"12345678909876543212345"906907map([., . == 1]) | tojson908[1, 1.000, 1.0, 100e-2]909"[[1,true],[1.000,true],[1.0,true],[1.00,true]]"910911. as $big | [$big, $big + 1] | map(. > 10000000000000000000000000000000)91210000000000000000000000000000001913[true, false]914915.foo916{"foo": 42, "bar": "less interesting data"}91742918919.foo920{"notfoo": true, "alsonotfoo": false}921null922923.["foo"]924{"foo": 42}92542926927.foo?928{"foo": 42, "bar": "less interesting data"}92942930931.foo?932{"notfoo": true, "alsonotfoo": false}933null934935.["foo"]?936{"foo": 42}93742938939[.foo?]940[1,2]941[]942943.[0]944[{"name":"JSON", "good":true}, {"name":"XML", "good":false}]945{"name":"JSON", "good":true}946947.[2]948[{"name":"JSON", "good":true}, {"name":"XML", "good":false}]949null950951.[-2]952[1,2,3]9532954955.[2:4]956["a","b","c","d","e"]957["c", "d"]958959.[2:4]960"abcdefghi"961"cd"962963.[:3]964["a","b","c","d","e"]965["a", "b", "c"]966967.[-2:]968["a","b","c","d","e"]969["d", "e"]970971.[]972[{"name":"JSON", "good":true}, {"name":"XML", "good":false}]973{"name":"JSON", "good":true}974{"name":"XML", "good":false}975976.[]977[]978979.[]980{"a": 1, "b": 1}98119821983984.foo, .bar985{"foo": 42, "bar": "something else", "baz": true}98642987"something else"988989.user, .projects[]990{"user":"stedolan", "projects": ["jq", "wikiflow"]}991"stedolan"992"jq"993"wikiflow"994995.[4,2]996["a","b","c","d","e"]997"e"998"c"9991000.[] | .name1001[{"name":"JSON", "good":true}, {"name":"XML", "good":false}]1002"JSON"1003"XML"10041005(. + 2) * 51006110071510081009[.user, .projects[]]1010{"user":"stedolan", "projects": ["jq", "wikiflow"]}1011["stedolan", "jq", "wikiflow"]10121013[ .[] | . * 2]1014[1, 2, 3]1015[2, 4, 6]10161017{user, title: .titles[]}1018{"user":"stedolan","titles":["JQ Primer", "More JQ"]}1019{"user":"stedolan", "title": "JQ Primer"}1020{"user":"stedolan", "title": "More JQ"}10211022{(.user): .titles}1023{"user":"stedolan","titles":["JQ Primer", "More JQ"]}1024{"stedolan": ["JQ Primer", "More JQ"]}10251026..|.a?1027[[{"a":1}]]1028110291030.a + 11031{"a": 7}1032810331034.a + .b1035{"a": [1,2], "b": [3,4]}1036[1,2,3,4]10371038.a + null1039{"a": 1}1040110411042.a + 11043{}1044110451046{a: 1} + {b: 2} + {c: 3} + {a: 42}1047null1048{"a": 42, "b": 2, "c": 3}104910504 - .a1051{"a":3}1052110531054. - ["xml", "yaml"]1055["xml", "yaml", "json"]1056["json"]1057105810 / . * 3105951060610611062. / ", "1063"a, b,c,d, e"1064["a","b,c,d","e"]10651066{"k": {"a": 1, "b": 2}} * {"k": {"a": 0,"c": 3}}1067null1068{"k": {"a": 0, "b": 2, "c": 3}}10691070.[] | (1 / .)?1071[1,0,-1]107211073-110741075.[] | length1076[[1,2], "string", {"a":2}, null, -5]107721078610791108001081510821083utf8bytelength1084"\u03bc"1085210861087keys1088{"abc": 1, "abcd": 2, "Foo": 3}1089["Foo", "abc", "abcd"]10901091keys1092[42,3,35]1093[0,1,2]10941095map(has("foo"))1096[{"foo": 42}, {}]1097[true, false]10981099map(has(2))1100[[0,1], ["a","b","c"]]1101[false, true]11021103.[] | in({"foo": 42})1104["foo", "bar"]1105true1106false11071108map(in([0,1]))1109[2, 0]1110[false, true]11111112map(.+1)1113[1,2,3]1114[2,3,4]11151116map_values(.+1)1117{"a": 1, "b": 2, "c": 3}1118{"a": 2, "b": 3, "c": 4}11191120map(., .)1121[1,2]1122[1,1,2,2]11231124map_values(. // empty)1125{"a": null, "b": true, "c": false}1126{"b":true}11271128pick(.a, .b.c, .x)1129{"a": 1, "b": {"c": 2, "d": 3}, "e": 4}1130{"a":1,"b":{"c":2},"x":null}11311132[1,2,3,4] | pick(.[2], .[0], .[0])1133[1,2,3,4]1134[1,null,3]11351136path(.a[0].b)1137null1138["a",0,"b"]11391140[path(..)]1141{"a":[{"b":1}]}1142[[],["a"],["a",0],["a",0,"b"]]11431144del(.foo)1145{"foo": 42, "bar": 9001, "baz": 42}1146{"bar": 9001, "baz": 42}11471148del(.[1, 2])1149["foo", "bar", "baz"]1150["foo"]11511152getpath(["a","b"])1153null1154null11551156[getpath(["a","b"], ["a","c"])]1157{"a":{"b":0, "c":1}}1158[0, 1]11591160setpath(["a","b"]; 1)1161null1162{"a": {"b": 1}}11631164setpath(["a","b"]; 1)1165{"a":{"b":0}}1166{"a": {"b": 1}}11671168setpath([0,"a"]; 1)1169null1170[{"a":1}]11711172delpaths([["a","b"]])1173{"a":{"b":1},"x":{"y":2}}1174{"a":{},"x":{"y":2}}11751176to_entries1177{"a": 1, "b": 2}1178[{"key":"a", "value":1}, {"key":"b", "value":2}]11791180from_entries1181[{"key":"a", "value":1}, {"key":"b", "value":2}]1182{"a": 1, "b": 2}11831184with_entries(.key |= "KEY_" + .)1185{"a": 1, "b": 2}1186{"KEY_a": 1, "KEY_b": 2}11871188map(select(. >= 2))1189[1,5,3,0,7]1190[5,3,7]11911192.[] | select(.id == "second")1193[{"id": "first", "val": 1}, {"id": "second", "val": 2}]1194{"id": "second", "val": 2}11951196.[]|numbers1197[[],{},1,"foo",null,true,false]11981119912001, empty, 21201null120211203212041205[1,2,empty,3]1206null1207[1,2,3]12081209try error("\($__loc__)") catch .1210null1211"{\"file\":\"<top-level>\",\"line\":1}"12121213[paths]1214[1,[[],{"a":2}]]1215[[0],[1],[1,0],[1,1],[1,1,"a"]]12161217[paths(type == "number")]1218[1,[[],{"a":2}]]1219[[0],[1,1,"a"]]12201221add1222["a","b","c"]1223"abc"12241225add1226[1, 2, 3]1227612281229add1230[]1231null12321233any1234[true, false]1235true12361237any1238[false, false]1239false12401241any1242[]1243false12441245all1246[true, false]1247false12481249all1250[true, true]1251true12521253all1254[]1255true12561257flatten1258[1, [2], [[3]]]1259[1, 2, 3]12601261flatten(1)1262[1, [2], [[3]]]1263[1, 2, [3]]12641265flatten1266[[]]1267[]12681269flatten1270[{"foo": "bar"}, [{"foo": "baz"}]]1271[{"foo": "bar"}, {"foo": "baz"}]12721273range(2; 4)1274null127521276312771278[range(2; 4)]1279null1280[2,3]12811282[range(4)]1283null1284[0,1,2,3]12851286[range(0; 10; 3)]1287null1288[0,3,6,9]12891290[range(0; 10; -1)]1291null1292[]12931294[range(0; -5; -1)]1295null1296[0,-1,-2,-3,-4]12971298floor12993.141591300313011302sqrt130391304313051306.[] | tonumber1307[1, "1"]130811309113101311.[] | tostring1312[1, "1", [1]]1313"1"1314"1"1315"[1]"13161317map(type)1318[0, false, [], {}, null, "hello"]1319["number", "boolean", "array", "object", "null", "string"]13201321.[] | (infinite * .) < 01322[-1, 1]1323true1324false13251326infinite, nan | type1327null1328"number"1329"number"13301331sort1332[8,3,null,6]1333[null,3,6,8]13341335sort_by(.foo)1336[{"foo":4, "bar":10}, {"foo":3, "bar":100}, {"foo":2, "bar":1}]1337[{"foo":2, "bar":1}, {"foo":3, "bar":100}, {"foo":4, "bar":10}]13381339group_by(.foo)1340[{"foo":1, "bar":10}, {"foo":3, "bar":100}, {"foo":1, "bar":1}]1341[[{"foo":1, "bar":10}, {"foo":1, "bar":1}], [{"foo":3, "bar":100}]]13421343min1344[5,4,2,7]1345213461347max_by(.foo)1348[{"foo":1, "bar":14}, {"foo":2, "bar":3}]1349{"foo":2, "bar":3}13501351unique1352[1,2,5,3,5,3,1,3]1353[1,2,3,5]13541355unique_by(.foo)1356[{"foo": 1, "bar": 2}, {"foo": 1, "bar": 3}, {"foo": 4, "bar": 5}]1357[{"foo": 1, "bar": 2}, {"foo": 4, "bar": 5}]13581359unique_by(length)1360["chunky", "bacon", "kitten", "cicada", "asparagus"]1361["bacon", "chunky", "asparagus"]13621363reverse1364[1,2,3,4]1365[4,3,2,1]13661367contains("bar")1368"foobar"1369true13701371contains(["baz", "bar"])1372["foobar", "foobaz", "blarp"]1373true13741375contains(["bazzzzz", "bar"])1376["foobar", "foobaz", "blarp"]1377false13781379contains({foo: 12, bar: [{barp: 12}]})1380{"foo": 12, "bar":[1,2,{"barp":12, "blip":13}]}1381true13821383contains({foo: 12, bar: [{barp: 15}]})1384{"foo": 12, "bar":[1,2,{"barp":12, "blip":13}]}1385false13861387indices(", ")1388"a,b, cd, efg, hijk"1389[3,7,12]13901391indices(1)1392[0,1,2,1,3,1,4]1393[1,3,5]13941395indices([1,2])1396[0,1,2,3,1,4,2,5,1,2,6,7]1397[1,8]13981399index(", ")1400"a,b, cd, efg, hijk"1401314021403rindex(", ")1404"a,b, cd, efg, hijk"14051214061407inside("foobar")1408"bar"1409true14101411inside(["foobar", "foobaz", "blarp"])1412["baz", "bar"]1413true14141415inside(["foobar", "foobaz", "blarp"])1416["bazzzzz", "bar"]1417false14181419inside({"foo": 12, "bar":[1,2,{"barp":12, "blip":13}]})1420{"foo": 12, "bar": [{"barp": 12}]}1421true14221423inside({"foo": 12, "bar":[1,2,{"barp":12, "blip":13}]})1424{"foo": 12, "bar": [{"barp": 15}]}1425false14261427[.[]|startswith("foo")]1428["fo", "foo", "barfoo", "foobar", "barfoob"]1429[false, true, false, true, false]14301431[.[]|endswith("foo")]1432["foobar", "barfoo"]1433[false, true]14341435combinations1436[[1,2], [3, 4]]1437[1, 3]1438[1, 4]1439[2, 3]1440[2, 4]14411442combinations(2)1443[0, 1]1444[0, 0]1445[0, 1]1446[1, 0]1447[1, 1]14481449[.[]|ltrimstr("foo")]1450["fo", "foo", "barfoo", "foobar", "afoo"]1451["fo","","barfoo","bar","afoo"]14521453[.[]|rtrimstr("foo")]1454["fo", "foo", "barfoo", "foobar", "foob"]1455["fo","","bar","foobar","foob"]14561457explode1458"foobar"1459[102,111,111,98,97,114]14601461implode1462[65, 66, 67]1463"ABC"14641465split(", ")1466"a, b,c,d, e, "1467["a","b,c,d","e",""]14681469join(", ")1470["a","b,c,d","e"]1471"a, b,c,d, e"14721473join(" ")1474["a",1,2.3,true,null,false]1475"a 1 2.3 true false"14761477[while(.<100; .*2)]147811479[1,2,4,8,16,32,64]14801481[repeat(.*2, error)?]148211483[2]14841485[.,1]|until(.[0] < 1; [.[0] - 1, .[1] * .[0]])|.[1]1486414872414881489recurse(.foo[])1490{"foo":[{"foo": []}, {"foo":[{"foo":[]}]}]}1491{"foo":[{"foo":[]},{"foo":[{"foo":[]}]}]}1492{"foo":[]}1493{"foo":[{"foo":[]}]}1494{"foo":[]}14951496recurse1497{"a":0,"b":[1]}1498{"a":0,"b":[1]}149901500[1]1501115021503recurse(. * .; . < 20)15042150521506415071615081509walk(if type == "array" then sort else . end)1510[[4, 1, 7], [8, 5, 2], [3, 6, 9]]1511[[1,4,7],[2,5,8],[3,6,9]]15121513walk( if type == "object" then with_entries( .key |= sub( "^_+"; "") ) else . end )1514[ { "_a": { "__b": 2 } } ]1515[{"a":{"b":2}}]15161517$ENV.PAGER1518null1519"less"15201521env.PAGER1522null1523"less"15241525transpose1526[[1], [2,3]]1527[[1,2],[null,3]]15281529bsearch(0)1530[0,1]1531015321533bsearch(0)1534[1,2,3]1535-115361537bsearch(4) as $ix | if $ix < 0 then .[-(1+$ix)] = 4 else . end1538[1,2,3]1539[1,2,3,4]15401541"The input was \(.), which is one less than \(.+1)"1542421543"The input was 42, which is one less than 43"15441545[.[]|tostring]1546[1, "foo", ["foo"]]1547["1","foo","[\"foo\"]"]15481549[.[]|tojson]1550[1, "foo", ["foo"]]1551["1","\"foo\"","[\"foo\"]"]15521553[.[]|tojson|fromjson]1554[1, "foo", ["foo"]]1555[1,"foo",["foo"]]15561557@html1558"This works if x < y"1559"This works if x &lt; y"15601561@sh "echo \(.)"1562"O'Hara's Ale"1563"echo 'O'\\''Hara'\\''s Ale'"15641565@base641566"This is a message"1567"VGhpcyBpcyBhIG1lc3NhZ2U="15681569@base64d1570"VGhpcyBpcyBhIG1lc3NhZ2U="1571"This is a message"15721573fromdate1574"2015-03-05T23:51:47Z"1575142559950715761577strptime("%Y-%m-%dT%H:%M:%SZ")1578"2015-03-05T23:51:47Z"1579[2015,2,5,23,51,47,4,63]15801581strptime("%Y-%m-%dT%H:%M:%SZ")|mktime1582"2015-03-05T23:51:47Z"1583142559950715841585. == false1586null1587false15881589. == {"b": {"d": (4 + 1e-20), "c": 3}, "a":1}1590{"a":1, "b": {"c": 3, "d": 4}}1591true15921593.[] == 11594[1, 1.0, "1", "banana"]1595true1596true1597false1598false15991600if . == 0 then "zero" elif . == 1 then "one" else "many" end160121602"many"16031604. < 5160521606true1607160842 and "a string"1609null1610true16111612(true, false) or false1613null1614true1615false16161617(true, true) and (true, false)1618null1619true1620false1621true1622false16231624[true, false | not]1625null1626[false, true]16271628.foo // 421629{"foo": 19}16301916311632.foo // 421633{}16344216351636try .a catch ". is not an object"1637true1638". is not an object"16391640[.[]|try .a]1641[{}, true, {"a":1}]1642[null, 1]16431644try error("some exception") catch .1645true1646"some exception"16471648[.[] | .a?]1649[{}, true, {"a":1}]1650[null, 1]16511652[.[] | tonumber?]1653["1", "invalid", "3", 4]1654[1, 3, 4]16551656test("foo")1657"foo"1658true16591660.[] | test("a b c # spaces are ignored"; "ix")1661["xabcd", "ABC"]1662true1663true16641665match("(abc)+"; "g")1666"abc abc"1667{"offset": 0, "length": 3, "string": "abc", "captures": [{"offset": 0, "length": 3, "string": "abc", "name": null}]}1668{"offset": 4, "length": 3, "string": "abc", "captures": [{"offset": 4, "length": 3, "string": "abc", "name": null}]}16691670match("foo")1671"foo bar foo"1672{"offset": 0, "length": 3, "string": "foo", "captures": []}16731674match(["foo", "ig"])1675"foo bar FOO"1676{"offset": 0, "length": 3, "string": "foo", "captures": []}1677{"offset": 8, "length": 3, "string": "FOO", "captures": []}16781679match("foo (?<bar123>bar)? foo"; "ig")1680"foo bar foo foo foo"1681{"offset": 0, "length": 11, "string": "foo bar foo", "captures": [{"offset": 4, "length": 3, "string": "bar", "name": "bar123"}]}1682{"offset": 12, "length": 8, "string": "foo foo", "captures": [{"offset": -1, "length": 0, "string": null, "name": "bar123"}]}16831684[ match("."; "g")] | length1685"abc"1686316871688capture("(?<a>[a-z]+)-(?<n>[0-9]+)")1689"xyzzy-14"1690{ "a": "xyzzy", "n": "14" }16911692.bar as $x | .foo | . + $x1693{"foo":10, "bar":200}169421016951696. as $i|[(.*2|. as $i| $i), $i]169751698[10,5]16991700. as [$a, $b, {c: $c}] | $a + $b + $c1701[2, 3, {"c": 4, "d": 5}]1702917031704.[] as [$a, $b] | {a: $a, b: $b}1705[[0], [0, 1], [2, 1, 0]]1706{"a":0,"b":null}1707{"a":0,"b":1}1708{"a":2,"b":1}17091710.[] as {$a, $b, c: {$d, $e}} ?// {$a, $b, c: [{$d, $e}]} | {$a, $b, $d, $e}1711[{"a": 1, "b": 2, "c": {"d": 3, "e": 4}}, {"a": 1, "b": 2, "c": [{"d": 3, "e": 4}]}]1712{"a":1,"b":2,"d":3,"e":4}1713{"a":1,"b":2,"d":3,"e":4}17141715.[] as {$a, $b, c: {$d}} ?// {$a, $b, c: [{$e}]} | {$a, $b, $d, $e}1716[{"a": 1, "b": 2, "c": {"d": 3, "e": 4}}, {"a": 1, "b": 2, "c": [{"d": 3, "e": 4}]}]1717{"a":1,"b":2,"d":3,"e":null}1718{"a":1,"b":2,"d":null,"e":4}17191720.[] as [$a] ?// [$b] | if $a != null then error("err: \($a)") else {$a,$b} end1721[[3]]1722{"a":null,"b":3}17231724def addvalue(f): . + [f]; map(addvalue(.[0]))1725[[1,2],[10,20]]1726[[1,2,1], [10,20,10]]17271728def addvalue(f): f as $x | map(. + $x); addvalue(.[0])1729[[1,2],[10,20]]1730[[1,2,1,2], [10,20,1,2]]17311732reduce .[] as $item (0; . + $item)1733[10,2,5,3]17342017351736isempty(empty)1737null1738true17391740[limit(3;.[])]1741[0,1,2,3,4,5,6,7,8,9]1742[0,1,2]17431744[first(range(.)), last(range(.)), nth(./2; range(.))]1745101746[0,9,5]17471748[range(.)]|[first, last, nth(5)]1749101750[0,9,5]17511752[foreach .[] as $item ([[],[]]; if $item == null then [[],.[0]] else [(.[0] + [$item]),[]] end; if $item == null then .[1] else empty end)]1753[1,2,3,4,null,"a","b",null]1754[[1,2,3,4],["a","b"]]17551756def range(init; upto; by): def _range: if (by > 0 and . < upto) or (by < 0 and . > upto) then ., ((.+by)|_range) else . end; if by == 0 then init else init|_range end | select((by > 0 and . < upto) or (by < 0 and . > upto)); range(0; 10; 3)1757null1758017593176061761917621763def while(cond; update): def _while: if cond then ., (update | _while) else empty end; _while; [while(.<100; .*2)]176411765[1,2,4,8,16,32,64]17661767[1|truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])]176811769[[[0],2],[[0]]]17701771fromstream(1|truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]]))1772null1773[2]17741775. as $dot|fromstream($dot|tostream)|.==$dot1776[0,[1,{"a":1},{"b":2}]]1777true17781779(..|select(type=="boolean")) |= if . then 1 else 0 end1780[true,false,[5,true,[true,[false]],false]]1781[1,0,[5,1,[1,[0]],0]]17821783.foo += 11784{"foo": 42}1785{"foo": 43}17861787.a = .b1788{"a": {"b": 10}, "b": 20}1789{"a":20,"b":20}17901791.a |= .b1792{"a": {"b": 10}, "b": 20}1793{"a":10,"b":20}17941795(.a, .b) = range(3)1796null1797{"a":0,"b":0}1798{"a":1,"b":1}1799{"a":2,"b":2}18001801(.a, .b) |= range(3)1802null1803{"a":0,"b":0}1804