printf "$ttt\n\n$ttt$ttt$ttt\n" > expect &&
printf "$ttt\n\n\n\n\n$ttt$ttt$ttt\n" | git stripspace >actual &&
+ git diff expect actual &&
+
+ printf "$ttt\n\n$ttt\n" > expect &&
+ printf "$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
+ git diff expect actual &&
+
+ printf "$ttt$ttt\n\n$ttt\n" > expect &&
+ printf "$ttt$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
+ git diff expect actual &&
+
+ printf "$ttt$ttt$ttt\n\n$ttt\n" > expect &&
+ printf "$ttt$ttt$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
+ git diff expect actual &&
+
+ printf "$ttt\n\n$ttt\n" > expect &&
+ printf "$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
+ git diff expect actual &&
+
+ printf "$ttt\n\n$ttt$ttt\n" > expect &&
+ printf "$ttt\n\t\n \n\n \t\t\n$ttt$ttt\n" | git stripspace >actual &&
+ git diff expect actual &&
+
+ printf "$ttt\n\n$ttt$ttt$ttt\n" > expect &&
+ printf "$ttt\n\t\n \n\n \t\t\n$ttt$ttt$ttt\n" | git stripspace >actual &&
git diff expect actual
'
test_expect_success \
- 'consecutive blank lines at the beginning should be removed' '
- printf "" > expect &&
+ 'only consecutive blank lines should be completely removed' '
+ > expect &&
+
printf "\n" | git stripspace >actual &&
git diff expect actual &&
- printf "" > expect &&
printf "\n\n\n" | git stripspace >actual &&
git diff expect actual &&
- printf "" > expect &&
printf "$sss\n$sss\n$sss\n" | git stripspace >actual &&
git diff expect actual &&
- printf "" > expect &&
printf "$sss$sss\n$sss\n\n" | git stripspace >actual &&
git diff expect actual &&
- printf "" > expect &&
printf "\n$sss\n$sss$sss\n" | git stripspace >actual &&
git diff expect actual &&
- printf "" > expect &&
printf "$sss$sss$sss$sss\n\n\n" | git stripspace >actual &&
git diff expect actual &&
- printf "" > expect &&
printf "\n$sss$sss$sss$sss\n\n" | git stripspace >actual &&
git diff expect actual &&
- printf "" > expect &&
printf "\n\n$sss$sss$sss$sss\n" | git stripspace >actual &&
- git diff expect actual &&
+ git diff expect actual
+'
+test_expect_success \
+ 'consecutive blank lines at the beginning should be removed' '
printf "$ttt\n" > expect &&
printf "\n$ttt\n" | git stripspace >actual &&
git diff expect actual &&
git diff expect actual &&
printf "$ttt\n" > expect &&
+
printf "$sss\n$sss\n$sss\n$ttt\n" | git stripspace >actual &&
git diff expect actual &&
- printf "$ttt\n" > expect &&
printf "\n$sss\n$sss$sss\n$ttt\n" | git stripspace >actual &&
git diff expect actual &&
- printf "$ttt\n" > expect &&
printf "$sss$sss\n$sss\n\n$ttt\n" | git stripspace >actual &&
git diff expect actual &&
- printf "$ttt\n" > expect &&
printf "$sss$sss$sss\n\n\n$ttt\n" | git stripspace >actual &&
git diff expect actual &&
- printf "$ttt\n" > expect &&
printf "\n$sss$sss$sss\n\n$ttt\n" | git stripspace >actual &&
git diff expect actual &&
- printf "$ttt\n" > expect &&
printf "\n\n$sss$sss$sss\n$ttt\n" | git stripspace >actual &&
git diff expect actual
'
git diff expect actual &&
printf "$ttt\n" > expect &&
+
printf "$ttt\n$sss\n$sss\n$sss\n" | git stripspace >actual &&
git diff expect actual &&
- printf "$ttt\n" > expect &&
printf "$ttt\n\n$sss\n$sss$sss\n" | git stripspace >actual &&
git diff expect actual &&
- printf "$ttt\n" > expect &&
printf "$ttt\n$sss$sss\n$sss\n\n" | git stripspace >actual &&
git diff expect actual &&
- printf "$ttt\n" > expect &&
printf "$ttt\n$sss$sss$sss\n\n\n" | git stripspace >actual &&
git diff expect actual &&
- printf "$ttt\n" > expect &&
printf "$ttt\n\n$sss$sss$sss\n\n" | git stripspace >actual &&
git diff expect actual &&
- printf "$ttt\n" > expect &&
printf "$ttt\n\n\n$sss$sss$sss\n" | git stripspace >actual &&
git diff expect actual
'
'text plus spaces without newline at end should end with newline' '
test `printf "$ttt$sss" | git stripspace | wc -l` -gt 0 &&
test `printf "$ttt$ttt$sss" | git stripspace | wc -l` -gt 0 &&
- test `printf "$ttt$ttt$ttt$sss" | git stripspace | wc -l` -gt 0
+ test `printf "$ttt$ttt$ttt$sss" | git stripspace | wc -l` -gt 0 &&
test `printf "$ttt$sss$sss" | git stripspace | wc -l` -gt 0 &&
test `printf "$ttt$ttt$sss$sss" | git stripspace | wc -l` -gt 0 &&
test `printf "$ttt$sss$sss$sss" | git stripspace | wc -l` -gt 0
'
-test_expect_failure \
+test_expect_success \
'text plus spaces without newline at end should not show spaces' '
- printf "$ttt$sss" | git stripspace | grep -q " " ||
- printf "$ttt$ttt$sss" | git stripspace | grep -q " " ||
- printf "$ttt$ttt$ttt$sss" | git stripspace | grep -q " " ||
- printf "$ttt$sss$sss" | git stripspace | grep -q " " ||
- printf "$ttt$ttt$sss$sss" | git stripspace | grep -q " " ||
- printf "$ttt$sss$sss$sss" | git stripspace | grep -q " "
+ ! (printf "$ttt$sss" | git stripspace | grep " " >/dev/null) &&
+ ! (printf "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
+ ! (printf "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
+ ! (printf "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
+ ! (printf "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
+ ! (printf "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null)
'
test_expect_success \
git diff expect actual
'
-test_expect_failure \
+test_expect_success \
'text plus spaces at end should not show spaces' '
- echo "$ttt$sss" | git stripspace | grep -q " " ||
- echo "$ttt$ttt$sss" | git stripspace | grep -q " " ||
- echo "$ttt$ttt$ttt$sss" | git stripspace | grep -q " " ||
- echo "$ttt$sss$sss" | git stripspace | grep -q " " ||
- echo "$ttt$ttt$sss$sss" | git stripspace | grep -q " " ||
- echo "$ttt$sss$sss$sss" | git stripspace | grep -q " "
+ ! (echo "$ttt$sss" | git stripspace | grep " " >/dev/null) &&
+ ! (echo "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
+ ! (echo "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
+ ! (echo "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
+ ! (echo "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
+ ! (echo "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null)
'
test_expect_success \
git diff expect actual
'
-test_expect_failure \
+test_expect_success \
'spaces without newline at end should not show spaces' '
- printf "" | git stripspace | grep -q " " ||
- printf "$sss" | git stripspace | grep -q " " ||
- printf "$sss$sss" | git stripspace | grep -q " " ||
- printf "$sss$sss$sss" | git stripspace | grep -q " " ||
- printf "$sss$sss$sss$sss" | git stripspace | grep -q " "
+ ! (printf "" | git stripspace | grep " " >/dev/null) &&
+ ! (printf "$sss" | git stripspace | grep " " >/dev/null) &&
+ ! (printf "$sss$sss" | git stripspace | grep " " >/dev/null) &&
+ ! (printf "$sss$sss$sss" | git stripspace | grep " " >/dev/null) &&
+ ! (printf "$sss$sss$sss$sss" | git stripspace | grep " " >/dev/null)
'
test_expect_success \
printf "" >expect &&
printf "" | git stripspace >actual &&
- git diff expect actual
+ git diff expect actual &&
printf "$sss$sss" | git stripspace >actual &&
- git diff expect actual
+ git diff expect actual &&
printf "$sss$sss$sss" | git stripspace >actual &&
- git diff expect actual
+ git diff expect actual &&
printf "$sss$sss$sss$sss" | git stripspace >actual &&
git diff expect actual
'
+test_expect_success \
+ 'consecutive text lines should be unchanged' '
+ printf "$ttt$ttt\n$ttt\n" >expect &&
+ printf "$ttt$ttt\n$ttt\n" | git stripspace >actual &&
+ git diff expect actual &&
+
+ printf "$ttt\n$ttt$ttt\n$ttt\n" >expect &&
+ printf "$ttt\n$ttt$ttt\n$ttt\n" | git stripspace >actual &&
+ git diff expect actual &&
+
+ printf "$ttt\n$ttt\n$ttt\n$ttt$ttt\n" >expect &&
+ printf "$ttt\n$ttt\n$ttt\n$ttt$ttt\n" | git stripspace >actual &&
+ git diff expect actual &&
+
+ printf "$ttt\n$ttt\n\n$ttt$ttt\n$ttt\n" >expect &&
+ printf "$ttt\n$ttt\n\n$ttt$ttt\n$ttt\n" | git stripspace >actual &&
+ git diff expect actual &&
+
+ printf "$ttt$ttt\n\n$ttt\n$ttt$ttt\n" >expect &&
+ printf "$ttt$ttt\n\n$ttt\n$ttt$ttt\n" | git stripspace >actual &&
+ git diff expect actual &&
+
+ printf "$ttt\n$ttt$ttt\n\n$ttt\n" >expect &&
+ printf "$ttt\n$ttt$ttt\n\n$ttt\n" | git stripspace >actual &&
+ git diff expect actual
+'
+
+test_expect_success 'strip comments, too' '
+ test ! -z "$(echo "# comment" | git stripspace)" &&
+ test -z "$(echo "# comment" | git stripspace -s)"
+'
+
test_done