0 }, { "foo": 1 }, "bar" ] - name: yaml input option with hyphen for stdin args: - --yaml-input - '.' - '-' input: | foo: 1 expected: | { "foo": 1 } - name: yaml input option error args: - --yaml-input - '.' input: | foo: 10 10 bar: error: | invalid yaml: :2 2 | 10 ^ could not find expected ':' - name: yaml input option multiple errors args: - --yaml-input - '.' input: | foo: 1 bar: 2 foo: 3 error: | invalid yaml: :3 3 | foo: 3 ^ mapping key "foo" already defined at line 1 - name: yaml file input error args: - --yaml-input - '.' - 'testdata/2.yaml' error: | invalid yaml: testdata/2.yaml:5 5 | a: b: c ^ mapping values are not allowed in this context - name: yaml file input error in dos format args: - --yaml-input - '.' - 'testdata/3.yaml' error: | invalid yaml: testdata/3.yaml:5 5 | a: b: c ^ mapping values are not allowed in this context - name: yaml file input error in mac format args: - --yaml-input - '.' - 'testdata/4.yaml' error: | invalid yaml: testdata/4.yaml:5 5 | a: b: c ^ mapping values are not allowed in this context - name: yaml output option args: - --yaml-output - '.' input: '{"foo": 128, "bar": {"baz": [1,"qux", []]}}' expected: | bar: baz: - 1 - qux - [] foo: 128 - name: yaml output option with multiple values args: - --yaml-output - '..' input: '{"foo": 128, "bar": [1,2,"foo"]}' expected: | bar: - 1 - 2 - foo foo: 128 --- - 1 - 2 - foo --- 1 --- 2 --- foo --- 128 - name: yaml input and output option args: - --yaml-input - --yaml-output - '.' input: | foo: 42 --- foo: bar: 42 baz: | a b qux: 100 --- foo: 1 --- bar expected: | foo: 42 --- foo: bar: 42 baz: | a b qux: 100 --- foo: 1 --- bar - name: yaml output with indent option args: - --yaml-output - --indent - '8' - '.' input: '{ "foo": { "baz": ["hello", "world"] } }' expected: | foo: baz: - hello - world - name: yaml output with indent option error args: - --yaml-output - --indent - '10' - '.' input: '{ "foo": { "baz": ["hello", "world"] } }' error: | too many indentation count: 10 - name: yaml output with tab option error args: - --yaml-output - --tab - '.' input: '{"foo": 128, "bar": {"baz": [1,"qux", []]}}' error: | cannot use tabs for YAML output - name: source query from file args: - -f - testdata/1.jq input: '{"foo":{"bar":42}}' expected: | 42 - name: source query from file short option in clumped options args: - -cfr - testdata/1.jq input: '{"foo":{"bar":42}}' expected: | 42 - name: source query from file long option args: - --from-file - testdata/1.jq input: '{"foo":{"bar":42}}' expected: | 42 - name: source query from file with --args args: - --args - --compact-output - --null-input - --from-file - testdata/14.jq - 1 - 2 - 3 expected: | {"named":{},"positional":["1","2","3"]} - name: invalid query args: - '>abc' input: '{}' error: | invalid query: >abc >abc ^ unexpected token ">" exit_code: 3 - name: invalid query args: - '.abc[' input: '{}' error: | invalid query: .abc[ .abc[ ^ unexpected EOF exit_code: 3 - name: invalid query args: - '[ .[] | { .id } ]' input: '{}' error: | invalid query: [ .[] | { .id } ] [ .[] | { .id } ] ^ unexpected token ".id" exit_code: 3 - name: invalid query args: - 'if 0then. else. end' input: '{}' error: | invalid query: if 0then. else. end if 0then. else. end ^ invalid token "0t" exit_code: 3 - name: invalid query args: - '.foo & .bar' input: '{}' error: | invalid query: .foo & .bar .foo & .bar ^ unexpected token "&" exit_code: 3 - name: invalid query args: - 'foo☆' input: '{}' error: | invalid query: foo☆ foo☆ ^ unexpected token "☆" exit_code: 3 - name: invalid query args: - "\\/" input: '{}' error: | invalid query: \/ \/ ^ unexpected token "\\" exit_code: 3 - name: invalid query args: - "{\n[]}" input: '{}' error: | invalid query: :2 2 | []} ^ unexpected token "[" exit_code: 3 - name: invalid multiple line query args: - | [ .[] | { id } } ] input: '{}' error: | invalid query: :3 3 | | { id } } ^ unexpected token "}" exit_code: 3 - name: invalid multiple line query in file args: - -f - testdata/10.jq error: | invalid query: testdata/10.jq:5 5 | bar ] ^ unexpected token "]" exit_code: 3 - name: invalid multiple line query in dos format args: - -f - testdata/11.jq error: | invalid query: testdata/11.jq:5 5 | bar ] ^ unexpected token "]" exit_code: 3 - name: invalid multiple line query in mac format args: - -f - testdata/12.jq error: | invalid query: testdata/12.jq:5 5 | bar ] ^ unexpected token "]" exit_code: 3 - name: invalid query in file args: - -f - testdata/2.jq error: | invalid query: testdata/2.jq:3 3 | bar, [] ^ unexpected token "[" exit_code: 3 - name: query file not found args: - -f - testdata/3.jq error: 'open testdata/3.jq:' - name: query file not specified args: - -f error: | expected a query file for flag `-f' - name: invalid json unexpected eof error input: '{' error: | invalid json: { ^ unexpected EOF - name: invalid json unexpected eof error with multibyte characters input: '{ "12345":' error: | invalid json: { "12345": ^ unexpected EOF - name: invalid json unexpected eof error with multiple lines input: | [0 ,[ error: | invalid json: :2 2 | ,[ ^ unexpected EOF - name: invalid json invalid character with multibyte characters input: | { "12345" 100 } error: | invalid json: :2 2 | "12345" 100 ^ invalid character '1' after object key - name: invalid json string literal input: | { "123": n } error: | invalid json: :2 2 | "123": n ^ invalid character '\n' in literal null (expecting 'u') - name: multiple json in input input: '{}[]{"foo":10}{"bar":[]}' expected: | {} [] { "foo": 10 } { "bar": [] } - name: hyphen for stdin args: - '.' - '-' input: '{}' expected: | {} - name: json file arguments args: - '.' - 'testdata/1.json' - 'testdata/2.json' expected: | { "foo": 10 } [ { "bar": [] } ] - name: json file error json args: - '.' - 'testdata/3.json' error: | invalid json: testdata/3.json { ^ unexpected EOF - name: json file error json args: - '.' - 'testdata/4.json' error: | invalid json: testdata/4.json:3 3 | bar ^ invalid character 'b' looking for beginning of value - name: json file error json args: - '.' - 'testdata/8.json' error: | invalid json: testdata/8.json [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, , 1, 1, 1, 1, 1, 1, 1 ^ invalid character ',' looking for beginning of value - name: json file error json args: - '.' - 'testdata/9.json' error: | invalid json: testdata/9.json:3 3 | 0", "0", "0", "0", "0", "0", "0", , "0", "0"] ^ invalid character ',' looking for beginning of value - name: json file error json with multibyte character in the error line args: - '.' - 'testdata/5.json' error: | # file contents is read by inputReader so the entire error line is shown unlike the following input json test invalid json: testdata/5.json:3 3 | "abcde": :★★★★★★★★★★★★★★★ ^ invalid character ':' looking for beginning of value - name: json input error json with multibyte character in the error line args: - '.' input: | { "a": "This is a test for multibyte character in the error line of JSON. Since the first buffer size of JSON decoder is 512 (see encoding/json/stream.go) and the decoder stops reading bytes on encountering an error, the error line can be an invalid UTF-8 string even if the complete input is a valid UTF-8 string. Note that the error happens before 512 bytes and the corresponding line continues beyond 512 bytes with a multibyte character at the boundary.", "abcde": :★★★★★★★★★★★★★★★ error: | invalid json: :3 3 | "abcde": :★★★★★★★★★★★★ ^ invalid character ':' looking for beginning of value - name: json file not found error args: - '.' - 'testdata/1.json' - 'testdata/6.json' - 'testdata/2.json' expected: | { "foo": 10 } [ { "bar": [] } ] error: 'open testdata/6.json:' - name: module directory option args: - -c - -L - 'testdata' - 'include "4"; 1 | f | g' input: '0' expected: | {"foo":[1,2,3,4,[1,2,{"foo":42}]]} - name: module directory option args: - -c - -L - 'testdata' - 'import "4" as m1; 1 | m1::f | m1::g' input: '0' expected: | {"foo":[1,2,3,4,[1,2,{"foo":42}]]} - name: module directory option args: - -c - -L - 'testdata' - 'include "m1"; include "m3"; [f, g]' input: '0' expected: | [42,43,44,45] - name: module directory option args: - -c - --library-path - 'testdata' - 'import "7" as $foo; $foo, $foo::foo' input: '0' expected: | [1,2,{"foo":42}] [1,2,{"foo":42}] - name: module directory option args: - -c - --library-path - 'testdata' - 'import "m1" as $x; $x, $x::x, $x[1].m1*100000000000000000000' input: '0' expected: | [42,{"m1":42}] [42,{"m1":42}] 4200000000000000000000 - name: module directory option with argjson args: - -c - -L - 'testdata' - --argjson - 'x' - '{}' - 'import "m1" as $x; $x' input: '0' expected: | [42,{"m1":42}] - name: module directory option parse error args: - 'include "m"; f' input: '0' error: 'compile error: module not found: "m"' exit_code: 3 - name: module directory option function error args: - -L - 'testdata' - 'include "5"; i' input: '0' error: | function not defined: i/0 exit_code: 3 - name: module directory option variable error args: - -L - 'testdata' - 'include "4"; $x' input: '0' error: 'compile error: variable not defined: $x' exit_code: 3 - name: module directory option variable name conflict args: - -c - -L - 'testdata' - 'include "6"; include "13"; . as $x | $x, g, h' input: '1' expected: | 1 [1,2,{"foo":42}] [[{"foo":10}],[1,2,{"foo":42}]] - name: module directory option json parse error args: - -Ltestdata - 'import "4" as $x; $x' input: '0' error: | compile error: invalid json: testdata/4.json:3 3 | bar ^ invalid character 'b' looking for beginning of value exit_code: 3 - name: module directory option with same alias name args: - -c - -L=testdata - 'include "4"; import "6" as bar; bar::g' input: '1' expected: | [1,2,{"foo":42}] - name: module directory option without argument args: - -c - -L input: '0' error: | expected argument for flag `-L' exit_code: 2 - name: search directory in query args: - 'include "m2" { search: "testdata/m2" }; g' input: '0' expected: | 0 43 44 - name: empty module args: - -L - 'testdata' - 'include "8"; .' input: '0' expected: | 0 - name: invalid query in a module args: - -L - 'testdata' - 'include "7"; .' input: '0' error: | invalid query: testdata/7.jq:1 1 | def f: 1 + ^ unexpected EOF exit_code: 3 - name: module directive args: - -c - -L - 'testdata' - 'include "9"; f(2)' input: '3' expected: | 6 - name: module in query args: - -n - 'module {}; .' expected: | null - name: modulemeta function args: - -c - -L - 'testdata' - 'tostring | modulemeta | .defs |= sort' input: '4 5 6 8 9' expected: | {"defs":["f/0","g/0"],"deps":[{"is_data":false,"relpath":"5"},{"as":"bar","is_data":false,"relpath":"6"}]} {"defs":["h/0"],"deps":[{"as":"foo","is_data":false,"relpath":"6","test":"foo"}]} {"defs":["g/0","i/0"],"deps":[{"as":"x","is_data":true,"relpath":"7"}]} {"defs":[],"deps":[]} {"defs":["f/1"],"deps":[],"description":"This is a description","name":"sample-module","x":[[],{},{"y":10,"z":20}],"y":{"z":[128,"",false,true,null,[[]]]}} - name: modulemeta function error args: - -c - -L - 'testdata' - '"3" | modulemeta' input: '0' error: | module not found: "3" - name: arg option args: - --arg - 'foo' - 'value 1' - --arg - 'bar' - '42' - '{ $foo, $bar }' input: '123' expected: | { "bar": "42", "foo": "value 1" } - name: arg option with function declaration args: - -n - --arg - 'foo' - 'bar' - 'def f: $foo; "baz" as $foo | ., f, $foo' expected: | null "bar" "baz" - name: arg option arguments count error args: - --arg error: | expected 2 arguments for flag `--arg' exit_code: 2 - name: arg option arguments count error args: - --arg - 'foo' error: | expected 2 arguments for flag `--arg' exit_code: 2 - name: arg option variable name error args: - --arg - 'f.oo' - '10' - '.' error: | invalid variable name: $f.oo exit_code: 3 - name: argjson option args: - --argjson - 'foo' - '{ "foo": 42 }' - --argjson - 'bar' - '10' - '{ $foo, $bar }' input: '123' expected: | { "bar": 10, "foo": { "foo": 42 } } - name: argjson option with big integer args: - --argjson - 'foo' - '10000000000000000000000000000000' - '$foo * 2' input: '0' expected: | 20000000000000000000000000000000 - name: arg and argjson options args: - --arg - 'x' - '1' - --argjson - 'x' - '1' - --argjson - 'y' - '2' - --arg - 'y' - '2' - '{ $x, $y }' input: '0' expected: | { "x": "1", "y": 2 } - name: argjson option error args: - --argjson - '0x' - '0' - '.' error: | invalid variable name: $0x exit_code: 3 - name: argjson option parse error args: - --argjson - 'foo' - '{ foo }' - '.' error: | invalid json: $foo { foo } ^ invalid character 'f' looking for beginning of object key string - name: slurpfile option args: - --slurpfile - 'foo' - 'testdata/7.json' - '{ $foo }' input: 'null' expected: | { "foo": [ 1, 2, { "foo": 42 } ] } - name: slurpfile option invalid json error args: - --slurpfile - 'foo' - 'testdata/1.jq' - '{ $foo }' input: 'null' error: | invalid json: testdata/1.jq .foo.bar ^ invalid character '.' looking for beginning of value - name: slurpfile option invalid file error args: - --slurpfile - 'foo' - '-' - '{ $foo }' input: 'null' error: 'open -:' - name: rawfile option args: - --rawfile - 'foo' - 'testdata/7.json' - '{ $foo }' input: 'null' expected: | { "foo": "1\n2\n{ \"foo\": 42 }\n" } - name: rawfile option error args: - --rawfile - 'foo' - 'testdata/6.json' - '{ $foo }' input: 'null' error: 'open testdata/6.json:' - name: $ARGS variable args: - --arg - 'a' - '1' - --argjson - 'b' - '1' - --slurpfile - 'c' - 'testdata/1.json' - --rawfile - 'd' - 'testdata/1.json' - '$ARGS | ., .named.a' input: 'null' expected: | { "named": { "a": "1", "b": 1, "c": [ { "foo": 10 } ], "d": "{\"foo\":10}\n" }, "positional": [] } "1" - name: $ARGS variable with args option args: - --arg - 'foo' - 'value' - '$ARGS | ., .positional[]' - --args - '1' - '"bar"' - '{"x":1}' input: '0' expected: | { "named": { "foo": "value" }, "positional": [ "1", "\"bar\"", "{\"x\":1}" ] } "1" "\"bar\"" "{\"x\":1}" - name: args option without argument args: - '$ARGS' - --args input: '0' expected: | { "named": {}, "positional": [] } - name: query and options after args option args: - --args - '$ARGS' - 1 - -n - 2 - -c - -- - 3 - -- - -c input: '0' expected: | {"named":{},"positional":["1","2","3","--","-c"]} - name: double dash with args option args: - --args - -- - 1 - 2 - 3 input: '0' expected: | 0 - name: $ARGS variable with jsonargs option args: - '$ARGS | ., .positional[]' - --arg - 'foo' - 'value' - --jsonargs - '1' - '"bar"' - '{"x":1}' input: '0' expected: | { "named": { "foo": "value" }, "positional": [ 1, "bar", { "x": 1 } ] } 1 "bar" { "x": 1 } - name: jsonargs option without argument args: - '$ARGS' - --jsonargs input: '0' expected: | { "named": {}, "positional": [] } - name: jsonargs option parse error args: - '$ARGS' - --jsonargs - '1' - '"bar"' - '{"x":}' input: '0' error: | invalid json: --jsonargs {"x":} ^ invalid character '}' looking for beginning of value - name: args with jsonargs option args: - -c - '$ARGS' - --args - 1 - 2 - --jsonargs - 1 - 2 - --args - 1 - 2 input: '0' expected: | {"named":{},"positional":["1","2",1,2,"1","2"]} - name: args with jsonargs option args: - -c - '$ARGS' - --args - 1 - 2 - --jsonargs - 1 - 2 - --args - 1 - 2 - --jsonargs - 1 - 2 input: '0' expected: | {"named":{},"positional":["1","2",1,2,"1","2",1,2]} - name: exit status option with null result args: - -e - '.' input: 'null' expected: | null exit_code: 1 - name: exit status option with empty function args: - -e - 'empty' input: 'null' exit_code: 4 - name: exit status long option with false result args: - --exit-status - '.' input: 'false' expected: | false exit_code: 1 - name: exit status long option with true result args: - --exit-status - 'not' input: 'false' expected: | true - name: exit status long option with multiple results args: - --exit-status - '1,not,2' input: 'false' expected: | 1 true 2 - name: exit status long option with error function args: - --exit-status - 'error' input: 'false' error: | error: false exit_code: 5 - name: exit status long option with error function args: - --exit-status - 'error' input: 'null' error: | error: null - name: exit status long option with halt function args: - --exit-status - 'halt' input: 'false' exit_code: 0 - name: exit status long option with halt_error function args: - --exit-status - 'halt_error(0)' input: 'null' exit_code: 0 - name: exit status long option with halt_error function args: - --exit-status - 'halt_error(42)' input: 'null' exit_code: 42 - name: query with leading hyphen args: - '-.' input: '1' expected: | -1 - name: query with leading hyphen args: - '-j0' input: '0 1 2' expected: | -1 -0.7651976865579666 -0.22389077914123567 - name: query with leading hyphen after a flag args: - -r - '-.' input: '1' expected: | -1 - name: double dash args: - '--' - '.' input: '1' expected: | 1 - name: double dash with query with leading hyphen args: - '--' - '-j' input: 'null' error: | compile error: function not defined: j/0 exit_code: 3 - name: double double dash args: - '--' - '--' - '.' input: '1' error: | invalid query: -- -- ^ unexpected EOF exit_code: 3 - name: short clumped options args: - -cRr - '.' input: 'foo' expected: | foo - name: invalid short option error args: - -q - '.' error: | unknown flag `q' exit_code: 2 - name: invalid short option error in clumped options args: - -nqe - '.' error: | unknown flag `q' exit_code: 2 - name: invalid long option error args: - --qqq - '.' error: | unknown flag `--qqq' exit_code: 2