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
17 -e 's/.\[1m/<WHITE>/g' \
18 -e 's/.\[31m/<RED>/g' \
19 -e 's/.\[32m/<GREEN>/g' \
20 -e 's/.\[35m/<MAGENTA>/g' \
21 -e 's/.\[36m/<BROWN>/g' \
26 test_must_fail git
diff --no-index "$@" pre post
> output
&&
27 decrypt_color
< output
> output.decrypted
&&
28 test_cmp expect output.decrypted
48 <WHITE
>diff --git a
/pre b
/post
<RESET
>
49 <WHITE
>index
330b04f.
.5ed8eff
100644<RESET
>
50 <WHITE
>--- a
/pre
<RESET
>
51 <WHITE
>+++ b
/post
<RESET
>
52 <BROWN
>@@
-1,3 +1,7 @@
<RESET
>
53 <RED
>h
(4)<RESET
><GREEN
>h
(4),hh
[44]<RESET
>
59 <GREEN
>aeff
= aeff
* ( aaa
)<RESET
>
62 test_expect_success
'word diff with runs of whitespace' '
64 word_diff --color-words
69 <WHITE
>diff --git a
/pre b
/post
<RESET
>
70 <WHITE
>index
330b04f.
.5ed8eff
100644<RESET
>
71 <WHITE
>--- a
/pre
<RESET
>
72 <WHITE
>+++ b
/post
<RESET
>
73 <BROWN
>@@
-1 +1 @@
<RESET
>
74 <RED
>h
(4)<RESET
><GREEN
>h
(4),hh
[44]<RESET
>
75 <BROWN
>@@
-3,0 +4,4 @@
<RESET
> <RESET
><MAGENTA
>a
= b
+ c
<RESET
>
79 <GREEN
>aeff
= aeff
* ( aaa
)<RESET
>
82 test_expect_success
'word diff without context' '
84 word_diff --color-words --unified=0
89 <WHITE
>diff --git a
/pre b
/post
<RESET
>
90 <WHITE
>index
330b04f.
.5ed8eff
100644<RESET
>
91 <WHITE
>--- a
/pre
<RESET
>
92 <WHITE
>+++ b
/post
<RESET
>
93 <BROWN
>@@
-1,3 +1,7 @@
<RESET
>
94 h
(4),<GREEN
>hh
<RESET
>[44]
100 <GREEN
>aeff
= aeff
* ( aaa
<RESET
> )
102 cp expect expect.letter-runs-are-words
104 test_expect_success
'word diff with a regular expression' '
106 word_diff --color-words="[a-z]+"
110 test_expect_success
'set a diff driver' '
111 git config diff.testdriver.wordRegex "[^[:space:]]" &&
112 cat <<EOF > .gitattributes
118 test_expect_success
'option overrides .gitattributes' '
120 word_diff --color-words="[a-z]+"
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 <BROWN
>@@
-1,3 +1,7 @@
<RESET
>
130 h
(4)<GREEN
>,hh
[44]<RESET
>
136 <GREEN
>aeff
= aeff
* ( aaa
)<RESET
>
138 cp expect expect.non-whitespace-is-word
140 test_expect_success
'use regex supplied by driver' '
142 word_diff --color-words
146 test_expect_success
'set diff.wordRegex option' '
147 git config diff.wordRegex "[[:alnum:]]+"
150 cp expect.letter-runs-are-words expect
152 test_expect_success
'command-line overrides config' '
153 word_diff --color-words="[a-z]+"
156 cp expect.non-whitespace-is-word expect
158 test_expect_success
'.gitattributes override config' '
159 word_diff --color-words
162 test_expect_success
'remove diff driver regex' '
163 git config --unset diff.testdriver.wordRegex
167 <WHITE
>diff --git a
/pre b
/post
<RESET
>
168 <WHITE
>index
330b04f.
.5ed8eff
100644<RESET
>
169 <WHITE
>--- a
/pre
<RESET
>
170 <WHITE
>+++ b
/post
<RESET
>
171 <BROWN
>@@
-1,3 +1,7 @@
<RESET
>
172 h
(4),<GREEN
>hh
[44<RESET
>]
178 <GREEN
>aeff
= aeff
* ( aaa
<RESET
> )
181 test_expect_success
'use configured regex' '
182 word_diff --color-words
185 echo 'aaa (aaa)' > pre
186 echo 'aaa (aaa) aaa' > post
189 <WHITE
>diff --git a
/pre b
/post
<RESET
>
190 <WHITE
>index c29453b..be22f37
100644<RESET
>
191 <WHITE
>--- a
/pre
<RESET
>
192 <WHITE
>+++ b
/post
<RESET
>
193 <BROWN
>@@
-1 +1 @@
<RESET
>
194 aaa
(aaa
) <GREEN
>aaa
<RESET
>
197 test_expect_success
'test parsing words for newline' '
199 word_diff --color-words="a+"
208 <WHITE
>diff --git a
/pre b
/post
<RESET
>
209 <WHITE
>index
289cb9d.
.2d06f37
100644<RESET
>
210 <WHITE
>--- a
/pre
<RESET
>
211 <WHITE
>+++ b
/post
<RESET
>
212 <BROWN
>@@
-1 +1 @@
<RESET
>
216 test_expect_success
'test when words are only removed at the end' '
218 word_diff --color-words=.