Merge branch 'ma/reset-doc-rendering-fix'
[git/debian.git] / t / t0030-stripspace.sh
blob5ce47e8af51d63c7bd294e6f7582f10e4891566d
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 test_cmp expect actual &&
21 echo "$ttt$ttt" >expect &&
22 git stripspace <expect >actual &&
23 test_cmp expect actual &&
25 echo "$ttt$ttt$ttt" >expect &&
26 git stripspace <expect >actual &&
27 test_cmp expect actual &&
29 echo "$ttt$ttt$ttt$ttt" >expect &&
30 git stripspace <expect >actual &&
31 test_cmp 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 test_cmp expect actual &&
40 echo "$sss$sss$ttt" >expect &&
41 git stripspace <expect >actual &&
42 test_cmp expect actual &&
44 echo "$sss$sss$sss$ttt" >expect &&
45 git stripspace <expect >actual &&
46 test_cmp 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 test_cmp expect actual &&
55 echo "$ttt$sss$sss$ttt" >expect &&
56 git stripspace <expect >actual &&
57 test_cmp 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 test_cmp 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 test_cmp 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 test_cmp expect actual &&
74 printf "$ttt\n\n$ttt\n" > expect &&
75 printf "$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
76 test_cmp 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 test_cmp 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 test_cmp 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 test_cmp 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 test_cmp 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 test_cmp 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 test_cmp 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 test_cmp 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 test_cmp expect actual
111 test_expect_success \
112 'only consecutive blank lines should be completely removed' '
114 printf "\n" | git stripspace >actual &&
115 test_must_be_empty actual &&
117 printf "\n\n\n" | git stripspace >actual &&
118 test_must_be_empty actual &&
120 printf "$sss\n$sss\n$sss\n" | git stripspace >actual &&
121 test_must_be_empty actual &&
123 printf "$sss$sss\n$sss\n\n" | git stripspace >actual &&
124 test_must_be_empty actual &&
126 printf "\n$sss\n$sss$sss\n" | git stripspace >actual &&
127 test_must_be_empty actual &&
129 printf "$sss$sss$sss$sss\n\n\n" | git stripspace >actual &&
130 test_must_be_empty actual &&
132 printf "\n$sss$sss$sss$sss\n\n" | git stripspace >actual &&
133 test_must_be_empty actual &&
135 printf "\n\n$sss$sss$sss$sss\n" | git stripspace >actual &&
136 test_must_be_empty actual
139 test_expect_success \
140 'consecutive blank lines at the beginning should be removed' '
141 printf "$ttt\n" > expect &&
142 printf "\n$ttt\n" | git stripspace >actual &&
143 test_cmp expect actual &&
145 printf "$ttt\n" > expect &&
146 printf "\n\n\n$ttt\n" | git stripspace >actual &&
147 test_cmp expect actual &&
149 printf "$ttt$ttt\n" > expect &&
150 printf "\n\n\n$ttt$ttt\n" | git stripspace >actual &&
151 test_cmp expect actual &&
153 printf "$ttt$ttt$ttt\n" > expect &&
154 printf "\n\n\n$ttt$ttt$ttt\n" | git stripspace >actual &&
155 test_cmp expect actual &&
157 printf "$ttt$ttt$ttt$ttt\n" > expect &&
158 printf "\n\n\n$ttt$ttt$ttt$ttt\n" | git stripspace >actual &&
159 test_cmp expect actual &&
161 printf "$ttt\n" > expect &&
163 printf "$sss\n$sss\n$sss\n$ttt\n" | git stripspace >actual &&
164 test_cmp expect actual &&
166 printf "\n$sss\n$sss$sss\n$ttt\n" | git stripspace >actual &&
167 test_cmp expect actual &&
169 printf "$sss$sss\n$sss\n\n$ttt\n" | git stripspace >actual &&
170 test_cmp expect actual &&
172 printf "$sss$sss$sss\n\n\n$ttt\n" | git stripspace >actual &&
173 test_cmp expect actual &&
175 printf "\n$sss$sss$sss\n\n$ttt\n" | git stripspace >actual &&
176 test_cmp expect actual &&
178 printf "\n\n$sss$sss$sss\n$ttt\n" | git stripspace >actual &&
179 test_cmp expect actual
182 test_expect_success \
183 'consecutive blank lines at the end should be removed' '
184 printf "$ttt\n" > expect &&
185 printf "$ttt\n\n" | git stripspace >actual &&
186 test_cmp expect actual &&
188 printf "$ttt\n" > expect &&
189 printf "$ttt\n\n\n\n" | git stripspace >actual &&
190 test_cmp expect actual &&
192 printf "$ttt$ttt\n" > expect &&
193 printf "$ttt$ttt\n\n\n\n" | git stripspace >actual &&
194 test_cmp expect actual &&
196 printf "$ttt$ttt$ttt\n" > expect &&
197 printf "$ttt$ttt$ttt\n\n\n\n" | git stripspace >actual &&
198 test_cmp expect actual &&
200 printf "$ttt$ttt$ttt$ttt\n" > expect &&
201 printf "$ttt$ttt$ttt$ttt\n\n\n\n" | git stripspace >actual &&
202 test_cmp expect actual &&
204 printf "$ttt\n" > expect &&
206 printf "$ttt\n$sss\n$sss\n$sss\n" | git stripspace >actual &&
207 test_cmp expect actual &&
209 printf "$ttt\n\n$sss\n$sss$sss\n" | git stripspace >actual &&
210 test_cmp expect actual &&
212 printf "$ttt\n$sss$sss\n$sss\n\n" | git stripspace >actual &&
213 test_cmp expect actual &&
215 printf "$ttt\n$sss$sss$sss\n\n\n" | git stripspace >actual &&
216 test_cmp expect actual &&
218 printf "$ttt\n\n$sss$sss$sss\n\n" | git stripspace >actual &&
219 test_cmp expect actual &&
221 printf "$ttt\n\n\n$sss$sss$sss\n" | git stripspace >actual &&
222 test_cmp expect actual
225 test_expect_success \
226 'text without newline at end should end with newline' '
227 test $(printf "$ttt" | git stripspace | wc -l) -gt 0 &&
228 test $(printf "$ttt$ttt" | git stripspace | wc -l) -gt 0 &&
229 test $(printf "$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0 &&
230 test $(printf "$ttt$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0
233 # text plus spaces at the end:
235 test_expect_success \
236 'text plus spaces without newline at end should end with newline' '
237 test $(printf "$ttt$sss" | git stripspace | wc -l) -gt 0 &&
238 test $(printf "$ttt$ttt$sss" | git stripspace | wc -l) -gt 0 &&
239 test $(printf "$ttt$ttt$ttt$sss" | git stripspace | wc -l) -gt 0 &&
240 test $(printf "$ttt$sss$sss" | git stripspace | wc -l) -gt 0 &&
241 test $(printf "$ttt$ttt$sss$sss" | git stripspace | wc -l) -gt 0 &&
242 test $(printf "$ttt$sss$sss$sss" | git stripspace | wc -l) -gt 0
245 test_expect_success \
246 'text plus spaces without newline at end should not show spaces' '
247 ! (printf "$ttt$sss" | git stripspace | grep " " >/dev/null) &&
248 ! (printf "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
249 ! (printf "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
250 ! (printf "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
251 ! (printf "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
252 ! (printf "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null)
255 test_expect_success \
256 'text plus spaces without newline should show the correct lines' '
257 printf "$ttt\n" >expect &&
258 printf "$ttt$sss" | git stripspace >actual &&
259 test_cmp expect actual &&
261 printf "$ttt\n" >expect &&
262 printf "$ttt$sss$sss" | git stripspace >actual &&
263 test_cmp expect actual &&
265 printf "$ttt\n" >expect &&
266 printf "$ttt$sss$sss$sss" | git stripspace >actual &&
267 test_cmp expect actual &&
269 printf "$ttt$ttt\n" >expect &&
270 printf "$ttt$ttt$sss" | git stripspace >actual &&
271 test_cmp expect actual &&
273 printf "$ttt$ttt\n" >expect &&
274 printf "$ttt$ttt$sss$sss" | git stripspace >actual &&
275 test_cmp expect actual &&
277 printf "$ttt$ttt$ttt\n" >expect &&
278 printf "$ttt$ttt$ttt$sss" | git stripspace >actual &&
279 test_cmp expect actual
282 test_expect_success \
283 'text plus spaces at end should not show spaces' '
284 ! (echo "$ttt$sss" | git stripspace | grep " " >/dev/null) &&
285 ! (echo "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
286 ! (echo "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
287 ! (echo "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
288 ! (echo "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
289 ! (echo "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null)
292 test_expect_success \
293 'text plus spaces at end should be cleaned and newline must remain' '
294 echo "$ttt" >expect &&
295 echo "$ttt$sss" | git stripspace >actual &&
296 test_cmp expect actual &&
298 echo "$ttt" >expect &&
299 echo "$ttt$sss$sss" | git stripspace >actual &&
300 test_cmp expect actual &&
302 echo "$ttt" >expect &&
303 echo "$ttt$sss$sss$sss" | git stripspace >actual &&
304 test_cmp expect actual &&
306 echo "$ttt$ttt" >expect &&
307 echo "$ttt$ttt$sss" | git stripspace >actual &&
308 test_cmp expect actual &&
310 echo "$ttt$ttt" >expect &&
311 echo "$ttt$ttt$sss$sss" | git stripspace >actual &&
312 test_cmp expect actual &&
314 echo "$ttt$ttt$ttt" >expect &&
315 echo "$ttt$ttt$ttt$sss" | git stripspace >actual &&
316 test_cmp expect actual
319 # spaces only:
321 test_expect_success \
322 'spaces with newline at end should be replaced with empty string' '
323 echo | git stripspace >actual &&
324 test_must_be_empty actual &&
326 echo "$sss" | git stripspace >actual &&
327 test_must_be_empty actual &&
329 echo "$sss$sss" | git stripspace >actual &&
330 test_must_be_empty actual &&
332 echo "$sss$sss$sss" | git stripspace >actual &&
333 test_must_be_empty actual &&
335 echo "$sss$sss$sss$sss" | git stripspace >actual &&
336 test_must_be_empty actual
339 test_expect_success \
340 'spaces without newline at end should not show spaces' '
341 ! (printf "" | git stripspace | grep " " >/dev/null) &&
342 ! (printf "$sss" | git stripspace | grep " " >/dev/null) &&
343 ! (printf "$sss$sss" | git stripspace | grep " " >/dev/null) &&
344 ! (printf "$sss$sss$sss" | git stripspace | grep " " >/dev/null) &&
345 ! (printf "$sss$sss$sss$sss" | git stripspace | grep " " >/dev/null)
348 test_expect_success \
349 'spaces without newline at end should be replaced with empty string' '
350 printf "" | git stripspace >actual &&
351 test_must_be_empty actual &&
353 printf "$sss$sss" | git stripspace >actual &&
354 test_must_be_empty actual &&
356 printf "$sss$sss$sss" | git stripspace >actual &&
357 test_must_be_empty actual &&
359 printf "$sss$sss$sss$sss" | git stripspace >actual &&
360 test_must_be_empty actual
363 test_expect_success \
364 'consecutive text lines should be unchanged' '
365 printf "$ttt$ttt\n$ttt\n" >expect &&
366 printf "$ttt$ttt\n$ttt\n" | git stripspace >actual &&
367 test_cmp expect actual &&
369 printf "$ttt\n$ttt$ttt\n$ttt\n" >expect &&
370 printf "$ttt\n$ttt$ttt\n$ttt\n" | git stripspace >actual &&
371 test_cmp expect actual &&
373 printf "$ttt\n$ttt\n$ttt\n$ttt$ttt\n" >expect &&
374 printf "$ttt\n$ttt\n$ttt\n$ttt$ttt\n" | git stripspace >actual &&
375 test_cmp expect actual &&
377 printf "$ttt\n$ttt\n\n$ttt$ttt\n$ttt\n" >expect &&
378 printf "$ttt\n$ttt\n\n$ttt$ttt\n$ttt\n" | git stripspace >actual &&
379 test_cmp expect actual &&
381 printf "$ttt$ttt\n\n$ttt\n$ttt$ttt\n" >expect &&
382 printf "$ttt$ttt\n\n$ttt\n$ttt$ttt\n" | git stripspace >actual &&
383 test_cmp expect actual &&
385 printf "$ttt\n$ttt$ttt\n\n$ttt\n" >expect &&
386 printf "$ttt\n$ttt$ttt\n\n$ttt\n" | git stripspace >actual &&
387 test_cmp expect actual
390 test_expect_success 'strip comments, too' '
391 test ! -z "$(echo "# comment" | git stripspace)" &&
392 test -z "$(echo "# comment" | git stripspace -s)"
395 test_expect_success 'strip comments with changed comment char' '
396 test ! -z "$(echo "; comment" | git -c core.commentchar=";" stripspace)" &&
397 test -z "$(echo "; comment" | git -c core.commentchar=";" stripspace -s)"
400 test_expect_success '-c with single line' '
401 printf "# foo\n" >expect &&
402 printf "foo" | git stripspace -c >actual &&
403 test_cmp expect actual
406 test_expect_success '-c with single line followed by empty line' '
407 printf "# foo\n#\n" >expect &&
408 printf "foo\n\n" | git stripspace -c >actual &&
409 test_cmp expect actual
412 test_expect_success '-c with newline only' '
413 printf "#\n" >expect &&
414 printf "\n" | git stripspace -c >actual &&
415 test_cmp expect actual
418 test_expect_success '--comment-lines with single line' '
419 printf "# foo\n" >expect &&
420 printf "foo" | git stripspace -c >actual &&
421 test_cmp expect actual
424 test_expect_success '-c with changed comment char' '
425 printf "; foo\n" >expect &&
426 printf "foo" | git -c core.commentchar=";" stripspace -c >actual &&
427 test_cmp expect actual
430 test_expect_success '-c with comment char defined in .git/config' '
431 test_config core.commentchar = &&
432 printf "= foo\n" >expect &&
433 printf "foo" | (
434 mkdir sub && cd sub && git stripspace -c
435 ) >actual &&
436 test_cmp expect actual
439 test_expect_success 'avoid SP-HT sequence in commented line' '
440 printf "#\tone\n#\n# two\n" >expect &&
441 printf "\tone\n\ntwo\n" | git stripspace -c >actual &&
442 test_cmp expect actual
445 test_done