3 test_description
='word diff colors'
7 test_expect_success setup
'
9 git config diff.color.old red
10 git config diff.color.new green
11 git config diff.color.func magenta
16 test_must_fail git
diff --no-index "$@" pre post
> output
&&
17 test_decode_color
<output
>output.decrypted
&&
18 test_cmp expect output.decrypted
38 <WHITE
>diff --git a
/pre b
/post
<RESET
>
39 <WHITE
>index
330b04f.
.5ed8eff
100644<RESET
>
40 <WHITE
>--- a
/pre
<RESET
>
41 <WHITE
>+++ b
/post
<RESET
>
42 <CYAN
>@@
-1,3 +1,7 @@
<RESET
>
43 <RED
>h
(4)<RESET
><GREEN
>h
(4),hh
[44]<RESET
>
49 <GREEN
>aeff
= aeff
* ( aaa
)<RESET
>
52 test_expect_success
'word diff with runs of whitespace' '
54 word_diff --color-words
59 <WHITE
>diff --git a
/pre b
/post
<RESET
>
60 <WHITE
>index
330b04f.
.5ed8eff
100644<RESET
>
61 <WHITE
>--- a
/pre
<RESET
>
62 <WHITE
>+++ b
/post
<RESET
>
63 <CYAN
>@@
-1 +1 @@
<RESET
>
64 <RED
>h
(4)<RESET
><GREEN
>h
(4),hh
[44]<RESET
>
65 <CYAN
>@@
-3,0 +4,4 @@
<RESET
> <RESET
><MAGENTA
>a
= b
+ c
<RESET
>
69 <GREEN
>aeff
= aeff
* ( aaa
)<RESET
>
72 test_expect_success
'word diff without context' '
74 word_diff --color-words --unified=0
79 <WHITE
>diff --git a
/pre b
/post
<RESET
>
80 <WHITE
>index
330b04f.
.5ed8eff
100644<RESET
>
81 <WHITE
>--- a
/pre
<RESET
>
82 <WHITE
>+++ b
/post
<RESET
>
83 <CYAN
>@@
-1,3 +1,7 @@
<RESET
>
84 h
(4),<GREEN
>hh
<RESET
>[44]
90 <GREEN
>aeff
= aeff
* ( aaa
<RESET
> )
92 cp expect expect.letter-runs-are-words
94 test_expect_success
'word diff with a regular expression' '
96 word_diff --color-words="[a-z]+"
100 test_expect_success
'set a diff driver' '
101 git config diff.testdriver.wordRegex "[^[:space:]]" &&
102 cat <<EOF > .gitattributes
108 test_expect_success
'option overrides .gitattributes' '
110 word_diff --color-words="[a-z]+"
115 <WHITE
>diff --git a
/pre b
/post
<RESET
>
116 <WHITE
>index
330b04f.
.5ed8eff
100644<RESET
>
117 <WHITE
>--- a
/pre
<RESET
>
118 <WHITE
>+++ b
/post
<RESET
>
119 <CYAN
>@@
-1,3 +1,7 @@
<RESET
>
120 h
(4)<GREEN
>,hh
[44]<RESET
>
126 <GREEN
>aeff
= aeff
* ( aaa
)<RESET
>
128 cp expect expect.non-whitespace-is-word
130 test_expect_success
'use regex supplied by driver' '
132 word_diff --color-words
136 test_expect_success
'set diff.wordRegex option' '
137 git config diff.wordRegex "[[:alnum:]]+"
140 cp expect.letter-runs-are-words expect
142 test_expect_success
'command-line overrides config' '
143 word_diff --color-words="[a-z]+"
146 cp expect.non-whitespace-is-word expect
148 test_expect_success
'.gitattributes override config' '
149 word_diff --color-words
152 test_expect_success
'remove diff driver regex' '
153 git config --unset diff.testdriver.wordRegex
157 <WHITE
>diff --git a
/pre b
/post
<RESET
>
158 <WHITE
>index
330b04f.
.5ed8eff
100644<RESET
>
159 <WHITE
>--- a
/pre
<RESET
>
160 <WHITE
>+++ b
/post
<RESET
>
161 <CYAN
>@@
-1,3 +1,7 @@
<RESET
>
162 h
(4),<GREEN
>hh
[44<RESET
>]
168 <GREEN
>aeff
= aeff
* ( aaa
<RESET
> )
171 test_expect_success
'use configured regex' '
172 word_diff --color-words
175 echo 'aaa (aaa)' > pre
176 echo 'aaa (aaa) aaa' > post
179 <WHITE
>diff --git a
/pre b
/post
<RESET
>
180 <WHITE
>index c29453b..be22f37
100644<RESET
>
181 <WHITE
>--- a
/pre
<RESET
>
182 <WHITE
>+++ b
/post
<RESET
>
183 <CYAN
>@@
-1 +1 @@
<RESET
>
184 aaa
(aaa
) <GREEN
>aaa
<RESET
>
187 test_expect_success
'test parsing words for newline' '
189 word_diff --color-words="a+"
198 <WHITE
>diff --git a
/pre b
/post
<RESET
>
199 <WHITE
>index
289cb9d.
.2d06f37
100644<RESET
>
200 <WHITE
>--- a
/pre
<RESET
>
201 <WHITE
>+++ b
/post
<RESET
>
202 <CYAN
>@@
-1 +1 @@
<RESET
>
206 test_expect_success
'test when words are only removed at the end' '
208 word_diff --color-words=.