]>
Commit | Line | Data |
---|---|---|
a0cf49c1 TH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2008 Timo Hirvonen | |
4 | # | |
5 | ||
6 | test_description='Test diff/status color escape codes' | |
7 | . ./test-lib.sh | |
8 | ||
9 | color() | |
10 | { | |
8b124135 JH |
11 | actual=$(git config --get-color no.such.slot "$1") && |
12 | test "$actual" = "\e$2" | |
a0cf49c1 TH |
13 | } |
14 | ||
15 | invalid_color() | |
16 | { | |
8b124135 | 17 | test_must_fail git config --get-color no.such.slot "$1" |
a0cf49c1 TH |
18 | } |
19 | ||
20 | test_expect_success 'reset' ' | |
21 | color "reset" "[m" | |
22 | ' | |
23 | ||
24 | test_expect_success 'attribute before color name' ' | |
25 | color "bold red" "[1;31m" | |
26 | ' | |
27 | ||
28 | test_expect_success 'color name before attribute' ' | |
29 | color "red bold" "[1;31m" | |
30 | ' | |
31 | ||
32 | test_expect_success 'attr fg bg' ' | |
33 | color "ul blue red" "[4;34;41m" | |
34 | ' | |
35 | ||
36 | test_expect_success 'fg attr bg' ' | |
37 | color "blue ul red" "[4;34;41m" | |
38 | ' | |
39 | ||
40 | test_expect_success 'fg bg attr' ' | |
41 | color "blue red ul" "[4;34;41m" | |
42 | ' | |
43 | ||
8b124135 JH |
44 | test_expect_success 'fg bg attr...' ' |
45 | color "blue bold dim ul blink reverse" "[1;2;4;5;7;34m" | |
46 | ' | |
47 | ||
ff40d185 JK |
48 | # note that nobold and nodim are the same code (22) |
49 | test_expect_success 'attr negation' ' | |
50 | color "nobold nodim noul noblink noreverse" "[22;24;25;27m" | |
51 | ' | |
52 | ||
5621068f JK |
53 | test_expect_success '"no-" variant of negation' ' |
54 | color "no-bold no-blink" "[22;25m" | |
55 | ' | |
56 | ||
8b124135 JH |
57 | test_expect_success 'long color specification' ' |
58 | color "254 255 bold dim ul blink reverse" "[1;2;4;5;7;38;5;254;48;5;255m" | |
59 | ' | |
60 | ||
ff40d185 JK |
61 | test_expect_success 'absurdly long color specification' ' |
62 | color \ | |
54590a0e | 63 | "#ffffff #ffffff bold nobold dim nodim italic noitalic |
9dc3515c JK |
64 | ul noul blink noblink reverse noreverse strike nostrike" \ |
65 | "[1;2;3;4;5;7;9;22;23;24;25;27;29;38;2;255;255;255;48;2;255;255;255m" | |
ff40d185 JK |
66 | ' |
67 | ||
3759d27a JK |
68 | test_expect_success '0-7 are aliases for basic ANSI color names' ' |
69 | color "0 7" "[30;47m" | |
70 | ' | |
71 | ||
a0cf49c1 TH |
72 | test_expect_success '256 colors' ' |
73 | color "254 bold 255" "[1;38;5;254;48;5;255m" | |
74 | ' | |
75 | ||
17a4be26 JK |
76 | test_expect_success '24-bit colors' ' |
77 | color "#ff00ff black" "[38;2;255;0;255;40m" | |
78 | ' | |
79 | ||
cb357221 JK |
80 | test_expect_success '"normal" yields no color at all"' ' |
81 | color "normal black" "[40m" | |
82 | ' | |
83 | ||
84 | test_expect_success '-1 is a synonym for "normal"' ' | |
85 | color "-1 black" "[40m" | |
86 | ' | |
87 | ||
a0cf49c1 TH |
88 | test_expect_success 'color too small' ' |
89 | invalid_color "-2" | |
90 | ' | |
91 | ||
92 | test_expect_success 'color too big' ' | |
93 | invalid_color "256" | |
94 | ' | |
95 | ||
96 | test_expect_success 'extra character after color number' ' | |
97 | invalid_color "3X" | |
98 | ' | |
99 | ||
100 | test_expect_success 'extra character after color name' ' | |
101 | invalid_color "redX" | |
102 | ' | |
103 | ||
104 | test_expect_success 'extra character after attribute' ' | |
105 | invalid_color "dimX" | |
106 | ' | |
107 | ||
8b8e8624 | 108 | test_expect_success 'unknown color slots are ignored (diff)' ' |
8b8e8624 JK |
109 | git config color.diff.nosuchslotwilleverbedefined white && |
110 | git diff --color | |
111 | ' | |
112 | ||
113 | test_expect_success 'unknown color slots are ignored (branch)' ' | |
114 | git config color.branch.nosuchslotwilleverbedefined white && | |
115 | git branch -a | |
116 | ' | |
117 | ||
118 | test_expect_success 'unknown color slots are ignored (status)' ' | |
9ddc5ac9 JK |
119 | git config color.status.nosuchslotwilleverbedefined white && |
120 | { git status; ret=$?; } && | |
121 | case $ret in 0|1) : ok ;; *) false ;; esac | |
8b8e8624 JK |
122 | ' |
123 | ||
a0cf49c1 | 124 | test_done |