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
58 test_expect_success
'--word-diff=color' '
60 word_diff --word-diff=color
64 test_expect_success
'--color --word-diff=color' '
66 word_diff --color --word-diff=color
70 sed 's/#.*$//' > expect
<<EOF
71 diff --git a/pre b/post
72 index 330b04f..5ed8eff 100644
87 +aeff = aeff * ( aaa )
91 test_expect_success
'--word-diff=porcelain' '
93 word_diff --word-diff=porcelain
98 diff --git a/pre b/post
99 index 330b04f..5ed8eff 100644
103 [-h(4)-]{+h(4),hh[44]+}
109 {+aeff = aeff * ( aaa )+}
112 test_expect_success
'--word-diff=plain' '
114 word_diff --word-diff=plain
118 test_expect_success
'--word-diff=plain --no-color' '
120 word_diff --word-diff=plain --no-color
125 <WHITE>diff --git a/pre b/post<RESET>
126 <WHITE>index 330b04f..5ed8eff 100644<RESET>
127 <WHITE>--- a/pre<RESET>
128 <WHITE>+++ b/post<RESET>
129 <CYAN>@@ -1,3 +1,7 @@<RESET>
130 <RED>[-h(4)-]<RESET><GREEN>{+h(4),hh[44]+}<RESET>
134 <GREEN>{+aa = a+}<RESET>
136 <GREEN>{+aeff = aeff * ( aaa )+}<RESET>
139 test_expect_success
'--word-diff=plain --color' '
141 word_diff --word-diff=plain --color
146 <WHITE
>diff --git a
/pre b
/post
<RESET
>
147 <WHITE
>index
330b04f.
.5ed8eff
100644<RESET
>
148 <WHITE
>--- a
/pre
<RESET
>
149 <WHITE
>+++ b
/post
<RESET
>
150 <CYAN
>@@
-1 +1 @@
<RESET
>
151 <RED
>h
(4)<RESET
><GREEN
>h
(4),hh
[44]<RESET
>
152 <CYAN
>@@
-3,0 +4,4 @@
<RESET
> <RESET
><MAGENTA
>a
= b
+ c
<RESET
>
156 <GREEN
>aeff
= aeff
* ( aaa
)<RESET
>
159 test_expect_success
'word diff without context' '
161 word_diff --color-words --unified=0
166 <WHITE
>diff --git a
/pre b
/post
<RESET
>
167 <WHITE
>index
330b04f.
.5ed8eff
100644<RESET
>
168 <WHITE
>--- a
/pre
<RESET
>
169 <WHITE
>+++ b
/post
<RESET
>
170 <CYAN
>@@
-1,3 +1,7 @@
<RESET
>
171 h
(4),<GREEN
>hh
<RESET
>[44]
177 <GREEN
>aeff
= aeff
* ( aaa
<RESET
> )
179 cp expect expect.letter-runs-are-words
181 test_expect_success
'word diff with a regular expression' '
183 word_diff --color-words="[a-z]+"
187 test_expect_success
'set a diff driver' '
188 git config diff.testdriver.wordRegex "[^[:space:]]" &&
189 cat <<EOF > .gitattributes
195 test_expect_success
'option overrides .gitattributes' '
197 word_diff --color-words="[a-z]+"
202 <WHITE
>diff --git a
/pre b
/post
<RESET
>
203 <WHITE
>index
330b04f.
.5ed8eff
100644<RESET
>
204 <WHITE
>--- a
/pre
<RESET
>
205 <WHITE
>+++ b
/post
<RESET
>
206 <CYAN
>@@
-1,3 +1,7 @@
<RESET
>
207 h
(4)<GREEN
>,hh
[44]<RESET
>
213 <GREEN
>aeff
= aeff
* ( aaa
)<RESET
>
215 cp expect expect.non-whitespace-is-word
217 test_expect_success
'use regex supplied by driver' '
219 word_diff --color-words
223 test_expect_success
'set diff.wordRegex option' '
224 git config diff.wordRegex "[[:alnum:]]+"
227 cp expect.letter-runs-are-words expect
229 test_expect_success
'command-line overrides config' '
230 word_diff --color-words="[a-z]+"
234 <WHITE
>diff --git a
/pre b
/post
<RESET
>
235 <WHITE
>index
330b04f.
.5ed8eff
100644<RESET
>
236 <WHITE
>--- a
/pre
<RESET
>
237 <WHITE
>+++ b
/post
<RESET
>
238 <CYAN
>@@
-1,3 +1,7 @@
<RESET
>
239 h
(4),<GREEN
>{+hh
+}<RESET
>[44]
243 <GREEN
>{+aa
= a
+}<RESET
>
245 <GREEN
>{+aeff
= aeff
* ( aaa
+}<RESET
> )
248 test_expect_success
'command-line overrides config: --word-diff-regex' '
249 word_diff --color --word-diff-regex="[a-z]+"
252 cp expect.non-whitespace-is-word expect
254 test_expect_success
'.gitattributes override config' '
255 word_diff --color-words
258 test_expect_success
'remove diff driver regex' '
259 git config --unset diff.testdriver.wordRegex
263 <WHITE
>diff --git a
/pre b
/post
<RESET
>
264 <WHITE
>index
330b04f.
.5ed8eff
100644<RESET
>
265 <WHITE
>--- a
/pre
<RESET
>
266 <WHITE
>+++ b
/post
<RESET
>
267 <CYAN
>@@
-1,3 +1,7 @@
<RESET
>
268 h
(4),<GREEN
>hh
[44<RESET
>]
274 <GREEN
>aeff
= aeff
* ( aaa
<RESET
> )
277 test_expect_success
'use configured regex' '
278 word_diff --color-words
281 echo 'aaa (aaa)' > pre
282 echo 'aaa (aaa) aaa' > post
285 <WHITE
>diff --git a
/pre b
/post
<RESET
>
286 <WHITE
>index c29453b..be22f37
100644<RESET
>
287 <WHITE
>--- a
/pre
<RESET
>
288 <WHITE
>+++ b
/post
<RESET
>
289 <CYAN
>@@
-1 +1 @@
<RESET
>
290 aaa
(aaa
) <GREEN
>aaa
<RESET
>
293 test_expect_success
'test parsing words for newline' '
295 word_diff --color-words="a+"
304 <WHITE
>diff --git a
/pre b
/post
<RESET
>
305 <WHITE
>index
289cb9d.
.2d06f37
100644<RESET
>
306 <WHITE
>--- a
/pre
<RESET
>
307 <WHITE
>+++ b
/post
<RESET
>
308 <CYAN
>@@
-1 +1 @@
<RESET
>
312 test_expect_success
'test when words are only removed at the end' '
314 word_diff --color-words=.
319 diff --git a
/pre b
/post
320 index
289cb9d.
.2d06f37
100644
328 test_expect_success
'--word-diff=none' '
330 word_diff --word-diff=plain --word-diff=none