object-file: convert 'switch' back to 'if'
[git/debian.git] / t / t4026-color.sh
blobcc3f60d468f4c51e7a6149ce8ef014bdf5a5a92b
1 #!/bin/sh
3 # Copyright (c) 2008 Timo Hirvonen
6 test_description='Test diff/status color escape codes'
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 ESC=$(printf '\033')
12 color()
14 actual=$(git config --get-color no.such.slot "$1") &&
15 test "$actual" = "${2:+$ESC}$2"
18 invalid_color()
20 test_must_fail git config --get-color no.such.slot "$1"
23 test_expect_success 'reset' '
24 color "reset" "[m"
27 test_expect_success 'empty color is empty' '
28 color "" ""
31 test_expect_success 'attribute before color name' '
32 color "bold red" "[1;31m"
35 test_expect_success 'aixterm bright fg color' '
36 color "brightred" "[91m"
39 test_expect_success 'aixterm bright bg color' '
40 color "green brightblue" "[32;104m"
43 test_expect_success 'color name before attribute' '
44 color "red bold" "[1;31m"
47 test_expect_success 'attr fg bg' '
48 color "ul blue red" "[4;34;41m"
51 test_expect_success 'fg attr bg' '
52 color "blue ul red" "[4;34;41m"
55 test_expect_success 'fg bg attr' '
56 color "blue red ul" "[4;34;41m"
59 test_expect_success 'fg bg attr...' '
60 color "blue bold dim ul blink reverse" "[1;2;4;5;7;34m"
63 test_expect_success 'reset fg bg attr...' '
64 color "reset blue bold dim ul blink reverse" "[;1;2;4;5;7;34m"
67 # note that nobold and nodim are the same code (22)
68 test_expect_success 'attr negation' '
69 color "nobold nodim noul noblink noreverse" "[22;24;25;27m"
72 test_expect_success '"no-" variant of negation' '
73 color "no-bold no-blink" "[22;25m"
76 test_expect_success 'long color specification' '
77 color "254 255 bold dim ul blink reverse" "[1;2;4;5;7;38;5;254;48;5;255m"
80 test_expect_success 'absurdly long color specification' '
81 color \
82 "#ffffff #ffffff bold nobold dim nodim italic noitalic
83 ul noul blink noblink reverse noreverse strike nostrike" \
84 "[1;2;3;4;5;7;9;22;23;24;25;27;29;38;2;255;255;255;48;2;255;255;255m"
87 test_expect_success '0-7 are aliases for basic ANSI color names' '
88 color "0 7" "[30;47m"
91 test_expect_success '8-15 are aliases for aixterm color names' '
92 color "12 13" "[94;105m"
95 test_expect_success '256 colors' '
96 color "254 bold 255" "[1;38;5;254;48;5;255m"
99 test_expect_success '24-bit colors' '
100 color "#ff00ff black" "[38;2;255;0;255;40m"
103 test_expect_success '"default" foreground' '
104 color "default" "[39m"
107 test_expect_success '"normal default" to clear background' '
108 color "normal default" "[49m"
111 test_expect_success '"default" can be combined with attributes' '
112 color "default default no-reverse bold" "[1;27;39;49m"
115 test_expect_success '"normal" yields no color at all"' '
116 color "normal black" "[40m"
119 test_expect_success '-1 is a synonym for "normal"' '
120 color "-1 black" "[40m"
123 test_expect_success 'color too small' '
124 invalid_color "-2"
127 test_expect_success 'color too big' '
128 invalid_color "256"
131 test_expect_success 'extra character after color number' '
132 invalid_color "3X"
135 test_expect_success 'extra character after color name' '
136 invalid_color "redX"
139 test_expect_success 'extra character after attribute' '
140 invalid_color "dimX"
143 test_expect_success 'unknown color slots are ignored (diff)' '
144 git config color.diff.nosuchslotwilleverbedefined white &&
145 git diff --color
148 test_expect_success 'unknown color slots are ignored (branch)' '
149 git config color.branch.nosuchslotwilleverbedefined white &&
150 git branch -a
153 test_expect_success 'unknown color slots are ignored (status)' '
154 git config color.status.nosuchslotwilleverbedefined white &&
155 { git status; ret=$?; } &&
156 case $ret in 0|1) : ok ;; *) false ;; esac
159 test_done