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