• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
10testing "expand default" "expand input" "        foo     bar\n" "\tfoo\tbar\n" ""
11testing "expand default stdin" "expand"  "        foo     bar\n" "" "\tfoo\tbar\n"
12testing "expand single" "expand -t 2 input" "  foo bar\n" "\tfoo\tbar\n" ""
13testing "expand tablist" "expand -t 5,10,12 input" "     foo  bar foo\n" "\tfoo\tbar\tfoo\n" ""
14testing "expand backspace" "expand input" "foobarfoo\b\b bar\n" "foobarfoo\b\b\tbar\n" ""
15
16# advanced tests
17
18POW=15
19TABSTOP=1
20BIGTAB=" "
21for i in $(seq $POW); do
22    BIGTAB=$BIGTAB$BIGTAB
23    TABSTOP=$[$TABSTOP*2]
24done
25testing "expand long tab single" "expand -t $TABSTOP input" "${BIGTAB}foo\n" "\tfoo\n" ""
26testing "expand long tab tablist" "expand -t $TABSTOP,$[TABSTOP+5] input" \
27        "${BIGTAB}foo  bar\n" "\tfoo\tbar\n" ""
28
29testing "expand multiline single" "expand -t 4 input" "foo \n    bar\n" "foo\t\n\tbar\n" ""
30testing "expand multiline tablist" "expand -t 4,8 input" \
31        "foo     bar\n    bar foo\n" "foo\t\tbar\n\tbar\tfoo\n" ""
32POW=15
33BIGLINE="foo "
34for i in $(seq $POW); do
35    BIGLINE=$BIGLINE$BIGLINE
36done
37if [ $POW -gt 0 ]; then
38    EXPANDLINE="${BIGLINE}        foo\n"
39else
40    EXPANDLINE="${BIGLINE}    foo\n"
41fi
42BIGLINE="${BIGLINE}\tfoo\n"
43testing "expand long line single" "expand input" \
44        "${EXPANDLINE}" "$BIGLINE" ""
45