interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t4026-color.sh

178 lines · 4005 bytes Raw Blame History
1#!/bin/sh
2#
3# Copyright (c) 2008 Timo Hirvonen
4#
5
6test_description='Test diff/status color escape codes'
7
8. ./test-lib.sh
9
10ESC=$(printf '\033')
11color()
12{
13 actual=$(git config --get-color no.such.slot "$1") &&
14 test "$actual" = "${2:+$ESC}$2"
15}
16
17invalid_color()
18{
19 test_must_fail git config --get-color no.such.slot "$1"
20}
21
22test_expect_success 'reset' '
23 color "reset" "[m"
24'
25
26test_expect_success 'empty color is empty' '
27 color "" ""
28'
29
30test_expect_success 'attribute before color name' '
31 color "bold red" "[1;31m"
32'
33
34test_expect_success 'aixterm bright fg color' '
35 color "brightred" "[91m"
36'
37
38test_expect_success 'aixterm bright bg color' '
39 color "green brightblue" "[32;104m"
40'
41
42test_expect_success 'color name before attribute' '
43 color "red bold" "[1;31m"
44'
45
46test_expect_success 'attr fg bg' '
47 color "ul blue red" "[4;34;41m"
48'
49
50test_expect_success 'fg attr bg' '
51 color "blue ul red" "[4;34;41m"
52'
53
54test_expect_success 'fg bg attr' '
55 color "blue red ul" "[4;34;41m"
56'
57
58test_expect_success 'fg bg attr...' '
59 color "blue bold dim ul blink reverse" "[1;2;4;5;7;34m"
60'
61
62test_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)
67test_expect_success 'attr negation' '
68 color "nobold nodim noul noblink noreverse" "[22;24;25;27m"
69'
70
71test_expect_success '"no-" variant of negation' '
72 color "no-bold no-blink" "[22;25m"
73'
74
75test_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
79test_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
86test_expect_success '0-7 are aliases for basic ANSI color names' '
87 color "0 7" "[30;47m"
88'
89
90test_expect_success '8-15 are aliases for aixterm color names' '
91 color "12 13" "[94;105m"
92'
93
94test_expect_success '256 colors' '
95 color "254 bold 255" "[1;38;5;254;48;5;255m"
96'
97
98test_expect_success 'RGB colors' '
99 color "#ff00ff #0f0" "[38;2;255;0;255;48;2;0;255;0m"
100'
101
102test_expect_success '"default" foreground' '
103 color "default" "[39m"
104'
105
106test_expect_success '"normal default" to clear background' '
107 color "normal default" "[49m"
108'
109
110test_expect_success '"default" can be combined with attributes' '
111 color "default default no-reverse bold" "[1;27;39;49m"
112'
113
114test_expect_success '"normal" yields no color at all' '
115 color "normal black" "[40m"
116'
117
118test_expect_success '-1 is a synonym for "normal"' '
119 color "-1 black" "[40m"
120'
121
122test_expect_success 'color too small' '
123 invalid_color "-2"
124'
125
126test_expect_success 'color too big' '
127 invalid_color "256"
128'
129
130test_expect_success 'extra character after color number' '
131 invalid_color "3X"
132'
133
134test_expect_success 'extra character after color name' '
135 invalid_color "redX"
136'
137
138test_expect_success 'extra character after attribute' '
139 invalid_color "dimX"
140'
141
142test_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
154test_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
162test_expect_success 'unknown color slots are ignored (diff)' '
163 git config color.diff.nosuchslotwilleverbedefined white &&
164 git diff --color
165'
166
167test_expect_success 'unknown color slots are ignored (branch)' '
168 git config color.branch.nosuchslotwilleverbedefined white &&
169 git branch -a
170'
171
172test_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
178test_done