t / t0030-stripspace.shon commit git-svn: use git-log rather than rev-list | xargs cat-file (3dfab99)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Carlos Rica
   4#
   5
   6test_description='git-stripspace'
   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 &&
  18    git-stripspace <expect >actual &&
  19    git diff expect actual &&
  20
  21    echo "$ttt$ttt" >expect &&
  22    git-stripspace <expect >actual &&
  23    git diff expect actual &&
  24
  25    echo "$ttt$ttt$ttt" >expect &&
  26    git-stripspace <expect >actual &&
  27    git diff expect actual &&
  28
  29    echo "$ttt$ttt$ttt$ttt" >expect &&
  30    git-stripspace <expect >actual &&
  31    git diff expect actual
  32'
  33
  34test_expect_success \
  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 &&
  39
  40    echo "$sss$sss$ttt" >expect &&
  41    git-stripspace <expect >actual &&
  42    git diff expect actual &&
  43
  44    echo "$sss$sss$sss$ttt" >expect &&
  45    git-stripspace <expect >actual &&
  46    git diff expect actual
  47'
  48
  49test_expect_success \
  50    'lines with intermediate spaces should be unchanged' '
  51    echo "$ttt$sss$ttt" >expect &&
  52    git-stripspace <expect >actual &&
  53    git diff expect actual &&
  54
  55    echo "$ttt$sss$sss$ttt" >expect &&
  56    git-stripspace <expect >actual &&
  57    git diff expect actual
  58'
  59
  60test_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    git diff expect actual &&
  65
  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 &&
  69
  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 &&
  73
  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 &&
  77
  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 &&
  81
  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
  85'
  86
  87test_expect_success \
  88    'consecutive blank lines at the beginning should be removed' '
  89    printf "" > expect &&
  90    printf "\n" | git-stripspace >actual &&
  91    git diff expect actual &&
  92
  93    printf "" > expect &&
  94    printf "\n\n\n" | git-stripspace >actual &&
  95    git diff expect actual &&
  96
  97    printf "" > expect &&
  98    printf "$sss\n$sss\n$sss\n" | git-stripspace >actual &&
  99    git diff expect actual &&
 100
 101    printf "" > expect &&
 102    printf "$sss$sss\n$sss\n\n" | git-stripspace >actual &&
 103    git diff expect actual &&
 104
 105    printf "" > expect &&
 106    printf "\n$sss\n$sss$sss\n" | git-stripspace >actual &&
 107    git diff expect actual &&
 108
 109    printf "" > expect &&
 110    printf "$sss$sss$sss$sss\n\n\n" | git-stripspace >actual &&
 111    git diff expect actual &&
 112
 113    printf "" > expect &&
 114    printf "\n$sss$sss$sss$sss\n\n" | git-stripspace >actual &&
 115    git diff expect actual &&
 116
 117    printf "" > expect &&
 118    printf "\n\n$sss$sss$sss$sss\n" | git-stripspace >actual &&
 119    git diff expect actual &&
 120
 121    printf "$ttt\n" > expect &&
 122    printf "\n$ttt\n" | git-stripspace >actual &&
 123    git diff expect actual &&
 124
 125    printf "$ttt\n" > expect &&
 126    printf "\n\n\n$ttt\n" | git-stripspace >actual &&
 127    git diff expect actual &&
 128
 129    printf "$ttt$ttt\n" > expect &&
 130    printf "\n\n\n$ttt$ttt\n" | git-stripspace >actual &&
 131    git diff expect actual &&
 132
 133    printf "$ttt$ttt$ttt\n" > expect &&
 134    printf "\n\n\n$ttt$ttt$ttt\n" | git-stripspace >actual &&
 135    git diff expect actual &&
 136
 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 &&
 140
 141    printf "$ttt\n" > expect &&
 142    printf "$sss\n$sss\n$sss\n$ttt\n" | git-stripspace >actual &&
 143    git diff expect actual &&
 144
 145    printf "$ttt\n" > expect &&
 146    printf "\n$sss\n$sss$sss\n$ttt\n" | git-stripspace >actual &&
 147    git diff expect actual &&
 148
 149    printf "$ttt\n" > expect &&
 150    printf "$sss$sss\n$sss\n\n$ttt\n" | git-stripspace >actual &&
 151    git diff expect actual &&
 152
 153    printf "$ttt\n" > expect &&
 154    printf "$sss$sss$sss\n\n\n$ttt\n" | git-stripspace >actual &&
 155    git diff expect actual &&
 156
 157    printf "$ttt\n" > expect &&
 158    printf "\n$sss$sss$sss\n\n$ttt\n" | git-stripspace >actual &&
 159    git diff expect actual &&
 160
 161    printf "$ttt\n" > expect &&
 162    printf "\n\n$sss$sss$sss\n$ttt\n" | git-stripspace >actual &&
 163    git diff expect actual
 164'
 165
 166test_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 &&
 171
 172    printf "$ttt\n" > expect &&
 173    printf "$ttt\n\n\n\n" | git-stripspace >actual &&
 174    git diff expect actual &&
 175
 176    printf "$ttt$ttt\n" > expect &&
 177    printf "$ttt$ttt\n\n\n\n" | git-stripspace >actual &&
 178    git diff expect actual &&
 179
 180    printf "$ttt$ttt$ttt\n" > expect &&
 181    printf "$ttt$ttt$ttt\n\n\n\n" | git-stripspace >actual &&
 182    git diff expect actual &&
 183
 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 &&
 187
 188    printf "$ttt\n" > expect &&
 189    printf "$ttt\n$sss\n$sss\n$sss\n" | git-stripspace >actual &&
 190    git diff expect actual &&
 191
 192    printf "$ttt\n" > expect &&
 193    printf "$ttt\n\n$sss\n$sss$sss\n" | git-stripspace >actual &&
 194    git diff expect actual &&
 195
 196    printf "$ttt\n" > expect &&
 197    printf "$ttt\n$sss$sss\n$sss\n\n" | git-stripspace >actual &&
 198    git diff expect actual &&
 199
 200    printf "$ttt\n" > expect &&
 201    printf "$ttt\n$sss$sss$sss\n\n\n" | git-stripspace >actual &&
 202    git diff expect actual &&
 203
 204    printf "$ttt\n" > expect &&
 205    printf "$ttt\n\n$sss$sss$sss\n\n" | git-stripspace >actual &&
 206    git diff expect actual &&
 207
 208    printf "$ttt\n" > expect &&
 209    printf "$ttt\n\n\n$sss$sss$sss\n" | git-stripspace >actual &&
 210    git diff expect actual
 211'
 212
 213test_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
 219'
 220
 221# text plus spaces at the end:
 222
 223test_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
 231'
 232
 233test_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 "  "
 241'
 242
 243test_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 &&
 248
 249    printf "$ttt\n" >expect &&
 250    printf "$ttt$sss$sss" | git-stripspace >actual &&
 251    git diff expect actual &&
 252
 253    printf "$ttt\n" >expect &&
 254    printf "$ttt$sss$sss$sss" | git-stripspace >actual &&
 255    git diff expect actual &&
 256
 257    printf "$ttt$ttt\n" >expect &&
 258    printf "$ttt$ttt$sss" | git-stripspace >actual &&
 259    git diff expect actual &&
 260
 261    printf "$ttt$ttt\n" >expect &&
 262    printf "$ttt$ttt$sss$sss" | git-stripspace >actual &&
 263    git diff expect actual &&
 264
 265    printf "$ttt$ttt$ttt\n" >expect &&
 266    printf "$ttt$ttt$ttt$sss" | git-stripspace >actual &&
 267    git diff expect actual
 268'
 269
 270test_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 "  "
 278'
 279
 280test_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 &&
 285
 286    echo "$ttt" >expect &&
 287    echo "$ttt$sss$sss" | git-stripspace >actual &&
 288    git diff expect actual &&
 289
 290    echo "$ttt" >expect &&
 291    echo "$ttt$sss$sss$sss" | git-stripspace >actual &&
 292    git diff expect actual &&
 293
 294    echo "$ttt$ttt" >expect &&
 295    echo "$ttt$ttt$sss" | git-stripspace >actual &&
 296    git diff expect actual &&
 297
 298    echo "$ttt$ttt" >expect &&
 299    echo "$ttt$ttt$sss$sss" | git-stripspace >actual &&
 300    git diff expect actual &&
 301
 302    echo "$ttt$ttt$ttt" >expect &&
 303    echo "$ttt$ttt$ttt$sss" | git-stripspace >actual &&
 304    git diff expect actual
 305'
 306
 307# spaces only:
 308
 309test_expect_success \
 310    'spaces with newline at end should be replaced with empty string' '
 311    printf "" >expect &&
 312
 313    echo | git-stripspace >actual &&
 314    git diff expect actual &&
 315
 316    echo "$sss" | git-stripspace >actual &&
 317    git diff expect actual &&
 318
 319    echo "$sss$sss" | git-stripspace >actual &&
 320    git diff expect actual &&
 321
 322    echo "$sss$sss$sss" | git-stripspace >actual &&
 323    git diff expect actual &&
 324
 325    echo "$sss$sss$sss$sss" | git-stripspace >actual &&
 326    git diff expect actual
 327'
 328
 329test_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 " "
 336'
 337
 338test_expect_success \
 339    'spaces without newline at end should be replaced with empty string' '
 340    printf "" >expect &&
 341
 342    printf "" | git-stripspace >actual &&
 343    git diff expect actual
 344
 345    printf "$sss$sss" | git-stripspace >actual &&
 346    git diff expect actual
 347
 348    printf "$sss$sss$sss" | git-stripspace >actual &&
 349    git diff expect actual
 350
 351    printf "$sss$sss$sss$sss" | git-stripspace >actual &&
 352    git diff expect actual
 353'
 354
 355test_done