Blame SOURCES/0002-add-mantest.patch

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