diff options
author | Emanuele Torre <torreemanuele6@gmail.com> | 2023-11-03 19:53:33 +0100 |
---|---|---|
committer | Nico Williams <nico@cryptonector.com> | 2023-11-03 15:52:02 -0500 |
commit | cca1f7d18f2fa6721952645821ae429a0166d7e4 (patch) | |
tree | 85b685c0aaba0eeacdecda274cb76b617350713e /tests | |
parent | f4929f3c19fc8486aac66ab0378fb3995adb3b6d (diff) |
Comment bug fixes, and fully support Tcl-style multiline comments
* bugfix: comments were incorrectly being terminated by CR; for example
jq -n $'1 #foo\r'
fails to compile because the CR character terminates the comment, and
CR is not a valid character in jq syntax.
* improvement: comments fully support Tcl-style line continuation.
Previously this was only "supported" in `-f' scripts, whose first line
starts with "#!", and second line starts with # and ends with \, only
for the comment on the second line, only for one extra line.
* man: document comment syntax, which was previously undocumented.
* tests: add regression tests for the bugfix, and some tests for line
continuation in comments.
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/shtest | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/shtest b/tests/shtest index 11125478..dd007d15 100755 --- a/tests/shtest +++ b/tests/shtest @@ -579,6 +579,36 @@ if ( ! $msys && ! $mingw ) && locale -a > /dev/null; then fi fi +# Comments! +if ! x=$($JQ -n '123 # comment') || [ "$x" != 123 ]; then + echo 'comment did not work' + exit 1 +fi + +cr=$(printf \\r) +if ! x=$($JQ -n "1 # foo$cr + 2") || [ "$x" != 1 ]; then + echo 'regression: carriage return terminates comment' + exit 1 +fi + +if ! x=$($JQ -cn '[ + 1, + # foo \ + 2, + # bar \\ + 3, + 4, # baz \\\ + 5, \ + 6, + 7 + # comment \ + comment \ + comment +]') || [ "$x" != '[1,3,4,7]' ]; then + echo 'multiline comment was not handled correctly' + exit 1 +fi + # Allow passing the inline jq script before -- #2919 if ! r=$($JQ --args -rn -- '$ARGS.positional[0]' bar) || [ "$r" != bar ]; then echo "passing the inline script after -- didn't work" |