Skip to content
Myr

Fix `--indent 0` implicitly enabling compact-output (#3232)

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

Now it will retain pretty-printing, just remove any indentation.

authored by itchyny · committed by GitHub · parent 07af9c1 · Browse files · 2 files+30 added−1 removed
This commit

State

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

Trailers

  • Co-authored-by: Andrew Marshall <andrew@johnandrewmarshall.com>
  • Co-authored-by: Gabriel Marin <marin.gabriel@protonmail.com>

Diff stats

2 files+30 added−1 removed

  • tests:+29 added−0 removed
  • other:+1 added−1 removed

2 files+30 added−1 removed

modified:src/jv.h+1 added-1 removed
224 unmodified lines
225 JV_PRINT_SPACE1 = 512,226 JV_PRINT_SPACE2 = 1024,227};228#define JV_PRINT_INDENT_FLAGS(n) \229 ((n) < 0 || (n) > 7 ? JV_PRINT_TAB | JV_PRINT_PRETTY : (n) == 0 ? 0 : (n) << 8 | JV_PRINT_PRETTY)229 ((n) < 0 || (n) > 7 ? JV_PRINT_TAB | JV_PRINT_PRETTY : (n) << 8 | JV_PRINT_PRETTY)230void jv_dumpf(jv, FILE *f, int flags);231void jv_dump(jv, int flags);232void jv_show(jv, int flags);233jv jv_dump_string(jv, int flags);
63 unmodified lines
modified:tests/shtest+29 added
663 unmodified lines
664$VALGRIND $Q $JQ . <<\NUM665-10E-1000000001666NUM667668# test for --indent and --compact-output -- #1465669printf '[1,2]\n' > $d/expected670$JQ --compact-output -n "[1,2]" > $d/out671cmp $d/out $d/expected672673printf '[\n1,\n2\n]\n' > $d/expected674$JQ --indent 0 -n "[1,2]" > $d/out675cmp $d/out $d/expected676677printf '[\n 1,\n 2\n]\n' > $d/expected678$JQ --indent 1 -n "[1,2]" > $d/out679cmp $d/out $d/expected680681printf '[\n 1,\n 2\n]\n' > $d/expected682$JQ --indent 5 -n "[1,2]" > $d/out683cmp $d/out $d/expected684685printf '[\n{\n"a": 1\n}\n]\n' > $d/expected686$JQ --indent 0 -n "[{a:1}]" > $d/out687cmp $d/out $d/expected688689printf '[\n {\n "a": 1\n }\n]\n' > $d/expected690$JQ --indent 1 -n "[{a:1}]" > $d/out691cmp $d/out $d/expected692693printf '[\n {\n "a": 1\n }\n]\n' > $d/expected694$JQ --indent 6 -n "[{a:1}]" > $d/out695cmp $d/out $d/expected696697exit 0