Skip to content
Myr

Update "tests/man.test" and remove superflous whitespace in manual.yml

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

tests/man.test was generated incorrectly and had some duplicate tests, the new CI workflow didn't like that.

authored by Emanuele Torre · committed by Nico Williams · parent c049061 · Browse files · 3 files+5 added−903 removed
This commit

State

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

Diff stats

3 files+5 added−903 removed

  • tests:+0 added−898 removed
  • other:+5 added−5 removed

3 files+5 added−903 removed

modified:docs/content/manual/manual.yml+4 added-4 removed
907 unmodified lines
908909 For any filter `f`, `map(f)` and `map_values(f)` apply `f`910 to each of the values in the input array or object, that is,911 to the values of `.[]`.912 912913 In the absence of errors, `map(f)` always outputs an array914 whereas `map_values(f)` outputs an array if given an array,915 or an object if given an object.916
27 unmodified lines
944 map_values(empty) #=> []945946 `map(f)` is equivalent to `[.[] | f]` and947 `map_values(f)` is equivalent to `.[] |= f`.948 948949 In fact, these are their implementations.950951952 examples:
15 unmodified lines
968969970 - title: "`pick(pathexps)`"971 body: |972 973 Emit the projection of the input object or array defined by the specified 972973 Emit the projection of the input object or array defined by the specified974 sequence of path expressions, such that if p is any one of these specifications,975 then `(. | p)` will evaluate to the same value as `(. | pick(pathexps) | p)`.976 For arrays, negative indices and .[m:n] specifications should not be used.977
2521 unmodified lines
modified:tests/man.test-898 removed
217 unmodified lines
218map_values(.+1)219{"a": 1, "b": 2, "c": 3}220{"a": 2, "b": 3, "c": 4}221222pick(.a, .b.c, .x)223{"a": 1, "b": {"c": 2, "d": 3}, "e": 4}224{"a":1,"b":{"c":2},"x":null}225226[1,2,3,4] | pick(.[2], .[0], .[0])227[1,2,3,4]228[1,null,3]229230path(.a[0].b)231null232["a",0,"b"]233234[path(..)]235{"a":[{"b":1}]}236[[],["a"],["a",0],["a",0,"b"]]237238del(.foo)239{"foo": 42, "bar": 9001, "baz": 42}240{"bar": 9001, "baz": 42}241242del(.[1, 2])243["foo", "bar", "baz"]244["foo"]245246getpath(["a","b"])247null248null249250[getpath(["a","b"], ["a","c"])]251{"a":{"b":0, "c":1}}252[0, 1]253254setpath(["a","b"]; 1)255null256{"a": {"b": 1}}257258setpath(["a","b"]; 1)259{"a":{"b":0}}260{"a": {"b": 1}}261262setpath([0,"a"]; 1)263null264[{"a":1}]265266delpaths([["a","b"]])267{"a":{"b":1},"x":{"y":2}}268{"a":{},"x":{"y":2}}269270to_entries271{"a": 1, "b": 2}272[{"key":"a", "value":1}, {"key":"b", "value":2}]273274from_entries275[{"key":"a", "value":1}, {"key":"b", "value":2}]276{"a": 1, "b": 2}277278with_entries(.key |= "KEY_" + .)279{"a": 1, "b": 2}280{"KEY_a": 1, "KEY_b": 2}281282map(select(. >= 2))283[1,5,3,0,7]284[5,3,7]285286.[] | select(.id == "second")287[{"id": "first", "val": 1}, {"id": "second", "val": 2}]288{"id": "second", "val": 2}289290.[]|numbers291[[],{},1,"foo",null,true,false]29212932941, empty, 2295null29612972298299[1,2,empty,3]300null301[1,2,3]302303try error("\($__loc__)") catch .304null305"{\"file\":\"<top-level>\",\"line\":1}"306307[paths]308[1,[[],{"a":2}]]309[[0],[1],[1,0],[1,1],[1,1,"a"]]310311[paths(type == "number")]312[1,[[],{"a":2}]]313[[0],[1,1,"a"]]314315add316["a","b","c"]317"abc"318319add320[1, 2, 3]3216322323add324[]325null326327any328[true, false]329true330331any332[false, false]333false334335any336[]337false338339all340[true, false]341false342343all344[true, true]345true346347all348[]349true350351flatten352[1, [2], [[3]]]353[1, 2, 3]354355flatten(1)356[1, [2], [[3]]]357[1, 2, [3]]358359flatten360[[]]361[]362363flatten364[{"foo": "bar"}, [{"foo": "baz"}]]365[{"foo": "bar"}, {"foo": "baz"}]366367range(2; 4)368null36923703371372[range(2; 4)]373null374[2,3]375376[range(4)]377null378[0,1,2,3]379380[range(0; 10; 3)]381null382[0,3,6,9]383384[range(0; 10; -1)]385null386[]387388[range(0; -5; -1)]389null390[0,-1,-2,-3,-4]391392floor3933.141593943395396sqrt39793983399400.[] | tonumber401[1, "1"]40214031404405.[] | tostring406[1, "1", [1]]407"1"408"1"409"[1]"410411map(type)412[0, false, [], {}, null, "hello"]413["number", "boolean", "array", "object", "null", "string"]414415.[] | (infinite * .) < 0416[-1, 1]417true418false419420infinite, nan | type421null422"number"423"number"424425sort426[8,3,null,6]427[null,3,6,8]428429sort_by(.foo)430[{"foo":4, "bar":10}, {"foo":3, "bar":100}, {"foo":2, "bar":1}]431[{"foo":2, "bar":1}, {"foo":3, "bar":100}, {"foo":4, "bar":10}]432433group_by(.foo)434[{"foo":1, "bar":10}, {"foo":3, "bar":100}, {"foo":1, "bar":1}]435[[{"foo":1, "bar":10}, {"foo":1, "bar":1}], [{"foo":3, "bar":100}]]436437min438[5,4,2,7]4392440441max_by(.foo)442[{"foo":1, "bar":14}, {"foo":2, "bar":3}]443{"foo":2, "bar":3}444445unique446[1,2,5,3,5,3,1,3]447[1,2,3,5]448449unique_by(.foo)450[{"foo": 1, "bar": 2}, {"foo": 1, "bar": 3}, {"foo": 4, "bar": 5}]451[{"foo": 1, "bar": 2}, {"foo": 4, "bar": 5}]452453unique_by(length)454["chunky", "bacon", "kitten", "cicada", "asparagus"]455["bacon", "chunky", "asparagus"]456457reverse458[1,2,3,4]459[4,3,2,1]460461contains("bar")462"foobar"463true464465contains(["baz", "bar"])466["foobar", "foobaz", "blarp"]467true468469contains(["bazzzzz", "bar"])470["foobar", "foobaz", "blarp"]471false472473contains({foo: 12, bar: [{barp: 12}]})474{"foo": 12, "bar":[1,2,{"barp":12, "blip":13}]}475true476477contains({foo: 12, bar: [{barp: 15}]})478{"foo": 12, "bar":[1,2,{"barp":12, "blip":13}]}479false480481indices(", ")482"a,b, cd, efg, hijk"483[3,7,12]484485indices(1)486[0,1,2,1,3,1,4]487[1,3,5]488489indices([1,2])490[0,1,2,3,1,4,2,5,1,2,6,7]491[1,8]492493index(", ")494"a,b, cd, efg, hijk"4953496497rindex(", ")498"a,b, cd, efg, hijk"49912500501inside("foobar")502"bar"503true504505inside(["foobar", "foobaz", "blarp"])506["baz", "bar"]507true508509inside(["foobar", "foobaz", "blarp"])510["bazzzzz", "bar"]511false512513inside({"foo": 12, "bar":[1,2,{"barp":12, "blip":13}]})514{"foo": 12, "bar": [{"barp": 12}]}515true516517inside({"foo": 12, "bar":[1,2,{"barp":12, "blip":13}]})518{"foo": 12, "bar": [{"barp": 15}]}519false520521[.[]|startswith("foo")]522["fo", "foo", "barfoo", "foobar", "barfoob"]523[false, true, false, true, false]524525[.[]|endswith("foo")]526["foobar", "barfoo"]527[false, true]528529combinations530[[1,2], [3, 4]]531[1, 3]532[1, 4]533[2, 3]534[2, 4]535536combinations(2)537[0, 1]538[0, 0]539[0, 1]540[1, 0]541[1, 1]542543[.[]|ltrimstr("foo")]544["fo", "foo", "barfoo", "foobar", "afoo"]545["fo","","barfoo","bar","afoo"]546547[.[]|rtrimstr("foo")]548["fo", "foo", "barfoo", "foobar", "foob"]549["fo","","bar","foobar","foob"]550551explode552"foobar"553[102,111,111,98,97,114]554555implode556[65, 66, 67]557"ABC"558559split(", ")560"a, b,c,d, e, "561["a","b,c,d","e",""]562563join(", ")564["a","b,c,d","e"]565"a, b,c,d, e"566567join(" ")568["a",1,2.3,true,null,false]569"a 1 2.3 true false"570571[while(.<100; .*2)]5721573[1,2,4,8,16,32,64]574575[repeat(.*2, error)?]5761577[2]578579[.,1]|until(.[0] < 1; [.[0] - 1, .[1] * .[0]])|.[1]580458124582583recurse(.foo[])584{"foo":[{"foo": []}, {"foo":[{"foo":[]}]}]}585{"foo":[{"foo":[]},{"foo":[{"foo":[]}]}]}586{"foo":[]}587{"foo":[{"foo":[]}]}588{"foo":[]}589590recurse591{"a":0,"b":[1]}592{"a":0,"b":[1]}5930594[1]5951596597recurse(. * .; . < 20)59825992600460116602603walk(if type == "array" then sort else . end)604[[4, 1, 7], [8, 5, 2], [3, 6, 9]]605[[1,4,7],[2,5,8],[3,6,9]]606607walk( if type == "object" then with_entries( .key |= sub( "^_+"; "") ) else . end )608[ { "_a": { "__b": 2 } } ]609[{"a":{"b":2}}]610611$ENV.PAGER612null613"less"614615env.PAGER616null617"less"618619transpose620[[1], [2,3]]621[[1,2],[null,3]]622623bsearch(0)624[0,1]6250626627bsearch(0)628[1,2,3]629-1630631bsearch(4) as $ix | if $ix < 0 then .[-(1+$ix)] = 4 else . end632[1,2,3]633[1,2,3,4]634635"The input was \(.), which is one less than \(.+1)"63642637"The input was 42, which is one less than 43"638639[.[]|tostring]640[1, "foo", ["foo"]]641["1","foo","[\"foo\"]"]642643[.[]|tojson]644[1, "foo", ["foo"]]645["1","\"foo\"","[\"foo\"]"]646647[.[]|tojson|fromjson]648[1, "foo", ["foo"]]649[1,"foo",["foo"]]650651@html652"This works if x < y"653"This works if x &lt; y"654655@sh "echo \(.)"656"O'Hara's Ale"657"echo 'O'\\''Hara'\\''s Ale'"658659@base64660"This is a message"661"VGhpcyBpcyBhIG1lc3NhZ2U="662663@base64d664"VGhpcyBpcyBhIG1lc3NhZ2U="665"This is a message"666667fromdate668"2015-03-05T23:51:47Z"6691425599507670671strptime("%Y-%m-%dT%H:%M:%SZ")672"2015-03-05T23:51:47Z"673[2015,2,5,23,51,47,4,63]674675strptime("%Y-%m-%dT%H:%M:%SZ")|mktime676"2015-03-05T23:51:47Z"6771425599507678679. == false680null681false682683. == {"b": {"d": (4 + 1e-20), "c": 3}, "a":1}684{"a":1, "b": {"c": 3, "d": 4}}685true686687.[] == 1688[1, 1.0, "1", "banana"]689true690true691false692false693694if . == 0 then "zero" elif . == 1 then "one" else "many" end6952696"many"697698. < 56992700true70170242 and "a string"703null704true705706(true, false) or false707null708true709false710711(true, true) and (true, false)712null713true714false715true716false717718[true, false | not]719null720[false, true]721722.foo // 42723{"foo": 19}72419725726.foo // 42727{}72842729730try .a catch ". is not an object"731true732". is not an object"733734[.[]|try .a]735[{}, true, {"a":1}]736[null, 1]737738try error("some exception") catch .739true740"some exception"741742[.[] | .a?]743[{}, true, {"a":1}]744[null, 1]745746[.[] | tonumber?]747["1", "invalid", "3", 4]748[1, 3, 4]749750test("foo")751"foo"752true753754.[] | test("a b c # spaces are ignored"; "ix")755["xabcd", "ABC"]756true757true758759match("(abc)+"; "g")760"abc abc"761{"offset": 0, "length": 3, "string": "abc", "captures": [{"offset": 0, "length": 3, "string": "abc", "name": null}]}762{"offset": 4, "length": 3, "string": "abc", "captures": [{"offset": 4, "length": 3, "string": "abc", "name": null}]}763764match("foo")765"foo bar foo"766{"offset": 0, "length": 3, "string": "foo", "captures": []}767768match(["foo", "ig"])769"foo bar FOO"770{"offset": 0, "length": 3, "string": "foo", "captures": []}771{"offset": 8, "length": 3, "string": "FOO", "captures": []}772773match("foo (?<bar123>bar)? foo"; "ig")774"foo bar foo foo foo"775{"offset": 0, "length": 11, "string": "foo bar foo", "captures": [{"offset": 4, "length": 3, "string": "bar", "name": "bar123"}]}776{"offset": 12, "length": 8, "string": "foo foo", "captures": [{"offset": -1, "length": 0, "string": null, "name": "bar123"}]}777778[ match("."; "g")] | length779"abc"7803781782capture("(?<a>[a-z]+)-(?<n>[0-9]+)")783"xyzzy-14"784{ "a": "xyzzy", "n": "14" }785786.bar as $x | .foo | . + $x787{"foo":10, "bar":200}788210789790. as $i|[(.*2|. as $i| $i), $i]7915792[10,5]793794. as [$a, $b, {c: $c}] | $a + $b + $c795[2, 3, {"c": 4, "d": 5}]7969797798.[] as [$a, $b] | {a: $a, b: $b}799[[0], [0, 1], [2, 1, 0]]800{"a":0,"b":null}801{"a":0,"b":1}802{"a":2,"b":1}803804.[] as {$a, $b, c: {$d, $e}} ?// {$a, $b, c: [{$d, $e}]} | {$a, $b, $d, $e}805[{"a": 1, "b": 2, "c": {"d": 3, "e": 4}}, {"a": 1, "b": 2, "c": [{"d": 3, "e": 4}]}]806{"a":1,"b":2,"d":3,"e":4}807{"a":1,"b":2,"d":3,"e":4}808809.[] as {$a, $b, c: {$d}} ?// {$a, $b, c: [{$e}]} | {$a, $b, $d, $e}810[{"a": 1, "b": 2, "c": {"d": 3, "e": 4}}, {"a": 1, "b": 2, "c": [{"d": 3, "e": 4}]}]811{"a":1,"b":2,"d":3,"e":null}812{"a":1,"b":2,"d":null,"e":4}813814.[] as [$a] ?// [$b] | if $a != null then error("err: \($a)") else {$a,$b} end815[[3]]816{"a":null,"b":3}817818def addvalue(f): . + [f]; map(addvalue(.[0]))819[[1,2],[10,20]]820[[1,2,1], [10,20,10]]821822def addvalue(f): f as $x | map(. + $x); addvalue(.[0])823[[1,2],[10,20]]824[[1,2,1,2], [10,20,1,2]]825826reduce .[] as $item (0; . + $item)827[10,2,5,3]82820829830isempty(empty)831null832true833834[limit(3;.[])]835[0,1,2,3,4,5,6,7,8,9]836[0,1,2]837838[first(range(.)), last(range(.)), nth(./2; range(.))]83910840[0,9,5]841842[range(.)]|[first, last, nth(5)]84310844[0,9,5]845846[foreach .[] as $item ([[],[]]; if $item == null then [[],.[0]] else [(.[0] + [$item]),[]] end; if $item == null then .[1] else empty end)]847[1,2,3,4,null,"a","b",null]848[[1,2,3,4],["a","b"]]849850def 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)851null8520853385468559856857def while(cond; update): def _while: if cond then ., (update | _while) else empty end; _while; [while(.<100; .*2)]8581859[1,2,4,8,16,32,64]860861[1|truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])]8621863[[[0],2],[[0]]]864865fromstream(1|truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]]))866null867[2]868869. as $dot|fromstream($dot|tostream)|.==$dot870[0,[1,{"a":1},{"b":2}]]871true872873(..|select(type=="boolean")) |= if . then 1 else 0 end874[true,false,[5,true,[true,[false]],false]]875[1,0,[5,1,[1,[0]],0]]876877.foo += 1878{"foo": 42}879{"foo": 43}880881.a = .b882{"a": {"b": 10}, "b": 20}883{"a":20,"b":20}884885.a |= .b886{"a": {"b": 10}, "b": 20}887{"a":10,"b":20}888889(.a, .b) = range(3)890null891{"a":0,"b":0}892{"a":1,"b":1}893{"a":2,"b":2}894895(.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}1119222map(., .)223[1,2]224[1,1,2,2]225
681 unmodified lines
modified:jq.1.prebuilt+1 added-1 removed
965 unmodified lines
966.967.IP "" 0968.969.SS "pick(pathexps)"970Emit the projection of the input object or array defined by the specified sequence of path expressions, such that if p is any one of these specifications, then \fB(\. | p)\fR will evaluate to the same value as \fB(\. | pick(pathexps) | p)\fR\. For arrays, negative indices and \.[m:n] specifications should not be used\.970Emit the projection of the input object or array defined by the specified sequence of path expressions, such that if p is any one of these specifications, then \fB(\. | p)\fR will evaluate to the same value as \fB(\. | pick(pathexps) | p)\fR\. For arrays, negative indices and \.[m:n] specifications should not be used\.971.972.IP "" 4973.974.nf
2811 unmodified lines