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