Blame SOURCES/0002-add-mantest.patch

0173ab
man.test from commit 50a7022ea68fb37faefdcd7a35661df72fbfd655
0173ab
0173ab
diff --git a/tests/man.test b/tests/man.test
0173ab
new file mode 100644
0173ab
index 0000000..2a49eff
0173ab
--- /dev/null
0173ab
+++ b/tests/man.test
0173ab
@@ -0,0 +1,843 @@
0173ab
+.
0173ab
+"Hello, world!"
0173ab
+"Hello, world!"
0173ab
+
0173ab
+.foo
0173ab
+{"foo": 42, "bar": "less interesting data"}
0173ab
+42
0173ab
+
0173ab
+.foo
0173ab
+{"notfoo": true, "alsonotfoo": false}
0173ab
+null
0173ab
+
0173ab
+.["foo"]
0173ab
+{"foo": 42}
0173ab
+42
0173ab
+
0173ab
+.foo?
0173ab
+{"foo": 42, "bar": "less interesting data"}
0173ab
+42
0173ab
+
0173ab
+.foo?
0173ab
+{"notfoo": true, "alsonotfoo": false}
0173ab
+null
0173ab
+
0173ab
+.["foo"]?
0173ab
+{"foo": 42}
0173ab
+42
0173ab
+
0173ab
+[.foo?]
0173ab
+[1,2]
0173ab
+[]
0173ab
+
0173ab
+.[0]
0173ab
+[{"name":"JSON", "good":true}, {"name":"XML", "good":false}]
0173ab
+{"name":"JSON", "good":true}
0173ab
+
0173ab
+.[2]
0173ab
+[{"name":"JSON", "good":true}, {"name":"XML", "good":false}]
0173ab
+null
0173ab
+
0173ab
+.[-2]
0173ab
+[1,2,3]
0173ab
+2
0173ab
+
0173ab
+.[2:4]
0173ab
+["a","b","c","d","e"]
0173ab
+["c", "d"]
0173ab
+
0173ab
+.[2:4]
0173ab
+"abcdefghi"
0173ab
+"cd"
0173ab
+
0173ab
+.[:3]
0173ab
+["a","b","c","d","e"]
0173ab
+["a", "b", "c"]
0173ab
+
0173ab
+.[-2:]
0173ab
+["a","b","c","d","e"]
0173ab
+["d", "e"]
0173ab
+
0173ab
+.[]
0173ab
+[{"name":"JSON", "good":true}, {"name":"XML", "good":false}]
0173ab
+{"name":"JSON", "good":true}
0173ab
+{"name":"XML", "good":false}
0173ab
+
0173ab
+.[]
0173ab
+[]
0173ab
+
0173ab
+.[]
0173ab
+{"a": 1, "b": 1}
0173ab
+1
0173ab
+1
0173ab
+
0173ab
+.foo, .bar
0173ab
+{"foo": 42, "bar": "something else", "baz": true}
0173ab
+42
0173ab
+"something else"
0173ab
+
0173ab
+.user, .projects[]
0173ab
+{"user":"stedolan", "projects": ["jq", "wikiflow"]}
0173ab
+"stedolan"
0173ab
+"jq"
0173ab
+"wikiflow"
0173ab
+
0173ab
+.[4,2]
0173ab
+["a","b","c","d","e"]
0173ab
+"e"
0173ab
+"c"
0173ab
+
0173ab
+.[] | .name
0173ab
+[{"name":"JSON", "good":true}, {"name":"XML", "good":false}]
0173ab
+"JSON"
0173ab
+"XML"
0173ab
+
0173ab
+(. + 2) * 5
0173ab
+1
0173ab
+15
0173ab
+
0173ab
+[.user, .projects[]]
0173ab
+{"user":"stedolan", "projects": ["jq", "wikiflow"]}
0173ab
+["stedolan", "jq", "wikiflow"]
0173ab
+
0173ab
+[ .[] | . * 2]
0173ab
+[1, 2, 3]
0173ab
+[2, 4, 6]
0173ab
+
0173ab
+{user, title: .titles[]}
0173ab
+{"user":"stedolan","titles":["JQ Primer", "More JQ"]}
0173ab
+{"user":"stedolan", "title": "JQ Primer"}
0173ab
+{"user":"stedolan", "title": "More JQ"}
0173ab
+
0173ab
+{(.user): .titles}
0173ab
+{"user":"stedolan","titles":["JQ Primer", "More JQ"]}
0173ab
+{"stedolan": ["JQ Primer", "More JQ"]}
0173ab
+
0173ab
+..|.a?
0173ab
+[[{"a":1}]]
0173ab
+1
0173ab
+
0173ab
+.a + 1
0173ab
+{"a": 7}
0173ab
+8
0173ab
+
0173ab
+.a + .b
0173ab
+{"a": [1,2], "b": [3,4]}
0173ab
+[1,2,3,4]
0173ab
+
0173ab
+.a + null
0173ab
+{"a": 1}
0173ab
+1
0173ab
+
0173ab
+.a + 1
0173ab
+{}
0173ab
+1
0173ab
+
0173ab
+{a: 1} + {b: 2} + {c: 3} + {a: 42}
0173ab
+null
0173ab
+{"a": 42, "b": 2, "c": 3}
0173ab
+
0173ab
+4 - .a
0173ab
+{"a":3}
0173ab
+1
0173ab
+
0173ab
+. - ["xml", "yaml"]
0173ab
+["xml", "yaml", "json"]
0173ab
+["json"]
0173ab
+
0173ab
+10 / . * 3
0173ab
+5
0173ab
+6
0173ab
+
0173ab
+. / ", "
0173ab
+"a, b,c,d, e"
0173ab
+["a","b,c,d","e"]
0173ab
+
0173ab
+{"k": {"a": 1, "b": 2}} * {"k": {"a": 0,"c": 3}}
0173ab
+null
0173ab
+{"k": {"a": 0, "b": 2, "c": 3}}
0173ab
+
0173ab
+.[] | (1 / .)?
0173ab
+[1,0,-1]
0173ab
+1
0173ab
+-1
0173ab
+
0173ab
+.[] | length
0173ab
+[[1,2], "string", {"a":2}, null]
0173ab
+2
0173ab
+6
0173ab
+1
0173ab
+0
0173ab
+
0173ab
+utf8bytelength
0173ab
+"\u03bc"
0173ab
+2
0173ab
+
0173ab
+keys
0173ab
+{"abc": 1, "abcd": 2, "Foo": 3}
0173ab
+["Foo", "abc", "abcd"]
0173ab
+
0173ab
+keys
0173ab
+[42,3,35]
0173ab
+[0,1,2]
0173ab
+
0173ab
+map(has("foo"))
0173ab
+[{"foo": 42}, {}]
0173ab
+[true, false]
0173ab
+
0173ab
+map(has(2))
0173ab
+[[0,1], ["a","b","c"]]
0173ab
+[false, true]
0173ab
+
0173ab
+.[] | in({"foo": 42})
0173ab
+["foo", "bar"]
0173ab
+true
0173ab
+false
0173ab
+
0173ab
+map(in([0,1]))
0173ab
+[2, 0]
0173ab
+[false, true]
0173ab
+
0173ab
+map(.+1)
0173ab
+[1,2,3]
0173ab
+[2,3,4]
0173ab
+
0173ab
+map_values(.+1)
0173ab
+{"a": 1, "b": 2, "c": 3}
0173ab
+{"a": 2, "b": 3, "c": 4}
0173ab
+
0173ab
+path(.a[0].b)
0173ab
+null
0173ab
+["a",0,"b"]
0173ab
+
0173ab
+[path(..)]
0173ab
+{"a":[{"b":1}]}
0173ab
+[[],["a"],["a",0],["a",0,"b"]]
0173ab
+
0173ab
+del(.foo)
0173ab
+{"foo": 42, "bar": 9001, "baz": 42}
0173ab
+{"bar": 9001, "baz": 42}
0173ab
+
0173ab
+del(.[1, 2])
0173ab
+["foo", "bar", "baz"]
0173ab
+["foo"]
0173ab
+
0173ab
+getpath(["a","b"])
0173ab
+null
0173ab
+null
0173ab
+
0173ab
+[getpath(["a","b"], ["a","c"])]
0173ab
+{"a":{"b":0, "c":1}}
0173ab
+[0, 1]
0173ab
+
0173ab
+setpath(["a","b"]; 1)
0173ab
+null
0173ab
+{"a": {"b": 1}}
0173ab
+
0173ab
+setpath(["a","b"]; 1)
0173ab
+{"a":{"b":0}}
0173ab
+{"a": {"b": 1}}
0173ab
+
0173ab
+setpath([0,"a"]; 1)
0173ab
+null
0173ab
+[{"a":1}]
0173ab
+
0173ab
+delpaths([["a","b"]])
0173ab
+{"a":{"b":1},"x":{"y":2}}
0173ab
+{"a":{},"x":{"y":2}}
0173ab
+
0173ab
+to_entries
0173ab
+{"a": 1, "b": 2}
0173ab
+[{"key":"a", "value":1}, {"key":"b", "value":2}]
0173ab
+
0173ab
+from_entries
0173ab
+[{"key":"a", "value":1}, {"key":"b", "value":2}]
0173ab
+{"a": 1, "b": 2}
0173ab
+
0173ab
+with_entries(.key |= "KEY_" + .)
0173ab
+{"a": 1, "b": 2}
0173ab
+{"KEY_a": 1, "KEY_b": 2}
0173ab
+
0173ab
+map(select(. >= 2))
0173ab
+[1,5,3,0,7]
0173ab
+[5,3,7]
0173ab
+
0173ab
+.[] | select(.id == "second")
0173ab
+[{"id": "first", "val": 1}, {"id": "second", "val": 2}]
0173ab
+{"id": "second", "val": 2}
0173ab
+
0173ab
+.[]|numbers
0173ab
+[[],{},1,"foo",null,true,false]
0173ab
+1
0173ab
+
0173ab
+1, empty, 2
0173ab
+null
0173ab
+1
0173ab
+2
0173ab
+
0173ab
+[1,2,empty,3]
0173ab
+null
0173ab
+[1,2,3]
0173ab
+
0173ab
+try error("\($__loc__)") catch .
0173ab
+null
0173ab
+"{\"file\":\"<top-level>\",\"line\":1}"
0173ab
+
0173ab
+[paths]
0173ab
+[1,[[],{"a":2}]]
0173ab
+[[0],[1],[1,0],[1,1],[1,1,"a"]]
0173ab
+
0173ab
+[paths(scalars)]
0173ab
+[1,[[],{"a":2}]]
0173ab
+[[0],[1,1,"a"]]
0173ab
+
0173ab
+add
0173ab
+["a","b","c"]
0173ab
+"abc"
0173ab
+
0173ab
+add
0173ab
+[1, 2, 3]
0173ab
+6
0173ab
+
0173ab
+add
0173ab
+[]
0173ab
+null
0173ab
+
0173ab
+any
0173ab
+[true, false]
0173ab
+true
0173ab
+
0173ab
+any
0173ab
+[false, false]
0173ab
+false
0173ab
+
0173ab
+any
0173ab
+[]
0173ab
+false
0173ab
+
0173ab
+all
0173ab
+[true, false]
0173ab
+false
0173ab
+
0173ab
+all
0173ab
+[true, true]
0173ab
+true
0173ab
+
0173ab
+all
0173ab
+[]
0173ab
+true
0173ab
+
0173ab
+flatten
0173ab
+[1, [2], [[3]]]
0173ab
+[1, 2, 3]
0173ab
+
0173ab
+flatten(1)
0173ab
+[1, [2], [[3]]]
0173ab
+[1, 2, [3]]
0173ab
+
0173ab
+flatten
0173ab
+[[]]
0173ab
+[]
0173ab
+
0173ab
+flatten
0173ab
+[{"foo": "bar"}, [{"foo": "baz"}]]
0173ab
+[{"foo": "bar"}, {"foo": "baz"}]
0173ab
+
0173ab
+range(2;4)
0173ab
+null
0173ab
+2
0173ab
+3
0173ab
+
0173ab
+[range(2;4)]
0173ab
+null
0173ab
+[2,3]
0173ab
+
0173ab
+[range(4)]
0173ab
+null
0173ab
+[0,1,2,3]
0173ab
+
0173ab
+[range(0;10;3)]
0173ab
+null
0173ab
+[0,3,6,9]
0173ab
+
0173ab
+[range(0;10;-1)]
0173ab
+null
0173ab
+[]
0173ab
+
0173ab
+[range(0;-5;-1)]
0173ab
+null
0173ab
+[0,-1,-2,-3,-4]
0173ab
+
0173ab
+floor
0173ab
+3.14159
0173ab
+3
0173ab
+
0173ab
+sqrt
0173ab
+9
0173ab
+3
0173ab
+
0173ab
+.[] | tonumber
0173ab
+[1, "1"]
0173ab
+1
0173ab
+1
0173ab
+
0173ab
+.[] | tostring
0173ab
+[1, "1", [1]]
0173ab
+"1"
0173ab
+"1"
0173ab
+"[1]"
0173ab
+
0173ab
+map(type)
0173ab
+[0, false, [], {}, null, "hello"]
0173ab
+["number", "boolean", "array", "object", "null", "string"]
0173ab
+
0173ab
+.[] | (infinite * .) < 0
0173ab
+[-1, 1]
0173ab
+true
0173ab
+false
0173ab
+
0173ab
+infinite, nan | type
0173ab
+null
0173ab
+"number"
0173ab
+"number"
0173ab
+
0173ab
+sort
0173ab
+[8,3,null,6]
0173ab
+[null,3,6,8]
0173ab
+
0173ab
+sort_by(.foo)
0173ab
+[{"foo":4, "bar":10}, {"foo":3, "bar":100}, {"foo":2, "bar":1}]
0173ab
+[{"foo":2, "bar":1}, {"foo":3, "bar":100}, {"foo":4, "bar":10}]
0173ab
+
0173ab
+group_by(.foo)
0173ab
+[{"foo":1, "bar":10}, {"foo":3, "bar":100}, {"foo":1, "bar":1}]
0173ab
+[[{"foo":1, "bar":10}, {"foo":1, "bar":1}], [{"foo":3, "bar":100}]]
0173ab
+
0173ab
+min
0173ab
+[5,4,2,7]
0173ab
+2
0173ab
+
0173ab
+max_by(.foo)
0173ab
+[{"foo":1, "bar":14}, {"foo":2, "bar":3}]
0173ab
+{"foo":2, "bar":3}
0173ab
+
0173ab
+unique
0173ab
+[1,2,5,3,5,3,1,3]
0173ab
+[1,2,3,5]
0173ab
+
0173ab
+unique_by(.foo)
0173ab
+[{"foo": 1, "bar": 2}, {"foo": 1, "bar": 3}, {"foo": 4, "bar": 5}]
0173ab
+[{"foo": 1, "bar": 2}, {"foo": 4, "bar": 5}]
0173ab
+
0173ab
+unique_by(length)
0173ab
+["chunky", "bacon", "kitten", "cicada", "asparagus"]
0173ab
+["bacon", "chunky", "asparagus"]
0173ab
+
0173ab
+reverse
0173ab
+[1,2,3,4]
0173ab
+[4,3,2,1]
0173ab
+
0173ab
+contains("bar")
0173ab
+"foobar"
0173ab
+true
0173ab
+
0173ab
+contains(["baz", "bar"])
0173ab
+["foobar", "foobaz", "blarp"]
0173ab
+true
0173ab
+
0173ab
+contains(["bazzzzz", "bar"])
0173ab
+["foobar", "foobaz", "blarp"]
0173ab
+false
0173ab
+
0173ab
+contains({foo: 12, bar: [{barp: 12}]})
0173ab
+{"foo": 12, "bar":[1,2,{"barp":12, "blip":13}]}
0173ab
+true
0173ab
+
0173ab
+contains({foo: 12, bar: [{barp: 15}]})
0173ab
+{"foo": 12, "bar":[1,2,{"barp":12, "blip":13}]}
0173ab
+false
0173ab
+
0173ab
+indices(", ")
0173ab
+"a,b, cd, efg, hijk"
0173ab
+[3,7,12]
0173ab
+
0173ab
+indices(1)
0173ab
+[0,1,2,1,3,1,4]
0173ab
+[1,3,5]
0173ab
+
0173ab
+indices([1,2])
0173ab
+[0,1,2,3,1,4,2,5,1,2,6,7]
0173ab
+[1,8]
0173ab
+
0173ab
+index(", ")
0173ab
+"a,b, cd, efg, hijk"
0173ab
+3
0173ab
+
0173ab
+rindex(", ")
0173ab
+"a,b, cd, efg, hijk"
0173ab
+12
0173ab
+
0173ab
+inside("foobar")
0173ab
+"bar"
0173ab
+true
0173ab
+
0173ab
+inside(["foobar", "foobaz", "blarp"])
0173ab
+["baz", "bar"]
0173ab
+true
0173ab
+
0173ab
+inside(["foobar", "foobaz", "blarp"])
0173ab
+["bazzzzz", "bar"]
0173ab
+false
0173ab
+
0173ab
+inside({"foo": 12, "bar":[1,2,{"barp":12, "blip":13}]})
0173ab
+{"foo": 12, "bar": [{"barp": 12}]}
0173ab
+true
0173ab
+
0173ab
+inside({"foo": 12, "bar":[1,2,{"barp":12, "blip":13}]})
0173ab
+{"foo": 12, "bar": [{"barp": 15}]}
0173ab
+false
0173ab
+
0173ab
+[.[]|startswith("foo")]
0173ab
+["fo", "foo", "barfoo", "foobar", "barfoob"]
0173ab
+[false, true, false, true, false]
0173ab
+
0173ab
+[.[]|endswith("foo")]
0173ab
+["foobar", "barfoo"]
0173ab
+[false, true]
0173ab
+
0173ab
+combinations
0173ab
+[[1,2], [3, 4]]
0173ab
+[1, 3]
0173ab
+[1, 4]
0173ab
+[2, 3]
0173ab
+[2, 4]
0173ab
+
0173ab
+combinations(2)
0173ab
+[0, 1]
0173ab
+[0, 0]
0173ab
+[0, 1]
0173ab
+[1, 0]
0173ab
+[1, 1]
0173ab
+
0173ab
+[.[]|ltrimstr("foo")]
0173ab
+["fo", "foo", "barfoo", "foobar", "afoo"]
0173ab
+["fo","","barfoo","bar","afoo"]
0173ab
+
0173ab
+[.[]|rtrimstr("foo")]
0173ab
+["fo", "foo", "barfoo", "foobar", "foob"]
0173ab
+["fo","","bar","foobar","foob"]
0173ab
+
0173ab
+explode
0173ab
+"foobar"
0173ab
+[102,111,111,98,97,114]
0173ab
+
0173ab
+implode
0173ab
+[65, 66, 67]
0173ab
+"ABC"
0173ab
+
0173ab
+split(", ")
0173ab
+"a, b,c,d, e, "
0173ab
+["a","b,c,d","e",""]
0173ab
+
0173ab
+join(", ")
0173ab
+["a","b,c,d","e"]
0173ab
+"a, b,c,d, e"
0173ab
+
0173ab
+join(" ")
0173ab
+["a",1,2.3,true,null,false]
0173ab
+"a 1 2.3 true  false"
0173ab
+
0173ab
+[while(.<100; .*2)]
0173ab
+1
0173ab
+[1,2,4,8,16,32,64]
0173ab
+
0173ab
+[.,1]|until(.[0] < 1; [.[0] - 1, .[1] * .[0]])|.[1]
0173ab
+4
0173ab
+24
0173ab
+
0173ab
+recurse(.foo[])
0173ab
+{"foo":[{"foo": []}, {"foo":[{"foo":[]}]}]}
0173ab
+{"foo":[{"foo":[]},{"foo":[{"foo":[]}]}]}
0173ab
+{"foo":[]}
0173ab
+{"foo":[{"foo":[]}]}
0173ab
+{"foo":[]}
0173ab
+
0173ab
+recurse
0173ab
+{"a":0,"b":[1]}
0173ab
+{"a":0,"b":[1]}
0173ab
+0
0173ab
+[1]
0173ab
+1
0173ab
+
0173ab
+recurse(. * .; . < 20)
0173ab
+2
0173ab
+2
0173ab
+4
0173ab
+16
0173ab
+
0173ab
+walk(if type == "array" then sort else . end)
0173ab
+[[4, 1, 7], [8, 5, 2], [3, 6, 9]]
0173ab
+[[1,4,7],[2,5,8],[3,6,9]]
0173ab
+
0173ab
+walk( if type == "object" then with_entries( .key |= sub( "^_+"; "") ) else . end )
0173ab
+[ { "_a": { "__b": 2 } } ]
0173ab
+[{"a":{"b":2}}]
0173ab
+
0173ab
+$ENV.PAGER
0173ab
+null
0173ab
+"less"
0173ab
+
0173ab
+env.PAGER
0173ab
+null
0173ab
+"less"
0173ab
+
0173ab
+transpose
0173ab
+[[1], [2,3]]
0173ab
+[[1,2],[null,3]]
0173ab
+
0173ab
+bsearch(0)
0173ab
+[0,1]
0173ab
+0
0173ab
+
0173ab
+bsearch(0)
0173ab
+[1,2,3]
0173ab
+-1
0173ab
+
0173ab
+bsearch(4) as $ix | if $ix < 0 then .[-(1+$ix)] = 4 else . end
0173ab
+[1,2,3]
0173ab
+[1,2,3,4]
0173ab
+
0173ab
+"The input was \(.), which is one less than \(.+1)"
0173ab
+42
0173ab
+"The input was 42, which is one less than 43"
0173ab
+
0173ab
+[.[]|tostring]
0173ab
+[1, "foo", ["foo"]]
0173ab
+["1","foo","[\"foo\"]"]
0173ab
+
0173ab
+[.[]|tojson]
0173ab
+[1, "foo", ["foo"]]
0173ab
+["1","\"foo\"","[\"foo\"]"]
0173ab
+
0173ab
+[.[]|tojson|fromjson]
0173ab
+[1, "foo", ["foo"]]
0173ab
+[1,"foo",["foo"]]
0173ab
+
0173ab
+@html
0173ab
+"This works if x < y"
0173ab
+"This works if x < y"
0173ab
+
0173ab
+@sh "echo \(.)"
0173ab
+"O'Hara's Ale"
0173ab
+"echo 'O'\\''Hara'\\''s Ale'"
0173ab
+
0173ab
+@base64
0173ab
+"This is a message"
0173ab
+"VGhpcyBpcyBhIG1lc3NhZ2U="
0173ab
+
0173ab
+@base64d
0173ab
+"VGhpcyBpcyBhIG1lc3NhZ2U="
0173ab
+"This is a message"
0173ab
+
0173ab
+fromdate
0173ab
+"2015-03-05T23:51:47Z"
0173ab
+1425599507
0173ab
+
0173ab
+strptime("%Y-%m-%dT%H:%M:%SZ")
0173ab
+"2015-03-05T23:51:47Z"
0173ab
+[2015,2,5,23,51,47,4,63]
0173ab
+
0173ab
+strptime("%Y-%m-%dT%H:%M:%SZ")|mktime
0173ab
+"2015-03-05T23:51:47Z"
0173ab
+1425599507
0173ab
+
0173ab
+.[] == 1
0173ab
+[1, 1.0, "1", "banana"]
0173ab
+true
0173ab
+true
0173ab
+false
0173ab
+false
0173ab
+
0173ab
+if . == 0 then "zero" elif . == 1 then "one" else "many" end
0173ab
+2
0173ab
+"many"
0173ab
+
0173ab
+. < 5
0173ab
+2
0173ab
+true
0173ab
+
0173ab
+42 and "a string"
0173ab
+null
0173ab
+true
0173ab
+
0173ab
+(true, false) or false
0173ab
+null
0173ab
+true
0173ab
+false
0173ab
+
0173ab
+(true, true) and (true, false)
0173ab
+null
0173ab
+true
0173ab
+false
0173ab
+true
0173ab
+false
0173ab
+
0173ab
+[true, false | not]
0173ab
+null
0173ab
+[false, true]
0173ab
+
0173ab
+.foo // 42
0173ab
+{"foo": 19}
0173ab
+19
0173ab
+
0173ab
+.foo // 42
0173ab
+{}
0173ab
+42
0173ab
+
0173ab
+try .a catch ". is not an object"
0173ab
+true
0173ab
+". is not an object"
0173ab
+
0173ab
+[.[]|try .a]
0173ab
+[{}, true, {"a":1}]
0173ab
+[null, 1]
0173ab
+
0173ab
+try error("some exception") catch .
0173ab
+true
0173ab
+"some exception"
0173ab
+
0173ab
+[.[]|(.a)?]
0173ab
+[{}, true, {"a":1}]
0173ab
+[null, 1]
0173ab
+
0173ab
+test("foo")
0173ab
+"foo"
0173ab
+true
0173ab
+
0173ab
+.[] | test("a b c # spaces are ignored"; "ix")
0173ab
+["xabcd", "ABC"]
0173ab
+true
0173ab
+true
0173ab
+
0173ab
+match("(abc)+"; "g")
0173ab
+"abc abc"
0173ab
+{"offset": 0, "length": 3, "string": "abc", "captures": [{"offset": 0, "length": 3, "string": "abc", "name": null}]}
0173ab
+{"offset": 4, "length": 3, "string": "abc", "captures": [{"offset": 4, "length": 3, "string": "abc", "name": null}]}
0173ab
+
0173ab
+match("foo")
0173ab
+"foo bar foo"
0173ab
+{"offset": 0, "length": 3, "string": "foo", "captures": []}
0173ab
+
0173ab
+match(["foo", "ig"])
0173ab
+"foo bar FOO"
0173ab
+{"offset": 0, "length": 3, "string": "foo", "captures": []}
0173ab
+{"offset": 8, "length": 3, "string": "FOO", "captures": []}
0173ab
+
0173ab
+match("foo (?<bar123>bar)? foo"; "ig")
0173ab
+"foo bar foo foo  foo"
0173ab
+{"offset": 0, "length": 11, "string": "foo bar foo", "captures": [{"offset": 4, "length": 3, "string": "bar", "name": "bar123"}]}
0173ab
+{"offset": 12, "length": 8, "string": "foo  foo", "captures": [{"offset": -1, "length": 0, "string": null, "name": "bar123"}]}
0173ab
+
0173ab
+[ match("."; "g")] | length
0173ab
+"abc"
0173ab
+3
0173ab
+
0173ab
+capture("(?[a-z]+)-(?<n>[0-9]+)")
0173ab
+"xyzzy-14"
0173ab
+{ "a": "xyzzy", "n": "14" }
0173ab
+
0173ab
+.bar as $x | .foo | . + $x
0173ab
+{"foo":10, "bar":200}
0173ab
+210
0173ab
+
0173ab
+. as $i|[(.*2|. as $i| $i), $i]
0173ab
+5
0173ab
+[10,5]
0173ab
+
0173ab
+. as [$a, $b, {c: $c}] | $a + $b + $c
0173ab
+[2, 3, {"c": 4, "d": 5}]
0173ab
+9
0173ab
+
0173ab
+.[] as [$a, $b] | {a: $a, b: $b}
0173ab
+[[0], [0, 1], [2, 1, 0]]
0173ab
+{"a":0,"b":null}
0173ab
+{"a":0,"b":1}
0173ab
+{"a":2,"b":1}
0173ab
+
0173ab
+.[] as {$a, $b, c: {$d, $e}} ?// {$a, $b, c: [{$d, $e}]} | {$a, $b, $d, $e}
0173ab
+[{"a": 1, "b": 2, "c": {"d": 3, "e": 4}}, {"a": 1, "b": 2, "c": [{"d": 3, "e": 4}]}]
0173ab
+{"a":1,"b":2,"d":3,"e":4}
0173ab
+{"a":1,"b":2,"d":3,"e":4}
0173ab
+
0173ab
+.[] as {$a, $b, c: {$d}} ?// {$a, $b, c: [{$e}]} | {$a, $b, $d, $e}
0173ab
+[{"a": 1, "b": 2, "c": {"d": 3, "e": 4}}, {"a": 1, "b": 2, "c": [{"d": 3, "e": 4}]}]
0173ab
+{"a":1,"b":2,"d":3,"e":null}
0173ab
+{"a":1,"b":2,"d":null,"e":4}
0173ab
+
0173ab
+.[] as [$a] ?// [$b] | if $a != null then error("err: \($a)") else {$a,$b} end
0173ab
+[[3]]
0173ab
+{"a":null,"b":3}
0173ab
+
0173ab
+def addvalue(f): . + [f]; map(addvalue(.[0]))
0173ab
+[[1,2],[10,20]]
0173ab
+[[1,2,1], [10,20,10]]
0173ab
+
0173ab
+def addvalue(f): f as $x | map(. + $x); addvalue(.[0])
0173ab
+[[1,2],[10,20]]
0173ab
+[[1,2,1,2], [10,20,1,2]]
0173ab
+
0173ab
+reduce .[] as $item (0; . + $item)
0173ab
+[10,2,5,3]
0173ab
+20
0173ab
+
0173ab
+isempty(empty)
0173ab
+null
0173ab
+true
0173ab
+
0173ab
+[limit(3;.[])]
0173ab
+[0,1,2,3,4,5,6,7,8,9]
0173ab
+[0,1,2]
0173ab
+
0173ab
+[first(range(.)), last(range(.)), nth(./2; range(.))]
0173ab
+10
0173ab
+[0,9,5]
0173ab
+
0173ab
+[range(.)]|[first, last, nth(5)]
0173ab
+10
0173ab
+[0,9,5]
0173ab
+
0173ab
+[foreach .[] as $item ([[],[]]; if $item == null then [[],.[0]] else [(.[0] + [$item]),[]] end; if $item == null then .[1] else empty end)]
0173ab
+[1,2,3,4,null,"a","b",null]
0173ab
+[[1,2,3,4],["a","b"]]
0173ab
+
0173ab
+def 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)
0173ab
+null
0173ab
+0
0173ab
+3
0173ab
+6
0173ab
+9
0173ab
+
0173ab
+def while(cond; update): def _while: if cond then ., (update | _while) else empty end; _while; [while(.<100; .*2)]
0173ab
+1
0173ab
+[1,2,4,8,16,32,64]
0173ab
+
0173ab
+[1|truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])]
0173ab
+1
0173ab
+[[[0],2],[[0]]]
0173ab
+
0173ab
+fromstream(1|truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]]))
0173ab
+null
0173ab
+[2]
0173ab
+
0173ab
+. as $dot|fromstream($dot|tostream)|.==$dot
0173ab
+[0,[1,{"a":1},{"b":2}]]
0173ab
+true
0173ab
+
0173ab
+(..|select(type=="boolean")) |= if . then 1 else 0 end
0173ab
+[true,false,[5,true,[true,[false]],false]]
0173ab
+[1,0,[5,1,[1,[0]],0]]
0173ab
+
0173ab
+.foo += 1
0173ab
+{"foo": 42}
0173ab
+{"foo": 43}
0173ab
+