Skip to content

Commit

Permalink
Fix --indent 0 implicitly enabling compact-output (#3232)
Browse files Browse the repository at this point in the history
Now it will retain pretty-printing, just remove any indentation.

Co-authored-by: Andrew Marshall <[email protected]>
Co-authored-by: Gabriel Marin <[email protected]>
  • Loading branch information
3 people authored Feb 1, 2025
1 parent 07af9c1 commit d0adcbf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/jv.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ enum jv_print_flags {
JV_PRINT_SPACE2 = 1024,
};
#define JV_PRINT_INDENT_FLAGS(n) \
((n) < 0 || (n) > 7 ? JV_PRINT_TAB | JV_PRINT_PRETTY : (n) == 0 ? 0 : (n) << 8 | JV_PRINT_PRETTY)
((n) < 0 || (n) > 7 ? JV_PRINT_TAB | JV_PRINT_PRETTY : (n) << 8 | JV_PRINT_PRETTY)
void jv_dumpf(jv, FILE *f, int flags);
void jv_dump(jv, int flags);
void jv_show(jv, int flags);
Expand Down
29 changes: 29 additions & 0 deletions tests/shtest
Original file line number Diff line number Diff line change
Expand Up @@ -665,4 +665,33 @@ $VALGRIND $Q $JQ . <<\NUM
-10E-1000000001
NUM

# test for --indent and --compact-output -- #1465
printf '[1,2]\n' > $d/expected
$JQ --compact-output -n "[1,2]" > $d/out
cmp $d/out $d/expected

printf '[\n1,\n2\n]\n' > $d/expected
$JQ --indent 0 -n "[1,2]" > $d/out
cmp $d/out $d/expected

printf '[\n 1,\n 2\n]\n' > $d/expected
$JQ --indent 1 -n "[1,2]" > $d/out
cmp $d/out $d/expected

printf '[\n 1,\n 2\n]\n' > $d/expected
$JQ --indent 5 -n "[1,2]" > $d/out
cmp $d/out $d/expected

printf '[\n{\n"a": 1\n}\n]\n' > $d/expected
$JQ --indent 0 -n "[{a:1}]" > $d/out
cmp $d/out $d/expected

printf '[\n {\n "a": 1\n }\n]\n' > $d/expected
$JQ --indent 1 -n "[{a:1}]" > $d/out
cmp $d/out $d/expected

printf '[\n {\n "a": 1\n }\n]\n' > $d/expected
$JQ --indent 6 -n "[{a:1}]" > $d/out
cmp $d/out $d/expected

exit 0

0 comments on commit d0adcbf

Please sign in to comment.