Prevent case sensitive commit
[git/jr.git] / t / t0030-stripspace.sh
blobcad95f35adad5864e99ef5cd1633c820ff25b6c0
1 #!/bin/sh
3 # Copyright (c) 2007 Carlos Rica
6 test_description='git stripspace'
8 . ./test-lib.sh
10 t40='A quick brown fox jumps over the lazy do'
11 s40=' '
12 sss="$s40$s40$s40$s40$s40$s40$s40$s40$s40$s40" # 400
13 ttt="$t40$t40$t40$t40$t40$t40$t40$t40$t40$t40" # 400
15 test_expect_success \
16 'long lines without spaces should be unchanged' '
17 echo "$ttt" >expect &&
18 git stripspace <expect >actual &&
19 git diff expect actual &&
21 echo "$ttt$ttt" >expect &&
22 git stripspace <expect >actual &&
23 git diff expect actual &&
25 echo "$ttt$ttt$ttt" >expect &&
26 git stripspace <expect >actual &&
27 git diff expect actual &&
29 echo "$ttt$ttt$ttt$ttt" >expect &&
30 git stripspace <expect >actual &&
31 git diff expect actual
34 test_expect_success \
35 'lines with spaces at the beginning should be unchanged' '
36 echo "$sss$ttt" >expect &&
37 git stripspace <expect >actual &&
38 git diff expect actual &&
40 echo "$sss$sss$ttt" >expect &&
41 git stripspace <expect >actual &&
42 git diff expect actual &&
44 echo "$sss$sss$sss$ttt" >expect &&
45 git stripspace <expect >actual &&
46 git diff expect actual
49 test_expect_success \
50 'lines with intermediate spaces should be unchanged' '
51 echo "$ttt$sss$ttt" >expect &&
52 git stripspace <expect >actual &&
53 git diff expect actual &&
55 echo "$ttt$sss$sss$ttt" >expect &&
56 git stripspace <expect >actual &&
57 git diff expect actual
60 test_expect_success \
61 'consecutive blank lines should be unified' '
62 printf "$ttt\n\n$ttt\n" > expect &&
63 printf "$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
64 git diff expect actual &&
66 printf "$ttt$ttt\n\n$ttt\n" > expect &&
67 printf "$ttt$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
68 git diff expect actual &&
70 printf "$ttt$ttt$ttt\n\n$ttt\n" > expect &&
71 printf "$ttt$ttt$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
72 git diff expect actual &&
74 printf "$ttt\n\n$ttt\n" > expect &&
75 printf "$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
76 git diff expect actual &&
78 printf "$ttt\n\n$ttt$ttt\n" > expect &&
79 printf "$ttt\n\n\n\n\n$ttt$ttt\n" | git stripspace >actual &&
80 git diff expect actual &&
82 printf "$ttt\n\n$ttt$ttt$ttt\n" > expect &&
83 printf "$ttt\n\n\n\n\n$ttt$ttt$ttt\n" | git stripspace >actual &&
84 git diff expect actual &&
86 printf "$ttt\n\n$ttt\n" > expect &&
87 printf "$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
88 git diff expect actual &&
90 printf "$ttt$ttt\n\n$ttt\n" > expect &&
91 printf "$ttt$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
92 git diff expect actual &&
94 printf "$ttt$ttt$ttt\n\n$ttt\n" > expect &&
95 printf "$ttt$ttt$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
96 git diff expect actual &&
98 printf "$ttt\n\n$ttt\n" > expect &&
99 printf "$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
100 git diff expect actual &&
102 printf "$ttt\n\n$ttt$ttt\n" > expect &&
103 printf "$ttt\n\t\n \n\n \t\t\n$ttt$ttt\n" | git stripspace >actual &&
104 git diff expect actual &&
106 printf "$ttt\n\n$ttt$ttt$ttt\n" > expect &&
107 printf "$ttt\n\t\n \n\n \t\t\n$ttt$ttt$ttt\n" | git stripspace >actual &&
108 git diff expect actual
111 test_expect_success \
112 'only consecutive blank lines should be completely removed' '
113 > expect &&
115 printf "\n" | git stripspace >actual &&
116 git diff expect actual &&
118 printf "\n\n\n" | git stripspace >actual &&
119 git diff expect actual &&
121 printf "$sss\n$sss\n$sss\n" | git stripspace >actual &&
122 git diff expect actual &&
124 printf "$sss$sss\n$sss\n\n" | git stripspace >actual &&
125 git diff expect actual &&
127 printf "\n$sss\n$sss$sss\n" | git stripspace >actual &&
128 git diff expect actual &&
130 printf "$sss$sss$sss$sss\n\n\n" | git stripspace >actual &&
131 git diff expect actual &&
133 printf "\n$sss$sss$sss$sss\n\n" | git stripspace >actual &&
134 git diff expect actual &&
136 printf "\n\n$sss$sss$sss$sss\n" | git stripspace >actual &&
137 git diff expect actual
140 test_expect_success \
141 'consecutive blank lines at the beginning should be removed' '
142 printf "$ttt\n" > expect &&
143 printf "\n$ttt\n" | git stripspace >actual &&
144 git diff expect actual &&
146 printf "$ttt\n" > expect &&
147 printf "\n\n\n$ttt\n" | git stripspace >actual &&
148 git diff expect actual &&
150 printf "$ttt$ttt\n" > expect &&
151 printf "\n\n\n$ttt$ttt\n" | git stripspace >actual &&
152 git diff expect actual &&
154 printf "$ttt$ttt$ttt\n" > expect &&
155 printf "\n\n\n$ttt$ttt$ttt\n" | git stripspace >actual &&
156 git diff expect actual &&
158 printf "$ttt$ttt$ttt$ttt\n" > expect &&
159 printf "\n\n\n$ttt$ttt$ttt$ttt\n" | git stripspace >actual &&
160 git diff expect actual &&
162 printf "$ttt\n" > expect &&
164 printf "$sss\n$sss\n$sss\n$ttt\n" | git stripspace >actual &&
165 git diff expect actual &&
167 printf "\n$sss\n$sss$sss\n$ttt\n" | git stripspace >actual &&
168 git diff expect actual &&
170 printf "$sss$sss\n$sss\n\n$ttt\n" | git stripspace >actual &&
171 git diff expect actual &&
173 printf "$sss$sss$sss\n\n\n$ttt\n" | git stripspace >actual &&
174 git diff expect actual &&
176 printf "\n$sss$sss$sss\n\n$ttt\n" | git stripspace >actual &&
177 git diff expect actual &&
179 printf "\n\n$sss$sss$sss\n$ttt\n" | git stripspace >actual &&
180 git diff expect actual
183 test_expect_success \
184 'consecutive blank lines at the end should be removed' '
185 printf "$ttt\n" > expect &&
186 printf "$ttt\n\n" | git stripspace >actual &&
187 git diff expect actual &&
189 printf "$ttt\n" > expect &&
190 printf "$ttt\n\n\n\n" | git stripspace >actual &&
191 git diff expect actual &&
193 printf "$ttt$ttt\n" > expect &&
194 printf "$ttt$ttt\n\n\n\n" | git stripspace >actual &&
195 git diff expect actual &&
197 printf "$ttt$ttt$ttt\n" > expect &&
198 printf "$ttt$ttt$ttt\n\n\n\n" | git stripspace >actual &&
199 git diff expect actual &&
201 printf "$ttt$ttt$ttt$ttt\n" > expect &&
202 printf "$ttt$ttt$ttt$ttt\n\n\n\n" | git stripspace >actual &&
203 git diff expect actual &&
205 printf "$ttt\n" > expect &&
207 printf "$ttt\n$sss\n$sss\n$sss\n" | git stripspace >actual &&
208 git diff expect actual &&
210 printf "$ttt\n\n$sss\n$sss$sss\n" | git stripspace >actual &&
211 git diff expect actual &&
213 printf "$ttt\n$sss$sss\n$sss\n\n" | git stripspace >actual &&
214 git diff expect actual &&
216 printf "$ttt\n$sss$sss$sss\n\n\n" | git stripspace >actual &&
217 git diff expect actual &&
219 printf "$ttt\n\n$sss$sss$sss\n\n" | git stripspace >actual &&
220 git diff expect actual &&
222 printf "$ttt\n\n\n$sss$sss$sss\n" | git stripspace >actual &&
223 git diff expect actual
226 test_expect_success \
227 'text without newline at end should end with newline' '
228 test `printf "$ttt" | git stripspace | wc -l` -gt 0 &&
229 test `printf "$ttt$ttt" | git stripspace | wc -l` -gt 0 &&
230 test `printf "$ttt$ttt$ttt" | git stripspace | wc -l` -gt 0 &&
231 test `printf "$ttt$ttt$ttt$ttt" | git stripspace | wc -l` -gt 0
234 # text plus spaces at the end:
236 test_expect_success \
237 'text plus spaces without newline at end should end with newline' '
238 test `printf "$ttt$sss" | git stripspace | wc -l` -gt 0 &&
239 test `printf "$ttt$ttt$sss" | git stripspace | wc -l` -gt 0 &&
240 test `printf "$ttt$ttt$ttt$sss" | git stripspace | wc -l` -gt 0 &&
241 test `printf "$ttt$sss$sss" | git stripspace | wc -l` -gt 0 &&
242 test `printf "$ttt$ttt$sss$sss" | git stripspace | wc -l` -gt 0 &&
243 test `printf "$ttt$sss$sss$sss" | git stripspace | wc -l` -gt 0
246 test_expect_failure \
247 'text plus spaces without newline at end should not show spaces' '
248 printf "$ttt$sss" | git stripspace | grep -q " " ||
249 printf "$ttt$ttt$sss" | git stripspace | grep -q " " ||
250 printf "$ttt$ttt$ttt$sss" | git stripspace | grep -q " " ||
251 printf "$ttt$sss$sss" | git stripspace | grep -q " " ||
252 printf "$ttt$ttt$sss$sss" | git stripspace | grep -q " " ||
253 printf "$ttt$sss$sss$sss" | git stripspace | grep -q " "
256 test_expect_success \
257 'text plus spaces without newline should show the correct lines' '
258 printf "$ttt\n" >expect &&
259 printf "$ttt$sss" | git stripspace >actual &&
260 git diff expect actual &&
262 printf "$ttt\n" >expect &&
263 printf "$ttt$sss$sss" | git stripspace >actual &&
264 git diff expect actual &&
266 printf "$ttt\n" >expect &&
267 printf "$ttt$sss$sss$sss" | git stripspace >actual &&
268 git diff expect actual &&
270 printf "$ttt$ttt\n" >expect &&
271 printf "$ttt$ttt$sss" | git stripspace >actual &&
272 git diff expect actual &&
274 printf "$ttt$ttt\n" >expect &&
275 printf "$ttt$ttt$sss$sss" | git stripspace >actual &&
276 git diff expect actual &&
278 printf "$ttt$ttt$ttt\n" >expect &&
279 printf "$ttt$ttt$ttt$sss" | git stripspace >actual &&
280 git diff expect actual
283 test_expect_failure \
284 'text plus spaces at end should not show spaces' '
285 echo "$ttt$sss" | git stripspace | grep -q " " ||
286 echo "$ttt$ttt$sss" | git stripspace | grep -q " " ||
287 echo "$ttt$ttt$ttt$sss" | git stripspace | grep -q " " ||
288 echo "$ttt$sss$sss" | git stripspace | grep -q " " ||
289 echo "$ttt$ttt$sss$sss" | git stripspace | grep -q " " ||
290 echo "$ttt$sss$sss$sss" | git stripspace | grep -q " "
293 test_expect_success \
294 'text plus spaces at end should be cleaned and newline must remain' '
295 echo "$ttt" >expect &&
296 echo "$ttt$sss" | git stripspace >actual &&
297 git diff expect actual &&
299 echo "$ttt" >expect &&
300 echo "$ttt$sss$sss" | git stripspace >actual &&
301 git diff expect actual &&
303 echo "$ttt" >expect &&
304 echo "$ttt$sss$sss$sss" | git stripspace >actual &&
305 git diff expect actual &&
307 echo "$ttt$ttt" >expect &&
308 echo "$ttt$ttt$sss" | git stripspace >actual &&
309 git diff expect actual &&
311 echo "$ttt$ttt" >expect &&
312 echo "$ttt$ttt$sss$sss" | git stripspace >actual &&
313 git diff expect actual &&
315 echo "$ttt$ttt$ttt" >expect &&
316 echo "$ttt$ttt$ttt$sss" | git stripspace >actual &&
317 git diff expect actual
320 # spaces only:
322 test_expect_success \
323 'spaces with newline at end should be replaced with empty string' '
324 printf "" >expect &&
326 echo | git stripspace >actual &&
327 git diff expect actual &&
329 echo "$sss" | git stripspace >actual &&
330 git diff expect actual &&
332 echo "$sss$sss" | git stripspace >actual &&
333 git diff expect actual &&
335 echo "$sss$sss$sss" | git stripspace >actual &&
336 git diff expect actual &&
338 echo "$sss$sss$sss$sss" | git stripspace >actual &&
339 git diff expect actual
342 test_expect_failure \
343 'spaces without newline at end should not show spaces' '
344 printf "" | git stripspace | grep -q " " ||
345 printf "$sss" | git stripspace | grep -q " " ||
346 printf "$sss$sss" | git stripspace | grep -q " " ||
347 printf "$sss$sss$sss" | git stripspace | grep -q " " ||
348 printf "$sss$sss$sss$sss" | git stripspace | grep -q " "
351 test_expect_success \
352 'spaces without newline at end should be replaced with empty string' '
353 printf "" >expect &&
355 printf "" | git stripspace >actual &&
356 git diff expect actual &&
358 printf "$sss$sss" | git stripspace >actual &&
359 git diff expect actual &&
361 printf "$sss$sss$sss" | git stripspace >actual &&
362 git diff expect actual &&
364 printf "$sss$sss$sss$sss" | git stripspace >actual &&
365 git diff expect actual
368 test_expect_success \
369 'consecutive text lines should be unchanged' '
370 printf "$ttt$ttt\n$ttt\n" >expect &&
371 printf "$ttt$ttt\n$ttt\n" | git stripspace >actual &&
372 git diff expect actual &&
374 printf "$ttt\n$ttt$ttt\n$ttt\n" >expect &&
375 printf "$ttt\n$ttt$ttt\n$ttt\n" | git stripspace >actual &&
376 git diff expect actual &&
378 printf "$ttt\n$ttt\n$ttt\n$ttt$ttt\n" >expect &&
379 printf "$ttt\n$ttt\n$ttt\n$ttt$ttt\n" | git stripspace >actual &&
380 git diff expect actual &&
382 printf "$ttt\n$ttt\n\n$ttt$ttt\n$ttt\n" >expect &&
383 printf "$ttt\n$ttt\n\n$ttt$ttt\n$ttt\n" | git stripspace >actual &&
384 git diff expect actual &&
386 printf "$ttt$ttt\n\n$ttt\n$ttt$ttt\n" >expect &&
387 printf "$ttt$ttt\n\n$ttt\n$ttt$ttt\n" | git stripspace >actual &&
388 git diff expect actual &&
390 printf "$ttt\n$ttt$ttt\n\n$ttt\n" >expect &&
391 printf "$ttt\n$ttt$ttt\n\n$ttt\n" | git stripspace >actual &&
392 git diff expect actual
395 test_expect_success 'strip comments, too' '
396 test ! -z "$(echo "# comment" | git stripspace)" &&
397 test -z "$(echo "# comment" | git stripspace -s)"
400 test_done