annotate scripts/test/expand.test @ 716:8c10cf7bace0

expand: handle backspace.
author Jonathan Clairembault <jonathan@clairembault.fr>
date Fri, 23 Nov 2012 09:24:53 +0100
parents 3417db95f24b
children 2818724bb8be
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
715
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
1 #!/bin/bash
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
2
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
3 # POSIX 2008 compliant expand tests.
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
4 # Copyright 2012 by Jonathan Clairembault <jonathan@clairembault.fr>
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
5
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
6 [ -f testing.sh ] && . testing.sh
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
7
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
8 # some basic tests
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
9
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
10 testing "expand default" "expand input" " foo bar\n" "\tfoo\tbar\n" ""
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
11 testing "expand default stdin" "expand" " foo bar\n" "" "\tfoo\tbar\n"
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
12 testing "expand single" "expand -t 2 input" " foo bar\n" "\tfoo\tbar\n" ""
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
13 testing "expand tablist" "expand -t 5,10,12 input" " foo bar foo\n" "\tfoo\tbar\tfoo\n" ""
716
8c10cf7bace0 expand: handle backspace.
Jonathan Clairembault <jonathan@clairembault.fr>
parents: 715
diff changeset
14 testing "expand backspace" "expand input" "foobarf bar\n" "foobarfoo\b\b\tbar\n" ""
715
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
15
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
16 # advanced tests
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
17
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
18 POW=15
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
19 TABSTOP=1
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
20 BIGTAB=" "
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
21 for i in $(seq $POW); do
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
22 BIGTAB=$BIGTAB$BIGTAB
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
23 TABSTOP=$[$TABSTOP*2]
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
24 done
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
25 testing "expand long tab single" "expand -t $TABSTOP input" "${BIGTAB}foo\n" "\tfoo\n" ""
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
26 testing "expand long tab tablist" "expand -t $TABSTOP,$[TABSTOP+5] input" \
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
27 "${BIGTAB}foo bar\n" "\tfoo\tbar\n" ""
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
28
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
29 testing "expand multiline single" "expand -t 4 input" "foo \n bar\n" "foo\t\n\tbar\n" ""
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
30 testing "expand multiline tablist" "expand -t 4,8 input" \
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
31 "foo bar\n bar foo\n" "foo\t\tbar\n\tbar\tfoo\n" ""
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
32 POW=15
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
33 BIGLINE="foo "
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
34 for i in $(seq $POW); do
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
35 BIGLINE=$BIGLINE$BIGLINE
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
36 done
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
37 if [ $POW -gt 0 ]; then
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
38 EXPANDLINE="${BIGLINE} foo\n"
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
39 else
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
40 EXPANDLINE="${BIGLINE} foo\n"
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
41 fi
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
42 BIGLINE="${BIGLINE}\tfoo\n"
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
43 testing "expand long line single" "expand input" \
3417db95f24b Add expand command as described in POSIX-2008.
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
diff changeset
44 "${EXPANDLINE}" "$BIGLINE" ""