# Tests are groups of three lines: program, input, expected output # Blank lines and lines starting with # are ignored # Simple value tests to check parser. Input is irrelevant # The input line starts with a 0xFEFF (byte order mark) codepoint # No, there is no reason to have a byte order mark in UTF8 text. # But apparently people do, so jq shouldn't break on it. # We test escapes by matching them against Unicode codepoints @text,@json,([1,.]|@csv,@tsv),@html,(@uri|.,@urid),@sh,(@base64|.,@base64d) "!()<>&'\"\t" "!()<>&'\"\t" "\"!()<>&'\\\"\\t\"" "1,\"!()<>&'\"\"\t\"" "1\t!()<>&'\"\\t" "!()<>&'"\t" "%21%28%29%3C%3E%26%27%22%09" "!()<>&'\"\t" "'!()<>&'\\''\"\t'" "ISgpPD4mJyIJ" "!()<>&'\"\t" # # Dictionary construction syntax # # # Field access, piping # # # Negative array indices # # # Multiple outputs, iteration # # Check that various builtins evaluate all arguments where appropriate, # doing cartesian products where appropriate. # # Slices # # # Variables # # # Builtin functions # # # User-defined functions # Oh god. # reduce .[] as $x (0; . + $x) [1,2,4] 7 # Check short-circuiting any(true, error; .) "badness" true all(false, error; .) "badness" false # # Paths # # # Assignment # # # Conditionals # # Try/catch and general `?` operator # string operations # Test recursive object merge [.[]|arrays] [1,2,"foo",[],[3,[]],{},true,false,null] [[],[3,[]]] sort [42,[2,5,3,11],10,{"a":42,"b":2},{"a":42},true,2,[2,6],"hello",null,[2,5,6],{"a":[],"b":1},"abc","ab",[3,10],{},false,"abcd",null] [null,null,false,true,2,10,42,"ab","abc","abcd","hello",[2,5,3,11],[2,5,6],[2,6],[3,10],{},{"a":42},{"a":42,"b":2},{"a":[],"b":1}] strftime("%Y-%m-%dT%H:%M:%SZ") [2015,2,5,23,51,47,4,63] "2015-03-05T23:51:47Z" # module system INDEX(range(5)|[., "foo\(.)"]; .[0]) null {"0":[0,"foo0"],"1":[1,"foo1"],"2":[2,"foo2"],"3":[3,"foo3"],"4":[4,"foo4"]} # check that dead code removal occurs after builtin it generation builtins|length > 10 null true # When no arithmetic is involved jq should preserve the literal value # Applying arithmetic to the value will truncate the result to double # Unary negation preserves numerical precision # Using a keyword as variable/label name # nan is parsed as a valid NaN value from JSON # NaN with payload is not parsed # calling input/0, or debug/0 in a test doesn't crash jq # try/catch catches more than it should #1859 # explode/implode # test replacement character (65533) for outside codepoint range and 0xd800 (55296) - 0xdfff (57343) utf16 surrogate pair range # 1.1 and 1.9 to test round down of non-ints walk(.) {"x":0} {"x":0} walk(1) {"x":0} 1 # ltrimstr/1 and rtrimstr/1 return an error for non-strings. #2969 # regression tests for #3413 # upper range bounds should be in sync with the constants defined at # src/jv_parse.c:#define MAX_PARSING_DEPTH (N) # src/jv_print.c:#define MAX_PRINT_DEPTH (N) try setpath([range(10001) | 0]; 0) catch . null "Path too deep" getpath([range(10000) | 0]) null null try getpath([range(10001) | 0]) catch . null "Path too deep" delpaths([[range(10000) | 0]]) null null try delpaths([[range(10001) | 0]]) catch . null "Path too deep" try (reduce range(10001) as $_ ([]; [.]) as $x | $x | contains($x)) catch . null "Containment check too deep" try (reduce range(10001) as $_ ({}; {a: .}) as $x | $x * $x) catch . null "Object merge too deep" # regression test for deep structural equality recursion try ((reduce range(10001) as $_ ([]; [.])) as $x | (reduce range(10001) as $_ ([]; [.])) as $y | $x == $y) catch . null "Equality check too deep" # regression tests for deep ordering comparisons try ((reduce range(10001) as $_ ([]; [.])) as $x | [$x, $x] | sort) catch . null "Comparison too deep"