1#!/bin/sh 2# 3# Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org> 4# 5# Permission to use, copy, modify, and distribute this software for any 6# purpose with or without fee is hereby granted, provided that the above 7# copyright notice and this permission notice appear in all copies. 8# 9# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 17fail=0 18 19tc1() 20{ 21 expected=$(echo -n "$3") 22 result=$(echo -n "$1" | column $2) 23 if [ "X$result" != "X$expected" ]; then 24 fail=$((fail+1)) 25 echo "argument: '$2'" 26 echo "input: '$1'" 27 echo "expected: '$expected'" 28 echo "result: '$result'" 29 fi 30} 31 32tc() 33{ 34 input=$1 35 shift 36 while [ $# -gt 1 ]; do 37 tc1 "$input" "$1" "$2" 38 shift 2 39 done 40} 41 42tc "1\n2\n\n3\n \t \n4" \ 43 "-c 7" "1\n2\n3\n4\n" \ 44 "-c 15" "1\n2\n3\n4\n" \ 45 "-c 16" "1\t3\n2\t4\n" \ 46 "-xc 7" "1\n2\n3\n4\n" \ 47 "-xc 16" "1\t2\n3\t4\n" 48tc "one\ntwo\nthree\nfour\nfive\nsix\n seven\neight\n" \ 49 "-c 23" "one\tfive\ntwo\tsix\nthree\t seven\nfour\teight\n" \ 50 "-xc 23" "one\ttwo\nthree\tfour\nfive\tsix\n seven\teight\n" \ 51 "-c 24" "one\tfour\t seven\ntwo\tfive\teight\nthree\tsix\n" \ 52 "-xc 24" "one\ttwo\tthree\nfour\tfive\tsix\n seven\teight\n" 53tc "eleven\ntwelve\nthirteen\n" \ 54 "-c 31" "eleven\ntwelve\nthirteen\n" \ 55 "-c 32" "eleven\t\tthirteen\ntwelve\n" \ 56 "-xc 32" "eleven\t\ttwelve\nthirteen\n" 57tc1 ".,word.,\n\t \t\n\nx.word\n" "-t -s .," "word\nx word\n" 58tc1 "1 2 3\n4 5\n" "-t" "1 2 3\n4 5\n" 59tc1 "abc\tbc\tc\nab\tabc\tbc\na\tab\tabc\n" \ 60 "-t" "abc bc c\nab abc bc\na ab abc\n" 61 62[ $fail -eq 0 ] && exit 0 63echo "column: $fail tests failed" 64exit 1 65