Code

status/commit: do not suggest "reset HEAD <path>" while merging
[git.git] / t / t4034-diff-words.sh
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
12 '
14 word_diff () {
15         test_must_fail git diff --no-index "$@" pre post > output &&
16         test_decode_color <output >output.decrypted &&
17         test_cmp expect output.decrypted
18 }
20 cat > pre <<\EOF
21 h(4)
23 a = b + c
24 EOF
26 cat > post <<\EOF
27 h(4),hh[44]
29 a = b + c
31 aa = a
33 aeff = aeff * ( aaa )
34 EOF
36 cat > expect <<\EOF
37 <WHITE>diff --git a/pre b/post<RESET>
38 <WHITE>index 330b04f..5ed8eff 100644<RESET>
39 <WHITE>--- a/pre<RESET>
40 <WHITE>+++ b/post<RESET>
41 <CYAN>@@ -1,3 +1,7 @@<RESET>
42 <RED>h(4)<RESET><GREEN>h(4),hh[44]<RESET>
43 <RESET>
44 a = b + c<RESET>
46 <GREEN>aa = a<RESET>
48 <GREEN>aeff = aeff * ( aaa )<RESET>
49 EOF
51 test_expect_success 'word diff with runs of whitespace' '
53         word_diff --color-words
55 '
57 cat > expect <<\EOF
58 <WHITE>diff --git a/pre b/post<RESET>
59 <WHITE>index 330b04f..5ed8eff 100644<RESET>
60 <WHITE>--- a/pre<RESET>
61 <WHITE>+++ b/post<RESET>
62 <CYAN>@@ -1,3 +1,7 @@<RESET>
63 h(4),<GREEN>hh<RESET>[44]
64 <RESET>
65 a = b + c<RESET>
67 <GREEN>aa = a<RESET>
69 <GREEN>aeff = aeff * ( aaa<RESET> )
70 EOF
71 cp expect expect.letter-runs-are-words
73 test_expect_success 'word diff with a regular expression' '
75         word_diff --color-words="[a-z]+"
77 '
79 test_expect_success 'set a diff driver' '
80         git config diff.testdriver.wordRegex "[^[:space:]]" &&
81         cat <<EOF > .gitattributes
82 pre diff=testdriver
83 post diff=testdriver
84 EOF
85 '
87 test_expect_success 'option overrides .gitattributes' '
89         word_diff --color-words="[a-z]+"
91 '
93 cat > expect <<\EOF
94 <WHITE>diff --git a/pre b/post<RESET>
95 <WHITE>index 330b04f..5ed8eff 100644<RESET>
96 <WHITE>--- a/pre<RESET>
97 <WHITE>+++ b/post<RESET>
98 <CYAN>@@ -1,3 +1,7 @@<RESET>
99 h(4)<GREEN>,hh[44]<RESET>
100 <RESET>
101 a = b + c<RESET>
103 <GREEN>aa = a<RESET>
105 <GREEN>aeff = aeff * ( aaa )<RESET>
106 EOF
107 cp expect expect.non-whitespace-is-word
109 test_expect_success 'use regex supplied by driver' '
111         word_diff --color-words
115 test_expect_success 'set diff.wordRegex option' '
116         git config diff.wordRegex "[[:alnum:]]+"
119 cp expect.letter-runs-are-words expect
121 test_expect_success 'command-line overrides config' '
122         word_diff --color-words="[a-z]+"
125 cp expect.non-whitespace-is-word expect
127 test_expect_success '.gitattributes override config' '
128         word_diff --color-words
131 test_expect_success 'remove diff driver regex' '
132         git config --unset diff.testdriver.wordRegex
135 cat > expect <<\EOF
136 <WHITE>diff --git a/pre b/post<RESET>
137 <WHITE>index 330b04f..5ed8eff 100644<RESET>
138 <WHITE>--- a/pre<RESET>
139 <WHITE>+++ b/post<RESET>
140 <CYAN>@@ -1,3 +1,7 @@<RESET>
141 h(4),<GREEN>hh[44<RESET>]
142 <RESET>
143 a = b + c<RESET>
145 <GREEN>aa = a<RESET>
147 <GREEN>aeff = aeff * ( aaa<RESET> )
148 EOF
150 test_expect_success 'use configured regex' '
151         word_diff --color-words
154 echo 'aaa (aaa)' > pre
155 echo 'aaa (aaa) aaa' > post
157 cat > expect <<\EOF
158 <WHITE>diff --git a/pre b/post<RESET>
159 <WHITE>index c29453b..be22f37 100644<RESET>
160 <WHITE>--- a/pre<RESET>
161 <WHITE>+++ b/post<RESET>
162 <CYAN>@@ -1 +1 @@<RESET>
163 aaa (aaa) <GREEN>aaa<RESET>
164 EOF
166 test_expect_success 'test parsing words for newline' '
168         word_diff --color-words="a+"
173 echo '(:' > pre
174 echo '(' > post
176 cat > expect <<\EOF
177 <WHITE>diff --git a/pre b/post<RESET>
178 <WHITE>index 289cb9d..2d06f37 100644<RESET>
179 <WHITE>--- a/pre<RESET>
180 <WHITE>+++ b/post<RESET>
181 <CYAN>@@ -1 +1 @@<RESET>
182 (<RED>:<RESET>
183 EOF
185 test_expect_success 'test when words are only removed at the end' '
187         word_diff --color-words=.
191 test_done