]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0030-stripspace.sh
l10n: fr v2.23.0 round 2
[thirdparty/git.git] / t / t0030-stripspace.sh
CommitLineData
30d038e2
CR
1#!/bin/sh
2#
3# Copyright (c) 2007 Carlos Rica
4#
5
5be60078 6test_description='git stripspace'
30d038e2
CR
7
8. ./test-lib.sh
9
10t40='A quick brown fox jumps over the lazy do'
11s40=' '
12sss="$s40$s40$s40$s40$s40$s40$s40$s40$s40$s40" # 400
13ttt="$t40$t40$t40$t40$t40$t40$t40$t40$t40$t40" # 400
14
15test_expect_success \
16 'long lines without spaces should be unchanged' '
17 echo "$ttt" >expect &&
5be60078 18 git stripspace <expect >actual &&
3af82863 19 test_cmp expect actual &&
30d038e2
CR
20
21 echo "$ttt$ttt" >expect &&
5be60078 22 git stripspace <expect >actual &&
3af82863 23 test_cmp expect actual &&
30d038e2
CR
24
25 echo "$ttt$ttt$ttt" >expect &&
5be60078 26 git stripspace <expect >actual &&
3af82863 27 test_cmp expect actual &&
30d038e2
CR
28
29 echo "$ttt$ttt$ttt$ttt" >expect &&
5be60078 30 git stripspace <expect >actual &&
3af82863 31 test_cmp expect actual
30d038e2
CR
32'
33
34test_expect_success \
35 'lines with spaces at the beginning should be unchanged' '
36 echo "$sss$ttt" >expect &&
5be60078 37 git stripspace <expect >actual &&
3af82863 38 test_cmp expect actual &&
30d038e2
CR
39
40 echo "$sss$sss$ttt" >expect &&
5be60078 41 git stripspace <expect >actual &&
3af82863 42 test_cmp expect actual &&
30d038e2
CR
43
44 echo "$sss$sss$sss$ttt" >expect &&
5be60078 45 git stripspace <expect >actual &&
3af82863 46 test_cmp expect actual
30d038e2
CR
47'
48
49test_expect_success \
50 'lines with intermediate spaces should be unchanged' '
51 echo "$ttt$sss$ttt" >expect &&
5be60078 52 git stripspace <expect >actual &&
3af82863 53 test_cmp expect actual &&
30d038e2
CR
54
55 echo "$ttt$sss$sss$ttt" >expect &&
5be60078 56 git stripspace <expect >actual &&
3af82863 57 test_cmp expect actual
30d038e2
CR
58'
59
60test_expect_success \
61 'consecutive blank lines should be unified' '
62 printf "$ttt\n\n$ttt\n" > expect &&
5be60078 63 printf "$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
3af82863 64 test_cmp expect actual &&
30d038e2
CR
65
66 printf "$ttt$ttt\n\n$ttt\n" > expect &&
5be60078 67 printf "$ttt$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
3af82863 68 test_cmp expect actual &&
30d038e2
CR
69
70 printf "$ttt$ttt$ttt\n\n$ttt\n" > expect &&
5be60078 71 printf "$ttt$ttt$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
3af82863 72 test_cmp expect actual &&
30d038e2
CR
73
74 printf "$ttt\n\n$ttt\n" > expect &&
5be60078 75 printf "$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
3af82863 76 test_cmp expect actual &&
30d038e2
CR
77
78 printf "$ttt\n\n$ttt$ttt\n" > expect &&
5be60078 79 printf "$ttt\n\n\n\n\n$ttt$ttt\n" | git stripspace >actual &&
3af82863 80 test_cmp expect actual &&
30d038e2
CR
81
82 printf "$ttt\n\n$ttt$ttt$ttt\n" > expect &&
5be60078 83 printf "$ttt\n\n\n\n\n$ttt$ttt$ttt\n" | git stripspace >actual &&
3af82863 84 test_cmp expect actual &&
b61a8a67
CR
85
86 printf "$ttt\n\n$ttt\n" > expect &&
87 printf "$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
3af82863 88 test_cmp expect actual &&
b61a8a67
CR
89
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 &&
3af82863 92 test_cmp expect actual &&
b61a8a67
CR
93
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 &&
3af82863 96 test_cmp expect actual &&
b61a8a67
CR
97
98 printf "$ttt\n\n$ttt\n" > expect &&
99 printf "$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
3af82863 100 test_cmp expect actual &&
b61a8a67
CR
101
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 &&
3af82863 104 test_cmp expect actual &&
b61a8a67
CR
105
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 &&
3af82863 108 test_cmp expect actual
30d038e2
CR
109'
110
111test_expect_success \
defd5314 112 'only consecutive blank lines should be completely removed' '
defd5314 113
5be60078 114 printf "\n" | git stripspace >actual &&
d3c6751b 115 test_must_be_empty actual &&
30d038e2 116
5be60078 117 printf "\n\n\n" | git stripspace >actual &&
d3c6751b 118 test_must_be_empty actual &&
30d038e2 119
5be60078 120 printf "$sss\n$sss\n$sss\n" | git stripspace >actual &&
d3c6751b 121 test_must_be_empty actual &&
30d038e2 122
5be60078 123 printf "$sss$sss\n$sss\n\n" | git stripspace >actual &&
d3c6751b 124 test_must_be_empty actual &&
30d038e2 125
5be60078 126 printf "\n$sss\n$sss$sss\n" | git stripspace >actual &&
d3c6751b 127 test_must_be_empty actual &&
30d038e2 128
5be60078 129 printf "$sss$sss$sss$sss\n\n\n" | git stripspace >actual &&
d3c6751b 130 test_must_be_empty actual &&
30d038e2 131
5be60078 132 printf "\n$sss$sss$sss$sss\n\n" | git stripspace >actual &&
d3c6751b 133 test_must_be_empty actual &&
30d038e2 134
5be60078 135 printf "\n\n$sss$sss$sss$sss\n" | git stripspace >actual &&
d3c6751b 136 test_must_be_empty actual
defd5314 137'
30d038e2 138
defd5314
CR
139test_expect_success \
140 'consecutive blank lines at the beginning should be removed' '
30d038e2 141 printf "$ttt\n" > expect &&
5be60078 142 printf "\n$ttt\n" | git stripspace >actual &&
3af82863 143 test_cmp expect actual &&
30d038e2
CR
144
145 printf "$ttt\n" > expect &&
5be60078 146 printf "\n\n\n$ttt\n" | git stripspace >actual &&
3af82863 147 test_cmp expect actual &&
30d038e2
CR
148
149 printf "$ttt$ttt\n" > expect &&
5be60078 150 printf "\n\n\n$ttt$ttt\n" | git stripspace >actual &&
3af82863 151 test_cmp expect actual &&
30d038e2
CR
152
153 printf "$ttt$ttt$ttt\n" > expect &&
5be60078 154 printf "\n\n\n$ttt$ttt$ttt\n" | git stripspace >actual &&
3af82863 155 test_cmp expect actual &&
30d038e2
CR
156
157 printf "$ttt$ttt$ttt$ttt\n" > expect &&
5be60078 158 printf "\n\n\n$ttt$ttt$ttt$ttt\n" | git stripspace >actual &&
3af82863 159 test_cmp expect actual &&
30d038e2
CR
160
161 printf "$ttt\n" > expect &&
defd5314 162
5be60078 163 printf "$sss\n$sss\n$sss\n$ttt\n" | git stripspace >actual &&
3af82863 164 test_cmp expect actual &&
30d038e2 165
5be60078 166 printf "\n$sss\n$sss$sss\n$ttt\n" | git stripspace >actual &&
3af82863 167 test_cmp expect actual &&
30d038e2 168
5be60078 169 printf "$sss$sss\n$sss\n\n$ttt\n" | git stripspace >actual &&
3af82863 170 test_cmp expect actual &&
30d038e2 171
5be60078 172 printf "$sss$sss$sss\n\n\n$ttt\n" | git stripspace >actual &&
3af82863 173 test_cmp expect actual &&
30d038e2 174
5be60078 175 printf "\n$sss$sss$sss\n\n$ttt\n" | git stripspace >actual &&
3af82863 176 test_cmp expect actual &&
30d038e2 177
5be60078 178 printf "\n\n$sss$sss$sss\n$ttt\n" | git stripspace >actual &&
3af82863 179 test_cmp expect actual
30d038e2
CR
180'
181
182test_expect_success \
183 'consecutive blank lines at the end should be removed' '
184 printf "$ttt\n" > expect &&
5be60078 185 printf "$ttt\n\n" | git stripspace >actual &&
3af82863 186 test_cmp expect actual &&
30d038e2
CR
187
188 printf "$ttt\n" > expect &&
5be60078 189 printf "$ttt\n\n\n\n" | git stripspace >actual &&
3af82863 190 test_cmp expect actual &&
30d038e2
CR
191
192 printf "$ttt$ttt\n" > expect &&
5be60078 193 printf "$ttt$ttt\n\n\n\n" | git stripspace >actual &&
3af82863 194 test_cmp expect actual &&
30d038e2
CR
195
196 printf "$ttt$ttt$ttt\n" > expect &&
5be60078 197 printf "$ttt$ttt$ttt\n\n\n\n" | git stripspace >actual &&
3af82863 198 test_cmp expect actual &&
30d038e2
CR
199
200 printf "$ttt$ttt$ttt$ttt\n" > expect &&
5be60078 201 printf "$ttt$ttt$ttt$ttt\n\n\n\n" | git stripspace >actual &&
3af82863 202 test_cmp expect actual &&
30d038e2
CR
203
204 printf "$ttt\n" > expect &&
defd5314 205
5be60078 206 printf "$ttt\n$sss\n$sss\n$sss\n" | git stripspace >actual &&
3af82863 207 test_cmp expect actual &&
30d038e2 208
5be60078 209 printf "$ttt\n\n$sss\n$sss$sss\n" | git stripspace >actual &&
3af82863 210 test_cmp expect actual &&
30d038e2 211
5be60078 212 printf "$ttt\n$sss$sss\n$sss\n\n" | git stripspace >actual &&
3af82863 213 test_cmp expect actual &&
30d038e2 214
5be60078 215 printf "$ttt\n$sss$sss$sss\n\n\n" | git stripspace >actual &&
3af82863 216 test_cmp expect actual &&
30d038e2 217
5be60078 218 printf "$ttt\n\n$sss$sss$sss\n\n" | git stripspace >actual &&
3af82863 219 test_cmp expect actual &&
30d038e2 220
5be60078 221 printf "$ttt\n\n\n$sss$sss$sss\n" | git stripspace >actual &&
3af82863 222 test_cmp expect actual
30d038e2
CR
223'
224
225test_expect_success \
226 'text without newline at end should end with newline' '
4d713567
EP
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
30d038e2
CR
231'
232
233# text plus spaces at the end:
234
235test_expect_success \
236 'text plus spaces without newline at end should end with newline' '
4d713567
EP
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
30d038e2
CR
243'
244
41ac414e 245test_expect_success \
30d038e2 246 'text plus spaces without newline at end should not show spaces' '
aadbe44f
JK
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)
30d038e2
CR
253'
254
255test_expect_success \
256 'text plus spaces without newline should show the correct lines' '
257 printf "$ttt\n" >expect &&
5be60078 258 printf "$ttt$sss" | git stripspace >actual &&
3af82863 259 test_cmp expect actual &&
30d038e2
CR
260
261 printf "$ttt\n" >expect &&
5be60078 262 printf "$ttt$sss$sss" | git stripspace >actual &&
3af82863 263 test_cmp expect actual &&
30d038e2
CR
264
265 printf "$ttt\n" >expect &&
5be60078 266 printf "$ttt$sss$sss$sss" | git stripspace >actual &&
3af82863 267 test_cmp expect actual &&
30d038e2
CR
268
269 printf "$ttt$ttt\n" >expect &&
5be60078 270 printf "$ttt$ttt$sss" | git stripspace >actual &&
3af82863 271 test_cmp expect actual &&
30d038e2
CR
272
273 printf "$ttt$ttt\n" >expect &&
5be60078 274 printf "$ttt$ttt$sss$sss" | git stripspace >actual &&
3af82863 275 test_cmp expect actual &&
30d038e2
CR
276
277 printf "$ttt$ttt$ttt\n" >expect &&
5be60078 278 printf "$ttt$ttt$ttt$sss" | git stripspace >actual &&
3af82863 279 test_cmp expect actual
30d038e2
CR
280'
281
41ac414e 282test_expect_success \
30d038e2 283 'text plus spaces at end should not show spaces' '
aadbe44f
JK
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)
30d038e2
CR
290'
291
292test_expect_success \
293 'text plus spaces at end should be cleaned and newline must remain' '
294 echo "$ttt" >expect &&
5be60078 295 echo "$ttt$sss" | git stripspace >actual &&
3af82863 296 test_cmp expect actual &&
30d038e2
CR
297
298 echo "$ttt" >expect &&
5be60078 299 echo "$ttt$sss$sss" | git stripspace >actual &&
3af82863 300 test_cmp expect actual &&
30d038e2
CR
301
302 echo "$ttt" >expect &&
5be60078 303 echo "$ttt$sss$sss$sss" | git stripspace >actual &&
3af82863 304 test_cmp expect actual &&
30d038e2
CR
305
306 echo "$ttt$ttt" >expect &&
5be60078 307 echo "$ttt$ttt$sss" | git stripspace >actual &&
3af82863 308 test_cmp expect actual &&
30d038e2
CR
309
310 echo "$ttt$ttt" >expect &&
5be60078 311 echo "$ttt$ttt$sss$sss" | git stripspace >actual &&
3af82863 312 test_cmp expect actual &&
30d038e2
CR
313
314 echo "$ttt$ttt$ttt" >expect &&
5be60078 315 echo "$ttt$ttt$ttt$sss" | git stripspace >actual &&
3af82863 316 test_cmp expect actual
30d038e2
CR
317'
318
319# spaces only:
320
321test_expect_success \
322 'spaces with newline at end should be replaced with empty string' '
5be60078 323 echo | git stripspace >actual &&
1c5e94f4 324 test_must_be_empty actual &&
30d038e2 325
5be60078 326 echo "$sss" | git stripspace >actual &&
1c5e94f4 327 test_must_be_empty actual &&
30d038e2 328
5be60078 329 echo "$sss$sss" | git stripspace >actual &&
1c5e94f4 330 test_must_be_empty actual &&
30d038e2 331
5be60078 332 echo "$sss$sss$sss" | git stripspace >actual &&
1c5e94f4 333 test_must_be_empty actual &&
30d038e2 334
5be60078 335 echo "$sss$sss$sss$sss" | git stripspace >actual &&
1c5e94f4 336 test_must_be_empty actual
30d038e2
CR
337'
338
41ac414e 339test_expect_success \
30d038e2 340 'spaces without newline at end should not show spaces' '
aadbe44f
JK
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)
30d038e2
CR
346'
347
348test_expect_success \
349 'spaces without newline at end should be replaced with empty string' '
5be60078 350 printf "" | git stripspace >actual &&
1c5e94f4 351 test_must_be_empty actual &&
30d038e2 352
5be60078 353 printf "$sss$sss" | git stripspace >actual &&
1c5e94f4 354 test_must_be_empty actual &&
30d038e2 355
5be60078 356 printf "$sss$sss$sss" | git stripspace >actual &&
1c5e94f4 357 test_must_be_empty actual &&
30d038e2 358
5be60078 359 printf "$sss$sss$sss$sss" | git stripspace >actual &&
1c5e94f4 360 test_must_be_empty actual
30d038e2
CR
361'
362
b61a8a67
CR
363test_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 &&
3af82863 367 test_cmp expect actual &&
b61a8a67
CR
368
369 printf "$ttt\n$ttt$ttt\n$ttt\n" >expect &&
370 printf "$ttt\n$ttt$ttt\n$ttt\n" | git stripspace >actual &&
3af82863 371 test_cmp expect actual &&
b61a8a67
CR
372
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 &&
3af82863 375 test_cmp expect actual &&
b61a8a67
CR
376
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 &&
3af82863 379 test_cmp expect actual &&
b61a8a67
CR
380
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 &&
3af82863 383 test_cmp expect actual &&
b61a8a67
CR
384
385 printf "$ttt\n$ttt$ttt\n\n$ttt\n" >expect &&
386 printf "$ttt\n$ttt$ttt\n\n$ttt\n" | git stripspace >actual &&
3af82863 387 test_cmp expect actual
b61a8a67
CR
388'
389
f653aee5
JS
390test_expect_success 'strip comments, too' '
391 test ! -z "$(echo "# comment" | git stripspace)" &&
392 test -z "$(echo "# comment" | git stripspace -s)"
393'
394
eff80a9f
JH
395test_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)"
398'
399
400test_expect_success '-c with single line' '
401 printf "# foo\n" >expect &&
402 printf "foo" | git stripspace -c >actual &&
403 test_cmp expect actual
404'
405
406test_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
410'
411
412test_expect_success '-c with newline only' '
413 printf "#\n" >expect &&
414 printf "\n" | git stripspace -c >actual &&
415 test_cmp expect actual
416'
417
418test_expect_success '--comment-lines with single line' '
419 printf "# foo\n" >expect &&
420 printf "foo" | git stripspace -c >actual &&
421 test_cmp expect actual
422'
423
424test_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
428'
429
92068ae8 430test_expect_success '-c with comment char defined in .git/config' '
66458388
JS
431 test_config core.commentchar = &&
432 printf "= foo\n" >expect &&
957da758
JN
433 rm -fr sub &&
434 mkdir sub &&
435 printf "foo" | git -C sub stripspace -c >actual &&
436 test_cmp expect actual
437'
438
439test_expect_success '-c outside git repository' '
440 printf "# foo\n" >expect &&
441 printf "foo" | nongit git stripspace -c >actual &&
66458388
JS
442 test_cmp expect actual
443'
444
d55aeb76
JH
445test_expect_success 'avoid SP-HT sequence in commented line' '
446 printf "#\tone\n#\n# two\n" >expect &&
447 printf "\tone\n\ntwo\n" | git stripspace -c >actual &&
448 test_cmp expect actual
449'
450
30d038e2 451test_done