annotate tests/expand.test @ 1776:7bf68329eb3b draft default tip

Repository switched to git at https://github.com/landley/toybox
author Rob Landley <rob@landley.net>
date Thu, 09 Apr 2015 02:28:32 -0500
parents 8700cbe1cb29
children
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" ""
723
2818724bb8be Re-add backspace support to expand (oops) and fix test to expect data plus backspace characters rather than the chracters cancelling each other out before output.
Rob Landley <rob@landley.net>
parents: 716
diff changeset
14 testing "expand backspace" "expand input" "foobarfoo\b\b 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" ""