Raw
1 #!/bin/sh
2 #
3 # Copyright (c) 2008 Timo Hirvonen
4 #
5
6 test_description='Test diff/status color escape codes'
7
8 . ./test-lib.sh
9
10 ESC=$(printf '\033')
11 color()
12 {
13 actual=$(git config --get-color no.such.slot "$1") &&
14 test "$actual" = "${2:+$ESC}$2"
15 }
16
17 invalid_color()
18 {
19 test_must_fail git config --get-color no.such.slot "$1"
20 }
21
22 test_expect_success 'reset' '
23 color "reset" "[m"
24 '
25
26 test_expect_success 'empty color is empty' '
27 color "" ""
28 '
29
30 test_expect_success 'attribute before color name' '
31 color "bold red" "[1;31m"
32 '
33
34 test_expect_success 'aixterm bright fg color' '
35 color "brightred" "[91m"
36 '
37
38 test_expect_success 'aixterm bright bg color' '
39 color "green brightblue" "[32;104m"
40 '
41
42 test_expect_success 'color name before attribute' '
43 color "red bold" "[1;31m"
44 '
45
46 test_expect_success 'attr fg bg' '
47 color "ul blue red" "[4;34;41m"
48 '
49
50 test_expect_success 'fg attr bg' '
51 color "blue ul red" "[4;34;41m"
52 '
53
54 test_expect_success 'fg bg attr' '
55 color "blue red ul" "[4;34;41m"
56 '
57
58 test_expect_success 'fg bg attr...' '
59 color "blue bold dim ul blink reverse" "[1;2;4;5;7;34m"
60 '
61
62 test_expect_success 'reset fg bg attr...' '
63 color "reset blue bold dim ul blink reverse" "[;1;2;4;5;7;34m"
64 '
65
66 # note that nobold and nodim are the same code (22)
67 test_expect_success 'attr negation' '
68 color "nobold nodim noul noblink noreverse" "[22;24;25;27m"
69 '
70
71 test_expect_success '"no-" variant of negation' '
72 color "no-bold no-blink" "[22;25m"
73 '
74
75 test_expect_success 'long color specification' '
76 color "254 255 bold dim ul blink reverse" "[1;2;4;5;7;38;5;254;48;5;255m"
77 '
78
79 test_expect_success 'absurdly long color specification' '
80 color \
81 "#ffffff #ffffff bold nobold dim nodim italic noitalic
82 ul noul blink noblink reverse noreverse strike nostrike" \
83 "[1;2;3;4;5;7;9;22;23;24;25;27;29;38;2;255;255;255;48;2;255;255;255m"
84 '
85
86 test_expect_success '0-7 are aliases for basic ANSI color names' '
87 color "0 7" "[30;47m"
88 '
89
90 test_expect_success '8-15 are aliases for aixterm color names' '
91 color "12 13" "[94;105m"
92 '
93
94 test_expect_success '256 colors' '
95 color "254 bold 255" "[1;38;5;254;48;5;255m"
96 '
97
98 test_expect_success 'RGB colors' '
99 color "#ff00ff #0f0" "[38;2;255;0;255;48;2;0;255;0m"
100 '
101
102 test_expect_success '"default" foreground' '
103 color "default" "[39m"
104 '
105
106 test_expect_success '"normal default" to clear background' '
107 color "normal default" "[49m"
108 '
109
110 test_expect_success '"default" can be combined with attributes' '
111 color "default default no-reverse bold" "[1;27;39;49m"
112 '
113
114 test_expect_success '"normal" yields no color at all' '
115 color "normal black" "[40m"
116 '
117
118 test_expect_success '-1 is a synonym for "normal"' '
119 color "-1 black" "[40m"
120 '
121
122 test_expect_success 'color too small' '
123 invalid_color "-2"
124 '
125
126 test_expect_success 'color too big' '
127 invalid_color "256"
128 '
129
130 test_expect_success 'extra character after color number' '
131 invalid_color "3X"
132 '
133
134 test_expect_success 'extra character after color name' '
135 invalid_color "redX"
136 '
137
138 test_expect_success 'extra character after attribute' '
139 invalid_color "dimX"
140 '
141
142 test_expect_success 'non-hex character in RGB color' '
143 invalid_color "#x23456" &&
144 invalid_color "#1x3456" &&
145 invalid_color "#12x456" &&
146 invalid_color "#123x56" &&
147 invalid_color "#1234x6" &&
148 invalid_color "#12345x" &&
149 invalid_color "#x23" &&
150 invalid_color "#1x3" &&
151 invalid_color "#12x"
152 '
153
154 test_expect_success 'wrong number of letters in RGB color' '
155 invalid_color "#1" &&
156 invalid_color "#23" &&
157 invalid_color "#789a" &&
158 invalid_color "#bcdef" &&
159 invalid_color "#1234567"
160 '
161
162 test_expect_success 'unknown color slots are ignored (diff)' '
163 git config color.diff.nosuchslotwilleverbedefined white &&
164 git diff --color
165 '
166
167 test_expect_success 'unknown color slots are ignored (branch)' '
168 git config color.branch.nosuchslotwilleverbedefined white &&
169 git branch -a
170 '
171
172 test_expect_success 'unknown color slots are ignored (status)' '
173 git config color.status.nosuchslotwilleverbedefined white &&
174 { git status; ret=$?; } &&
175 case $ret in 0|1) : ok ;; *) false ;; esac
176 '
177
178 test_done