Jonathan Clairembault | 939fa74 | 2012-11-23 00:06:28 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # POSIX 2008 compliant expand tests. |
| 4 | # Copyright 2012 by Jonathan Clairembault <jonathan@clairembault.fr> |
| 5 | |
| 6 | [ -f testing.sh ] && . testing.sh |
| 7 | |
| 8 | # some basic tests |
| 9 | |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 10 | testing "default" "expand input" " foo bar\n" "\tfoo\tbar\n" "" |
| 11 | testing "default stdin" "expand" " foo bar\n" "" "\tfoo\tbar\n" |
| 12 | testing "single" "expand -t 2 input" " foo bar\n" "\tfoo\tbar\n" "" |
| 13 | testing "tablist" "expand -t 5,10,12 input" " foo bar foo\n" "\tfoo\tbar\tfoo\n" "" |
| 14 | testing "backspace" "expand input" "foobarfoo\b\b bar\n" "foobarfoo\b\b\tbar\n" "" |
Jonathan Clairembault | 939fa74 | 2012-11-23 00:06:28 +0100 | [diff] [blame] | 15 | |
| 16 | # advanced tests |
| 17 | |
| 18 | POW=15 |
| 19 | TABSTOP=1 |
| 20 | BIGTAB=" " |
| 21 | for i in $(seq $POW); do |
| 22 | BIGTAB=$BIGTAB$BIGTAB |
Elliott Hughes | 8d826bf | 2017-04-15 11:27:18 -0700 | [diff] [blame] | 23 | TABSTOP=$(($TABSTOP*2)) |
Jonathan Clairembault | 939fa74 | 2012-11-23 00:06:28 +0100 | [diff] [blame] | 24 | done |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 25 | testing "long tab single" "expand -t $TABSTOP input" "${BIGTAB}foo\n" "\tfoo\n" "" |
Elliott Hughes | 8d826bf | 2017-04-15 11:27:18 -0700 | [diff] [blame] | 26 | testing "long tab tablist" "expand -t $TABSTOP,$((TABSTOP+5)) input" \ |
Jonathan Clairembault | 939fa74 | 2012-11-23 00:06:28 +0100 | [diff] [blame] | 27 | "${BIGTAB}foo bar\n" "\tfoo\tbar\n" "" |
| 28 | |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 29 | testing "multiline single" "expand -t 4 input" "foo \n bar\n" "foo\t\n\tbar\n" "" |
| 30 | testing "multiline tablist" "expand -t 4,8 input" \ |
Jonathan Clairembault | 939fa74 | 2012-11-23 00:06:28 +0100 | [diff] [blame] | 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" |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 43 | testing "long line single" "expand input" \ |
Jonathan Clairembault | 939fa74 | 2012-11-23 00:06:28 +0100 | [diff] [blame] | 44 | "${EXPANDLINE}" "$BIGLINE" "" |