blob: 3dcdb1c3cd2e340302c1e468d9602b5c722b66c4 [file] [log] [blame]
Jonathan Clairembault939fa742012-11-23 00:06:28 +01001#!/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 Landley336c44a2016-03-02 15:20:04 -060010testing "default" "expand input" " foo bar\n" "\tfoo\tbar\n" ""
11testing "default stdin" "expand" " foo bar\n" "" "\tfoo\tbar\n"
12testing "single" "expand -t 2 input" " foo bar\n" "\tfoo\tbar\n" ""
13testing "tablist" "expand -t 5,10,12 input" " foo bar foo\n" "\tfoo\tbar\tfoo\n" ""
14testing "backspace" "expand input" "foobarfoo\b\b bar\n" "foobarfoo\b\b\tbar\n" ""
Jonathan Clairembault939fa742012-11-23 00:06:28 +010015
16# advanced tests
17
18POW=15
19TABSTOP=1
20BIGTAB=" "
21for i in $(seq $POW); do
22 BIGTAB=$BIGTAB$BIGTAB
Elliott Hughes8d826bf2017-04-15 11:27:18 -070023 TABSTOP=$(($TABSTOP*2))
Jonathan Clairembault939fa742012-11-23 00:06:28 +010024done
Rob Landley336c44a2016-03-02 15:20:04 -060025testing "long tab single" "expand -t $TABSTOP input" "${BIGTAB}foo\n" "\tfoo\n" ""
Elliott Hughes8d826bf2017-04-15 11:27:18 -070026testing "long tab tablist" "expand -t $TABSTOP,$((TABSTOP+5)) input" \
Jonathan Clairembault939fa742012-11-23 00:06:28 +010027 "${BIGTAB}foo bar\n" "\tfoo\tbar\n" ""
28
Rob Landley336c44a2016-03-02 15:20:04 -060029testing "multiline single" "expand -t 4 input" "foo \n bar\n" "foo\t\n\tbar\n" ""
30testing "multiline tablist" "expand -t 4,8 input" \
Jonathan Clairembault939fa742012-11-23 00:06:28 +010031 "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"
Rob Landley336c44a2016-03-02 15:20:04 -060043testing "long line single" "expand input" \
Jonathan Clairembault939fa742012-11-23 00:06:28 +010044 "${EXPANDLINE}" "$BIGLINE" ""