Blame SOURCES/0002-add-mantest.patch

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