Blame SOURCES/0002-add-mantest.patch

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