1 #!/bin/bash 2 3 # POSIX 2008 compliant expand tests. 4 # Copyright 2012 by Jonathan Clairembault <jonathan (at] clairembault.fr> 5 6 [ -f testing.sh ] && . testing.sh 7 8 # some basic tests 9 10 testing "expand default" "expand input" " foo bar\n" "\tfoo\tbar\n" "" 11 testing "expand default stdin" "expand" " foo bar\n" "" "\tfoo\tbar\n" 12 testing "expand single" "expand -t 2 input" " foo bar\n" "\tfoo\tbar\n" "" 13 testing "expand tablist" "expand -t 5,10,12 input" " foo bar foo\n" "\tfoo\tbar\tfoo\n" "" 14 testing "expand backspace" "expand input" "foobarfoo\b\b bar\n" "foobarfoo\b\b\tbar\n" "" 15 16 # advanced tests 17 18 POW=15 19 TABSTOP=1 20 BIGTAB=" " 21 for i in $(seq $POW); do 22 BIGTAB=$BIGTAB$BIGTAB 23 TABSTOP=$[$TABSTOP*2] 24 done 25 testing "expand long tab single" "expand -t $TABSTOP input" "${BIGTAB}foo\n" "\tfoo\n" "" 26 testing "expand long tab tablist" "expand -t $TABSTOP,$[TABSTOP+5] input" \ 27 "${BIGTAB}foo bar\n" "\tfoo\tbar\n" "" 28 29 testing "expand multiline single" "expand -t 4 input" "foo \n bar\n" "foo\t\n\tbar\n" "" 30 testing "expand multiline tablist" "expand -t 4,8 input" \ 31 "foo bar\n bar foo\n" "foo\t\tbar\n\tbar\tfoo\n" "" 32 POW=15 33 BIGLINE="foo " 34 for i in $(seq $POW); do 35 BIGLINE=$BIGLINE$BIGLINE 36 done 37 if [ $POW -gt 0 ]; then 38 EXPANDLINE="${BIGLINE} foo\n" 39 else 40 EXPANDLINE="${BIGLINE} foo\n" 41 fi 42 BIGLINE="${BIGLINE}\tfoo\n" 43 testing "expand long line single" "expand input" \ 44 "${EXPANDLINE}" "$BIGLINE" "" 45