3 # Copyright (c) 2007 Carlos Rica
6 test_description='git-stripspace'
10 t40='A quick brown fox jumps over the lazy do'
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
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
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
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
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
88 'consecutive blank lines at the beginning should be removed' '
90 printf "\n" | git-stripspace >actual &&
91 git diff expect actual &&
94 printf "\n\n\n" | git-stripspace >actual &&
95 git diff expect actual &&
98 printf "$sss\n$sss\n$sss\n" | git-stripspace >actual &&
99 git diff expect actual &&
101 printf "" > expect &&
102 printf "$sss$sss\n$sss\n\n" | git-stripspace >actual &&
103 git diff expect actual &&
105 printf "" > expect &&
106 printf "\n$sss\n$sss$sss\n" | git-stripspace >actual &&
107 git diff expect actual &&
109 printf "" > expect &&
110 printf "$sss$sss$sss$sss\n\n\n" | git-stripspace >actual &&
111 git diff expect actual &&
113 printf "" > expect &&
114 printf "\n$sss$sss$sss$sss\n\n" | git-stripspace >actual &&
115 git diff expect actual &&
117 printf "" > expect &&
118 printf "\n\n$sss$sss$sss$sss\n" | git-stripspace >actual &&
119 git diff expect actual &&
121 printf "$ttt\n" > expect &&
122 printf "\n$ttt\n" | git-stripspace >actual &&
123 git diff expect actual &&
125 printf "$ttt\n" > expect &&
126 printf "\n\n\n$ttt\n" | git-stripspace >actual &&
127 git diff expect actual &&
129 printf "$ttt$ttt\n" > expect &&
130 printf "\n\n\n$ttt$ttt\n" | git-stripspace >actual &&
131 git diff expect actual &&
133 printf "$ttt$ttt$ttt\n" > expect &&
134 printf "\n\n\n$ttt$ttt$ttt\n" | git-stripspace >actual &&
135 git diff expect actual &&
137 printf "$ttt$ttt$ttt$ttt\n" > expect &&
138 printf "\n\n\n$ttt$ttt$ttt$ttt\n" | git-stripspace >actual &&
139 git diff expect actual &&
141 printf "$ttt\n" > expect &&
142 printf "$sss\n$sss\n$sss\n$ttt\n" | git-stripspace >actual &&
143 git diff expect actual &&
145 printf "$ttt\n" > expect &&
146 printf "\n$sss\n$sss$sss\n$ttt\n" | git-stripspace >actual &&
147 git diff expect actual &&
149 printf "$ttt\n" > expect &&
150 printf "$sss$sss\n$sss\n\n$ttt\n" | git-stripspace >actual &&
151 git diff expect actual &&
153 printf "$ttt\n" > expect &&
154 printf "$sss$sss$sss\n\n\n$ttt\n" | git-stripspace >actual &&
155 git diff expect actual &&
157 printf "$ttt\n" > expect &&
158 printf "\n$sss$sss$sss\n\n$ttt\n" | git-stripspace >actual &&
159 git diff expect actual &&
161 printf "$ttt\n" > expect &&
162 printf "\n\n$sss$sss$sss\n$ttt\n" | git-stripspace >actual &&
163 git diff expect actual
166 test_expect_success \
167 'consecutive blank lines at the end should be removed' '
168 printf "$ttt\n" > expect &&
169 printf "$ttt\n\n" | git-stripspace >actual &&
170 git diff expect actual &&
172 printf "$ttt\n" > expect &&
173 printf "$ttt\n\n\n\n" | git-stripspace >actual &&
174 git diff expect actual &&
176 printf "$ttt$ttt\n" > expect &&
177 printf "$ttt$ttt\n\n\n\n" | git-stripspace >actual &&
178 git diff expect actual &&
180 printf "$ttt$ttt$ttt\n" > expect &&
181 printf "$ttt$ttt$ttt\n\n\n\n" | git-stripspace >actual &&
182 git diff expect actual &&
184 printf "$ttt$ttt$ttt$ttt\n" > expect &&
185 printf "$ttt$ttt$ttt$ttt\n\n\n\n" | git-stripspace >actual &&
186 git diff expect actual &&
188 printf "$ttt\n" > expect &&
189 printf "$ttt\n$sss\n$sss\n$sss\n" | git-stripspace >actual &&
190 git diff expect actual &&
192 printf "$ttt\n" > expect &&
193 printf "$ttt\n\n$sss\n$sss$sss\n" | git-stripspace >actual &&
194 git diff expect actual &&
196 printf "$ttt\n" > expect &&
197 printf "$ttt\n$sss$sss\n$sss\n\n" | git-stripspace >actual &&
198 git diff expect actual &&
200 printf "$ttt\n" > expect &&
201 printf "$ttt\n$sss$sss$sss\n\n\n" | git-stripspace >actual &&
202 git diff expect actual &&
204 printf "$ttt\n" > expect &&
205 printf "$ttt\n\n$sss$sss$sss\n\n" | git-stripspace >actual &&
206 git diff expect actual &&
208 printf "$ttt\n" > expect &&
209 printf "$ttt\n\n\n$sss$sss$sss\n" | git-stripspace >actual &&
210 git diff expect actual
213 test_expect_success \
214 'text without newline at end should end with newline' '
215 test `printf "$ttt" | git-stripspace | wc -l` -gt 0 &&
216 test `printf "$ttt$ttt" | git-stripspace | wc -l` -gt 0 &&
217 test `printf "$ttt$ttt$ttt" | git-stripspace | wc -l` -gt 0 &&
218 test `printf "$ttt$ttt$ttt$ttt" | git-stripspace | wc -l` -gt 0
221 # text plus spaces at the end:
223 test_expect_success \
224 'text plus spaces without newline at end should end with newline' '
225 test `printf "$ttt$sss" | git-stripspace | wc -l` -gt 0 &&
226 test `printf "$ttt$ttt$sss" | git-stripspace | wc -l` -gt 0 &&
227 test `printf "$ttt$ttt$ttt$sss" | git-stripspace | wc -l` -gt 0
228 test `printf "$ttt$sss$sss" | git-stripspace | wc -l` -gt 0 &&
229 test `printf "$ttt$ttt$sss$sss" | git-stripspace | wc -l` -gt 0 &&
230 test `printf "$ttt$sss$sss$sss" | git-stripspace | wc -l` -gt 0
233 test_expect_failure \
234 'text plus spaces without newline at end should not show spaces' '
235 printf "$ttt$sss" | git-stripspace | grep -q " " ||
236 printf "$ttt$ttt$sss" | git-stripspace | grep -q " " ||
237 printf "$ttt$ttt$ttt$sss" | git-stripspace | grep -q " " ||
238 printf "$ttt$sss$sss" | git-stripspace | grep -q " " ||
239 printf "$ttt$ttt$sss$sss" | git-stripspace | grep -q " " ||
240 printf "$ttt$sss$sss$sss" | git-stripspace | grep -q " "
243 test_expect_success \
244 'text plus spaces without newline should show the correct lines' '
245 printf "$ttt\n" >expect &&
246 printf "$ttt$sss" | git-stripspace >actual &&
247 git diff expect actual &&
249 printf "$ttt\n" >expect &&
250 printf "$ttt$sss$sss" | git-stripspace >actual &&
251 git diff expect actual &&
253 printf "$ttt\n" >expect &&
254 printf "$ttt$sss$sss$sss" | git-stripspace >actual &&
255 git diff expect actual &&
257 printf "$ttt$ttt\n" >expect &&
258 printf "$ttt$ttt$sss" | git-stripspace >actual &&
259 git diff expect actual &&
261 printf "$ttt$ttt\n" >expect &&
262 printf "$ttt$ttt$sss$sss" | git-stripspace >actual &&
263 git diff expect actual &&
265 printf "$ttt$ttt$ttt\n" >expect &&
266 printf "$ttt$ttt$ttt$sss" | git-stripspace >actual &&
267 git diff expect actual
270 test_expect_failure \
271 'text plus spaces at end should not show spaces' '
272 echo "$ttt$sss" | git-stripspace | grep -q " " ||
273 echo "$ttt$ttt$sss" | git-stripspace | grep -q " " ||
274 echo "$ttt$ttt$ttt$sss" | git-stripspace | grep -q " " ||
275 echo "$ttt$sss$sss" | git-stripspace | grep -q " " ||
276 echo "$ttt$ttt$sss$sss" | git-stripspace | grep -q " " ||
277 echo "$ttt$sss$sss$sss" | git-stripspace | grep -q " "
280 test_expect_success \
281 'text plus spaces at end should be cleaned and newline must remain' '
282 echo "$ttt" >expect &&
283 echo "$ttt$sss" | git-stripspace >actual &&
284 git diff expect actual &&
286 echo "$ttt" >expect &&
287 echo "$ttt$sss$sss" | git-stripspace >actual &&
288 git diff expect actual &&
290 echo "$ttt" >expect &&
291 echo "$ttt$sss$sss$sss" | git-stripspace >actual &&
292 git diff expect actual &&
294 echo "$ttt$ttt" >expect &&
295 echo "$ttt$ttt$sss" | git-stripspace >actual &&
296 git diff expect actual &&
298 echo "$ttt$ttt" >expect &&
299 echo "$ttt$ttt$sss$sss" | git-stripspace >actual &&
300 git diff expect actual &&
302 echo "$ttt$ttt$ttt" >expect &&
303 echo "$ttt$ttt$ttt$sss" | git-stripspace >actual &&
304 git diff expect actual
309 test_expect_success \
310 'spaces with newline at end should be replaced with empty string' '
313 echo | git-stripspace >actual &&
314 git diff expect actual &&
316 echo "$sss" | git-stripspace >actual &&
317 git diff expect actual &&
319 echo "$sss$sss" | git-stripspace >actual &&
320 git diff expect actual &&
322 echo "$sss$sss$sss" | git-stripspace >actual &&
323 git diff expect actual &&
325 echo "$sss$sss$sss$sss" | git-stripspace >actual &&
326 git diff expect actual
329 test_expect_failure \
330 'spaces without newline at end should not show spaces' '
331 printf "" | git-stripspace | grep -q " " ||
332 printf "$sss" | git-stripspace | grep -q " " ||
333 printf "$sss$sss" | git-stripspace | grep -q " " ||
334 printf "$sss$sss$sss" | git-stripspace | grep -q " " ||
335 printf "$sss$sss$sss$sss" | git-stripspace | grep -q " "
338 test_expect_success \
339 'spaces without newline at end should be replaced with empty string' '
342 printf "" | git-stripspace >actual &&
343 git diff expect actual
345 printf "$sss$sss" | git-stripspace >actual &&
346 git diff expect actual
348 printf "$sss$sss$sss" | git-stripspace >actual &&
349 git diff expect actual
351 printf "$sss$sss$sss$sss" | git-stripspace >actual &&
352 git diff expect actual