blob: a8e84d854636178224b1bbd52272d47fc686ece9 [file] [log] [blame]
Carlos Rica30d038e2007-06-25 21:24:21 +02001#!/bin/sh
2#
3# Copyright (c) 2007 Carlos Rica
4#
5
Junio C Hamano5be60072007-07-02 22:52:14 -07006test_description='git stripspace'
Carlos Rica30d038e2007-06-25 21:24:21 +02007
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 &&
Junio C Hamano5be60072007-07-02 22:52:14 -070018 git stripspace <expect >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -070019 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +020020
21 echo "$ttt$ttt" >expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -070022 git stripspace <expect >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -070023 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +020024
25 echo "$ttt$ttt$ttt" >expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -070026 git stripspace <expect >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -070027 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +020028
29 echo "$ttt$ttt$ttt$ttt" >expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -070030 git stripspace <expect >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -070031 test_cmp expect actual
Carlos Rica30d038e2007-06-25 21:24:21 +020032'
33
34test_expect_success \
35 'lines with spaces at the beginning should be unchanged' '
36 echo "$sss$ttt" >expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -070037 git stripspace <expect >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -070038 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +020039
40 echo "$sss$sss$ttt" >expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -070041 git stripspace <expect >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -070042 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +020043
44 echo "$sss$sss$sss$ttt" >expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -070045 git stripspace <expect >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -070046 test_cmp expect actual
Carlos Rica30d038e2007-06-25 21:24:21 +020047'
48
49test_expect_success \
50 'lines with intermediate spaces should be unchanged' '
51 echo "$ttt$sss$ttt" >expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -070052 git stripspace <expect >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -070053 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +020054
55 echo "$ttt$sss$sss$ttt" >expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -070056 git stripspace <expect >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -070057 test_cmp expect actual
Carlos Rica30d038e2007-06-25 21:24:21 +020058'
59
60test_expect_success \
61 'consecutive blank lines should be unified' '
62 printf "$ttt\n\n$ttt\n" > expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -070063 printf "$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -070064 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +020065
66 printf "$ttt$ttt\n\n$ttt\n" > expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -070067 printf "$ttt$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -070068 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +020069
70 printf "$ttt$ttt$ttt\n\n$ttt\n" > expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -070071 printf "$ttt$ttt$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -070072 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +020073
74 printf "$ttt\n\n$ttt\n" > expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -070075 printf "$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -070076 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +020077
78 printf "$ttt\n\n$ttt$ttt\n" > expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -070079 printf "$ttt\n\n\n\n\n$ttt$ttt\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -070080 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +020081
82 printf "$ttt\n\n$ttt$ttt$ttt\n" > expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -070083 printf "$ttt\n\n\n\n\n$ttt$ttt$ttt\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -070084 test_cmp expect actual &&
Carlos Ricab61a8a62007-07-10 23:59:43 +020085
86 printf "$ttt\n\n$ttt\n" > expect &&
87 printf "$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -070088 test_cmp expect actual &&
Carlos Ricab61a8a62007-07-10 23:59:43 +020089
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 &&
Junio C Hamano3af82862008-05-23 22:28:56 -070092 test_cmp expect actual &&
Carlos Ricab61a8a62007-07-10 23:59:43 +020093
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 &&
Junio C Hamano3af82862008-05-23 22:28:56 -070096 test_cmp expect actual &&
Carlos Ricab61a8a62007-07-10 23:59:43 +020097
98 printf "$ttt\n\n$ttt\n" > expect &&
99 printf "$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700100 test_cmp expect actual &&
Carlos Ricab61a8a62007-07-10 23:59:43 +0200101
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 &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700104 test_cmp expect actual &&
Carlos Ricab61a8a62007-07-10 23:59:43 +0200105
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 &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700108 test_cmp expect actual
Carlos Rica30d038e2007-06-25 21:24:21 +0200109'
110
111test_expect_success \
Carlos Ricadefd5312007-07-10 23:53:45 +0200112 'only consecutive blank lines should be completely removed' '
113 > expect &&
114
Junio C Hamano5be60072007-07-02 22:52:14 -0700115 printf "\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700116 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200117
Junio C Hamano5be60072007-07-02 22:52:14 -0700118 printf "\n\n\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700119 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200120
Junio C Hamano5be60072007-07-02 22:52:14 -0700121 printf "$sss\n$sss\n$sss\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700122 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200123
Junio C Hamano5be60072007-07-02 22:52:14 -0700124 printf "$sss$sss\n$sss\n\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700125 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200126
Junio C Hamano5be60072007-07-02 22:52:14 -0700127 printf "\n$sss\n$sss$sss\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700128 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200129
Junio C Hamano5be60072007-07-02 22:52:14 -0700130 printf "$sss$sss$sss$sss\n\n\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700131 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200132
Junio C Hamano5be60072007-07-02 22:52:14 -0700133 printf "\n$sss$sss$sss$sss\n\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700134 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200135
Junio C Hamano5be60072007-07-02 22:52:14 -0700136 printf "\n\n$sss$sss$sss$sss\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700137 test_cmp expect actual
Carlos Ricadefd5312007-07-10 23:53:45 +0200138'
Carlos Rica30d038e2007-06-25 21:24:21 +0200139
Carlos Ricadefd5312007-07-10 23:53:45 +0200140test_expect_success \
141 'consecutive blank lines at the beginning should be removed' '
Carlos Rica30d038e2007-06-25 21:24:21 +0200142 printf "$ttt\n" > expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700143 printf "\n$ttt\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700144 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200145
146 printf "$ttt\n" > expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700147 printf "\n\n\n$ttt\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700148 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200149
150 printf "$ttt$ttt\n" > expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700151 printf "\n\n\n$ttt$ttt\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700152 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200153
154 printf "$ttt$ttt$ttt\n" > expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700155 printf "\n\n\n$ttt$ttt$ttt\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700156 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200157
158 printf "$ttt$ttt$ttt$ttt\n" > expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700159 printf "\n\n\n$ttt$ttt$ttt$ttt\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700160 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200161
162 printf "$ttt\n" > expect &&
Carlos Ricadefd5312007-07-10 23:53:45 +0200163
Junio C Hamano5be60072007-07-02 22:52:14 -0700164 printf "$sss\n$sss\n$sss\n$ttt\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700165 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200166
Junio C Hamano5be60072007-07-02 22:52:14 -0700167 printf "\n$sss\n$sss$sss\n$ttt\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700168 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200169
Junio C Hamano5be60072007-07-02 22:52:14 -0700170 printf "$sss$sss\n$sss\n\n$ttt\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700171 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200172
Junio C Hamano5be60072007-07-02 22:52:14 -0700173 printf "$sss$sss$sss\n\n\n$ttt\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700174 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200175
Junio C Hamano5be60072007-07-02 22:52:14 -0700176 printf "\n$sss$sss$sss\n\n$ttt\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700177 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200178
Junio C Hamano5be60072007-07-02 22:52:14 -0700179 printf "\n\n$sss$sss$sss\n$ttt\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700180 test_cmp expect actual
Carlos Rica30d038e2007-06-25 21:24:21 +0200181'
182
183test_expect_success \
184 'consecutive blank lines at the end should be removed' '
185 printf "$ttt\n" > expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700186 printf "$ttt\n\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700187 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200188
189 printf "$ttt\n" > expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700190 printf "$ttt\n\n\n\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700191 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200192
193 printf "$ttt$ttt\n" > expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700194 printf "$ttt$ttt\n\n\n\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700195 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200196
197 printf "$ttt$ttt$ttt\n" > expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700198 printf "$ttt$ttt$ttt\n\n\n\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700199 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200200
201 printf "$ttt$ttt$ttt$ttt\n" > expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700202 printf "$ttt$ttt$ttt$ttt\n\n\n\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700203 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200204
205 printf "$ttt\n" > expect &&
Carlos Ricadefd5312007-07-10 23:53:45 +0200206
Junio C Hamano5be60072007-07-02 22:52:14 -0700207 printf "$ttt\n$sss\n$sss\n$sss\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700208 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200209
Junio C Hamano5be60072007-07-02 22:52:14 -0700210 printf "$ttt\n\n$sss\n$sss$sss\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700211 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200212
Junio C Hamano5be60072007-07-02 22:52:14 -0700213 printf "$ttt\n$sss$sss\n$sss\n\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700214 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200215
Junio C Hamano5be60072007-07-02 22:52:14 -0700216 printf "$ttt\n$sss$sss$sss\n\n\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700217 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200218
Junio C Hamano5be60072007-07-02 22:52:14 -0700219 printf "$ttt\n\n$sss$sss$sss\n\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700220 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200221
Junio C Hamano5be60072007-07-02 22:52:14 -0700222 printf "$ttt\n\n\n$sss$sss$sss\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700223 test_cmp expect actual
Carlos Rica30d038e2007-06-25 21:24:21 +0200224'
225
226test_expect_success \
227 'text without newline at end should end with newline' '
Junio C Hamano5be60072007-07-02 22:52:14 -0700228 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
Carlos Rica30d038e2007-06-25 21:24:21 +0200232'
233
234# text plus spaces at the end:
235
236test_expect_success \
237 'text plus spaces without newline at end should end with newline' '
Junio C Hamano5be60072007-07-02 22:52:14 -0700238 test `printf "$ttt$sss" | git stripspace | wc -l` -gt 0 &&
239 test `printf "$ttt$ttt$sss" | git stripspace | wc -l` -gt 0 &&
Carlos Ricadefd5312007-07-10 23:53:45 +0200240 test `printf "$ttt$ttt$ttt$sss" | git stripspace | wc -l` -gt 0 &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700241 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
Carlos Rica30d038e2007-06-25 21:24:21 +0200244'
245
Junio C Hamano41ac4142008-02-01 01:50:53 -0800246test_expect_success \
Carlos Rica30d038e2007-06-25 21:24:21 +0200247 'text plus spaces without newline at end should not show spaces' '
Jeff Kingaadbe442008-03-12 17:32:17 -0400248 ! (printf "$ttt$sss" | git stripspace | grep " " >/dev/null) &&
249 ! (printf "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
250 ! (printf "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
251 ! (printf "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
252 ! (printf "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
253 ! (printf "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null)
Carlos Rica30d038e2007-06-25 21:24:21 +0200254'
255
256test_expect_success \
257 'text plus spaces without newline should show the correct lines' '
258 printf "$ttt\n" >expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700259 printf "$ttt$sss" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700260 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200261
262 printf "$ttt\n" >expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700263 printf "$ttt$sss$sss" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700264 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200265
266 printf "$ttt\n" >expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700267 printf "$ttt$sss$sss$sss" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700268 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200269
270 printf "$ttt$ttt\n" >expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700271 printf "$ttt$ttt$sss" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700272 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200273
274 printf "$ttt$ttt\n" >expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700275 printf "$ttt$ttt$sss$sss" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700276 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200277
278 printf "$ttt$ttt$ttt\n" >expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700279 printf "$ttt$ttt$ttt$sss" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700280 test_cmp expect actual
Carlos Rica30d038e2007-06-25 21:24:21 +0200281'
282
Junio C Hamano41ac4142008-02-01 01:50:53 -0800283test_expect_success \
Carlos Rica30d038e2007-06-25 21:24:21 +0200284 'text plus spaces at end should not show spaces' '
Jeff Kingaadbe442008-03-12 17:32:17 -0400285 ! (echo "$ttt$sss" | git stripspace | grep " " >/dev/null) &&
286 ! (echo "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
287 ! (echo "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
288 ! (echo "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
289 ! (echo "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
290 ! (echo "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null)
Carlos Rica30d038e2007-06-25 21:24:21 +0200291'
292
293test_expect_success \
294 'text plus spaces at end should be cleaned and newline must remain' '
295 echo "$ttt" >expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700296 echo "$ttt$sss" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700297 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200298
299 echo "$ttt" >expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700300 echo "$ttt$sss$sss" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700301 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200302
303 echo "$ttt" >expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700304 echo "$ttt$sss$sss$sss" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700305 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200306
307 echo "$ttt$ttt" >expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700308 echo "$ttt$ttt$sss" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700309 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200310
311 echo "$ttt$ttt" >expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700312 echo "$ttt$ttt$sss$sss" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700313 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200314
315 echo "$ttt$ttt$ttt" >expect &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700316 echo "$ttt$ttt$ttt$sss" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700317 test_cmp expect actual
Carlos Rica30d038e2007-06-25 21:24:21 +0200318'
319
320# spaces only:
321
322test_expect_success \
323 'spaces with newline at end should be replaced with empty string' '
324 printf "" >expect &&
325
Junio C Hamano5be60072007-07-02 22:52:14 -0700326 echo | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700327 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200328
Junio C Hamano5be60072007-07-02 22:52:14 -0700329 echo "$sss" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700330 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200331
Junio C Hamano5be60072007-07-02 22:52:14 -0700332 echo "$sss$sss" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700333 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200334
Junio C Hamano5be60072007-07-02 22:52:14 -0700335 echo "$sss$sss$sss" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700336 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200337
Junio C Hamano5be60072007-07-02 22:52:14 -0700338 echo "$sss$sss$sss$sss" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700339 test_cmp expect actual
Carlos Rica30d038e2007-06-25 21:24:21 +0200340'
341
Junio C Hamano41ac4142008-02-01 01:50:53 -0800342test_expect_success \
Carlos Rica30d038e2007-06-25 21:24:21 +0200343 'spaces without newline at end should not show spaces' '
Jeff Kingaadbe442008-03-12 17:32:17 -0400344 ! (printf "" | git stripspace | grep " " >/dev/null) &&
345 ! (printf "$sss" | git stripspace | grep " " >/dev/null) &&
346 ! (printf "$sss$sss" | git stripspace | grep " " >/dev/null) &&
347 ! (printf "$sss$sss$sss" | git stripspace | grep " " >/dev/null) &&
348 ! (printf "$sss$sss$sss$sss" | git stripspace | grep " " >/dev/null)
Carlos Rica30d038e2007-06-25 21:24:21 +0200349'
350
351test_expect_success \
352 'spaces without newline at end should be replaced with empty string' '
353 printf "" >expect &&
354
Junio C Hamano5be60072007-07-02 22:52:14 -0700355 printf "" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700356 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200357
Junio C Hamano5be60072007-07-02 22:52:14 -0700358 printf "$sss$sss" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700359 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200360
Junio C Hamano5be60072007-07-02 22:52:14 -0700361 printf "$sss$sss$sss" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700362 test_cmp expect actual &&
Carlos Rica30d038e2007-06-25 21:24:21 +0200363
Junio C Hamano5be60072007-07-02 22:52:14 -0700364 printf "$sss$sss$sss$sss" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700365 test_cmp expect actual
Carlos Rica30d038e2007-06-25 21:24:21 +0200366'
367
Carlos Ricab61a8a62007-07-10 23:59:43 +0200368test_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 &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700372 test_cmp expect actual &&
Carlos Ricab61a8a62007-07-10 23:59:43 +0200373
374 printf "$ttt\n$ttt$ttt\n$ttt\n" >expect &&
375 printf "$ttt\n$ttt$ttt\n$ttt\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700376 test_cmp expect actual &&
Carlos Ricab61a8a62007-07-10 23:59:43 +0200377
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 &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700380 test_cmp expect actual &&
Carlos Ricab61a8a62007-07-10 23:59:43 +0200381
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 &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700384 test_cmp expect actual &&
Carlos Ricab61a8a62007-07-10 23:59:43 +0200385
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 &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700388 test_cmp expect actual &&
Carlos Ricab61a8a62007-07-10 23:59:43 +0200389
390 printf "$ttt\n$ttt$ttt\n\n$ttt\n" >expect &&
391 printf "$ttt\n$ttt$ttt\n\n$ttt\n" | git stripspace >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700392 test_cmp expect actual
Carlos Ricab61a8a62007-07-10 23:59:43 +0200393'
394
Johannes Schindelinf653aee2007-07-23 12:58:27 +0100395test_expect_success 'strip comments, too' '
396 test ! -z "$(echo "# comment" | git stripspace)" &&
397 test -z "$(echo "# comment" | git stripspace -s)"
398'
399
Junio C Hamanoeff80a92013-01-16 20:18:48 +0100400test_expect_success 'strip comments with changed comment char' '
401 test ! -z "$(echo "; comment" | git -c core.commentchar=";" stripspace)" &&
402 test -z "$(echo "; comment" | git -c core.commentchar=";" stripspace -s)"
403'
404
405test_expect_success '-c with single line' '
406 printf "# foo\n" >expect &&
407 printf "foo" | git stripspace -c >actual &&
408 test_cmp expect actual
409'
410
411test_expect_success '-c with single line followed by empty line' '
412 printf "# foo\n#\n" >expect &&
413 printf "foo\n\n" | git stripspace -c >actual &&
414 test_cmp expect actual
415'
416
417test_expect_success '-c with newline only' '
418 printf "#\n" >expect &&
419 printf "\n" | git stripspace -c >actual &&
420 test_cmp expect actual
421'
422
423test_expect_success '--comment-lines with single line' '
424 printf "# foo\n" >expect &&
425 printf "foo" | git stripspace -c >actual &&
426 test_cmp expect actual
427'
428
429test_expect_success '-c with changed comment char' '
430 printf "; foo\n" >expect &&
431 printf "foo" | git -c core.commentchar=";" stripspace -c >actual &&
432 test_cmp expect actual
433'
434
Carlos Rica30d038e2007-06-25 21:24:21 +0200435test_done