SubmittingPatches: hints to know the status of a submitted patch.
[git/raj.git] / t / t4034-diff-words.sh
blob1c21276c55400c594f71bc01eba17b0d3820b420
1 #!/bin/sh
3 test_description='word diff colors'
5 . ./test-lib.sh
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
15 decrypt_color () {
16 sed \
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' \
22 -e 's/.\[m/<RESET>/g'
25 word_diff () {
26 test_must_fail git diff --no-index "$@" pre post > output &&
27 decrypt_color < output > output.decrypted &&
28 test_cmp expect output.decrypted
31 cat > pre <<\EOF
32 h(4)
34 a = b + c
35 EOF
37 cat > post <<\EOF
38 h(4),hh[44]
40 a = b + c
42 aa = a
44 aeff = aeff * ( aaa )
45 EOF
47 cat > expect <<\EOF
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>
55 a = b + c<RESET>
57 <GREEN>aa = a<RESET>
59 <GREEN>aeff = aeff * ( aaa )<RESET>
60 EOF
62 test_expect_success 'word diff with runs of whitespace' '
64 word_diff --color-words
68 cat > expect <<\EOF
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>
77 <GREEN>aa = a<RESET>
79 <GREEN>aeff = aeff * ( aaa )<RESET>
80 EOF
82 test_expect_success 'word diff without context' '
84 word_diff --color-words --unified=0
88 cat > expect <<\EOF
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]
96 a = b + c<RESET>
98 <GREEN>aa = a<RESET>
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
113 pre diff=testdriver
114 post diff=testdriver
118 test_expect_success 'option overrides .gitattributes' '
120 word_diff --color-words="[a-z]+"
124 cat > expect <<\EOF
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>
132 a = b + c<RESET>
134 <GREEN>aa = a<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
166 cat > expect <<\EOF
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>]
174 a = b + c<RESET>
176 <GREEN>aa = a<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
188 cat > expect <<\EOF
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+"
204 echo '(:' > pre
205 echo '(' > post
207 cat > expect <<\EOF
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>
213 (<RED>:<RESET>
216 test_expect_success 'test when words are only removed at the end' '
218 word_diff --color-words=.
222 test_done