]>
Commit | Line | Data |
---|---|---|
2e5d2003 JS |
1 | #!/bin/sh |
2 | ||
3 | test_description='word diff colors' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | test_expect_success setup ' | |
8 | ||
9 | git config diff.color.old red | |
10 | git config diff.color.new green | |
89cb73a1 | 11 | git config diff.color.func magenta |
2e5d2003 JS |
12 | |
13 | ' | |
14 | ||
2e5d2003 JS |
15 | word_diff () { |
16 | test_must_fail git diff --no-index "$@" pre post > output && | |
68cfc6f5 | 17 | test_decode_color <output >output.decrypted && |
2e5d2003 JS |
18 | test_cmp expect output.decrypted |
19 | } | |
20 | ||
21 | cat > pre <<\EOF | |
22 | h(4) | |
23 | ||
24 | a = b + c | |
25 | EOF | |
26 | ||
27 | cat > post <<\EOF | |
28 | h(4),hh[44] | |
29 | ||
30 | a = b + c | |
31 | ||
32 | aa = a | |
33 | ||
34 | aeff = aeff * ( aaa ) | |
35 | EOF | |
36 | ||
37 | cat > expect <<\EOF | |
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> | |
68cfc6f5 | 42 | <CYAN>@@ -1,3 +1,7 @@<RESET> |
2e5d2003 | 43 | <RED>h(4)<RESET><GREEN>h(4),hh[44]<RESET> |
06a47552 | 44 | |
2e5d2003 JS |
45 | a = b + c<RESET> |
46 | ||
47 | <GREEN>aa = a<RESET> | |
48 | ||
49 | <GREEN>aeff = aeff * ( aaa )<RESET> | |
50 | EOF | |
51 | ||
52 | test_expect_success 'word diff with runs of whitespace' ' | |
53 | ||
54 | word_diff --color-words | |
55 | ||
56 | ' | |
57 | ||
168eff3c MH |
58 | cat > expect <<\EOF |
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> | |
c2ff10c9 | 63 | <CYAN>@@ -1 +1 @@<RESET> |
168eff3c | 64 | <RED>h(4)<RESET><GREEN>h(4),hh[44]<RESET> |
c2ff10c9 | 65 | <CYAN>@@ -3,0 +4,4 @@<RESET> <RESET><MAGENTA>a = b + c<RESET> |
168eff3c MH |
66 | |
67 | <GREEN>aa = a<RESET> | |
68 | ||
69 | <GREEN>aeff = aeff * ( aaa )<RESET> | |
70 | EOF | |
71 | ||
a4ca1465 | 72 | test_expect_success 'word diff without context' ' |
168eff3c MH |
73 | |
74 | word_diff --color-words --unified=0 | |
75 | ||
76 | ' | |
77 | ||
2b6a5417 JS |
78 | cat > expect <<\EOF |
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> | |
68cfc6f5 | 83 | <CYAN>@@ -1,3 +1,7 @@<RESET> |
2b6a5417 | 84 | h(4),<GREEN>hh<RESET>[44] |
06a47552 | 85 | |
2b6a5417 JS |
86 | a = b + c<RESET> |
87 | ||
88 | <GREEN>aa = a<RESET> | |
89 | ||
90 | <GREEN>aeff = aeff * ( aaa<RESET> ) | |
91 | EOF | |
98a4d87b | 92 | cp expect expect.letter-runs-are-words |
2b6a5417 JS |
93 | |
94 | test_expect_success 'word diff with a regular expression' ' | |
95 | ||
96 | word_diff --color-words="[a-z]+" | |
97 | ||
98 | ' | |
99 | ||
80c49c3d | 100 | test_expect_success 'set a diff driver' ' |
ae3b970a | 101 | git config diff.testdriver.wordRegex "[^[:space:]]" && |
80c49c3d TR |
102 | cat <<EOF > .gitattributes |
103 | pre diff=testdriver | |
104 | post diff=testdriver | |
105 | EOF | |
106 | ' | |
107 | ||
98a4d87b | 108 | test_expect_success 'option overrides .gitattributes' ' |
80c49c3d TR |
109 | |
110 | word_diff --color-words="[a-z]+" | |
111 | ||
112 | ' | |
113 | ||
114 | cat > expect <<\EOF | |
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> | |
68cfc6f5 | 119 | <CYAN>@@ -1,3 +1,7 @@<RESET> |
80c49c3d | 120 | h(4)<GREEN>,hh[44]<RESET> |
06a47552 | 121 | |
80c49c3d TR |
122 | a = b + c<RESET> |
123 | ||
124 | <GREEN>aa = a<RESET> | |
125 | ||
126 | <GREEN>aeff = aeff * ( aaa )<RESET> | |
127 | EOF | |
98a4d87b | 128 | cp expect expect.non-whitespace-is-word |
80c49c3d | 129 | |
98a4d87b | 130 | test_expect_success 'use regex supplied by driver' ' |
80c49c3d TR |
131 | |
132 | word_diff --color-words | |
133 | ||
134 | ' | |
135 | ||
ae3b970a BSSJ |
136 | test_expect_success 'set diff.wordRegex option' ' |
137 | git config diff.wordRegex "[[:alnum:]]+" | |
98a4d87b BSSJ |
138 | ' |
139 | ||
140 | cp expect.letter-runs-are-words expect | |
141 | ||
142 | test_expect_success 'command-line overrides config' ' | |
143 | word_diff --color-words="[a-z]+" | |
144 | ' | |
145 | ||
146 | cp expect.non-whitespace-is-word expect | |
147 | ||
148 | test_expect_success '.gitattributes override config' ' | |
149 | word_diff --color-words | |
150 | ' | |
151 | ||
152 | test_expect_success 'remove diff driver regex' ' | |
ae3b970a | 153 | git config --unset diff.testdriver.wordRegex |
98a4d87b BSSJ |
154 | ' |
155 | ||
156 | cat > expect <<\EOF | |
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> | |
68cfc6f5 | 161 | <CYAN>@@ -1,3 +1,7 @@<RESET> |
98a4d87b | 162 | h(4),<GREEN>hh[44<RESET>] |
06a47552 | 163 | |
98a4d87b BSSJ |
164 | a = b + c<RESET> |
165 | ||
166 | <GREEN>aa = a<RESET> | |
167 | ||
168 | <GREEN>aeff = aeff * ( aaa<RESET> ) | |
169 | EOF | |
170 | ||
171 | test_expect_success 'use configured regex' ' | |
172 | word_diff --color-words | |
173 | ' | |
174 | ||
2b6a5417 JS |
175 | echo 'aaa (aaa)' > pre |
176 | echo 'aaa (aaa) aaa' > post | |
177 | ||
178 | cat > expect <<\EOF | |
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> | |
68cfc6f5 | 183 | <CYAN>@@ -1 +1 @@<RESET> |
2b6a5417 JS |
184 | aaa (aaa) <GREEN>aaa<RESET> |
185 | EOF | |
186 | ||
187 | test_expect_success 'test parsing words for newline' ' | |
188 | ||
189 | word_diff --color-words="a+" | |
190 | ||
80c49c3d | 191 | |
2b6a5417 JS |
192 | ' |
193 | ||
194 | echo '(:' > pre | |
195 | echo '(' > post | |
196 | ||
197 | cat > expect <<\EOF | |
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> | |
68cfc6f5 | 202 | <CYAN>@@ -1 +1 @@<RESET> |
2b6a5417 JS |
203 | (<RED>:<RESET> |
204 | EOF | |
205 | ||
206 | test_expect_success 'test when words are only removed at the end' ' | |
207 | ||
208 | word_diff --color-words=. | |
209 | ||
210 | ' | |
211 | ||
2e5d2003 | 212 | test_done |