Skip to content
Myr

Add more test cases for JQ_COLORS support (ref #3288)

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

authored by itchyny · committed by itchyny · parent aa977aa · Browse files · 1 file+57 added−6 removed
This commit

State

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

Diff stats

1 file+57 added−6 removed

  • tests:+57 added−6 removed

1 file+57 added−6 removed

modified:tests/shtest+57 added-6 removed
500 unmodified lines
501 printf '\033[1;35m]\033[0m\n'502} > $d/expect503cmp $d/color $d/expect504505## Set non-default colors only for literals, complex input506JQ_COLORS='0;37:0;31:0;35:0;34:0;36' \507 $JQ -Ccn '[{"a":true,"b":false},"abc",123,null]' > $d/color508{509 printf '\033[1;39m[\033[0m'510 printf '\033[1;39m{\033[0m'511 printf '\033[1;34m"a"\033[0m'512 printf '\033[1;39m:\033[0m'513 printf '\033[0;35mtrue\033[0m'514 printf '\033[1;39m,\033[0m'515 printf '\033[1;34m"b"\033[0m'516 printf '\033[1;39m:\033[0m'517 printf '\033[0;31mfalse\033[0m'518 printf '\033[1;39m}\033[0m'519 printf '\033[1;39m,\033[0m'520 printf '\033[0;36m"abc"\033[0m'521 printf '\033[1;39m,\033[0m'522 printf '\033[0;34m123\033[0m'523 printf '\033[1;39m,\033[0m'524 printf '\033[0;37mnull\033[0m'525 printf '\033[1;39m]\033[0m\n'526} > $d/expect527cmp $d/color $d/expect528529## Default colors, complex input, indented530$JQ -Cn '[{"a":true,"b":false},"abc",123,null]' > $d/color531{532 printf '\033[1;39m[\033[0m\n'
39 unmodified lines
572 printf '\033[1;35m]\033[0m\n'573} > $d/expect574cmp $d/color $d/expect575552# Check garbage in JQ_COLORS. These emit a warning on stderr.553set -vx576## Set truecolor, complex input, indented577JQ_COLORS=$(printf '38;2;%s:' \578 '255;173;173' '255;214;165' '253;255;182' '202;255;191' \579 '155;246;255' '160;196;255' '189;178;255' '255;198;255') \580 $JQ -Cn '[{"a":true,"b":false},"abc",123,null]' > $d/color581{582 printf '\033[38;2;160;196;255m[\033[0m\n'583 printf ' \033[38;2;189;178;255m{\033[0m\n'584 printf ' \033[38;2;255;198;255m"a"\033[0m'585 printf '\033[38;2;189;178;255m:\033[0m '586 printf '\033[38;2;253;255;182mtrue\033[0m'587 printf '\033[38;2;189;178;255m,\033[0m\n'588 printf ' \033[38;2;255;198;255m"b"\033[0m'589 printf '\033[38;2;189;178;255m:\033[0m '590 printf '\033[38;2;255;214;165mfalse\033[0m\n'591 printf ' \033[38;2;189;178;255m}\033[0m'592 printf '\033[38;2;160;196;255m,\033[0m\n'593 printf ' \033[38;2;155;246;255m"abc"\033[0m'594 printf '\033[38;2;160;196;255m,\033[0m\n'595 printf ' \033[38;2;202;255;191m123\033[0m'596 printf '\033[38;2;160;196;255m,\033[0m\n'597 printf ' \033[38;2;255;173;173mnull\033[0m\n'598 printf '\033[38;2;160;196;255m]\033[0m\n'599} > $d/expect600cmp $d/color $d/expect601602# Check invalid JQ_COLORS603echo 'Failed to set $JQ_COLORS' > $d/expect_warning604$JQ -Ccn '[{"a":true,"b":false},"abc",123,null]' > $d/expect605for colors in '/' '[30' '30m' '30:31m:32' '30:*:31' 'invalid'; do556JQ_COLORS='garbage;30:*;31:,;3^:0;$%:0;34:1;35:1;36' \557 $JQ -Ccn '[{"a":true,"b":false},"abc",123,null]' > $d/color 2>$d/warning558cmp $d/color $d/expect559cmp $d/warning $d/expect_warning606 JQ_COLORS=$colors \607 $JQ -Ccn '[{"a":true,"b":false},"abc",123,null]' > $d/color 2>$d/warning608 cmp $d/color $d/expect609 cmp $d/warning $d/expect_warning610done611612# Check $NO_COLOR613test_no_color=true614$msys && test_no_color=false
217 unmodified lines