summaryrefslogtreecommitdiff
path: root/regress/tools/files/tr-test.sh
blob: 32366311a5581e2db85d2317eae54a5578b005e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#! /bin/sh
# $NetBSD: tr-test.sh,v 1.2 2005/11/24 19:46:45 rillig Exp $
#

set -e

mydir=`dirname "$0"`
. "${mydir}/tests.subr"

#
# Functions specific for the tr testsuite.
#

# usage: tr_test <testname> <input> <expected-output> <args...>
tr_test() {
	testname=$1; input=$2; expected=$3; shift 3;

	testcase_start "${testname}"
	output=`tr "$@" <<EOF
$input
EOF
`
	assert_equal "${testname}" "${expected}" "${output}"
}

#
# The actual test.
#

nl="
"

tr_test "simple" \
	"foo" "baa" "fo" "ba"
tr_test "tolower" \
	"The Great Green Fox" "the great green fox" "A-Z" "a-z"
tr_test "eat-newlines" \
	"foo${nl}bar${nl}" "foobar" -d "\\n"
tr_test "eat-minus" \
	"describe-function" "describefunction" -d "-"
# The following test does not work on NetBSD 1.6.2.
#tr_test "eat-minus-d" \
#	"describe-function" "escribefunction" -d "-d"
tr_test "eat-d-minus" \
	"describe-function" "escribefunction" -d "d-"

s="0123456789abcdef"
s="$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s"
s="$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s"
s="$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s"
f="ffffffffffffffff"
f="$f$f$f$f$f$f$f$f$f$f$f$f$f$f$f$f"
f="$f$f$f$f$f$f$f$f$f$f$f$f$f$f$f$f"

tr_test "65536" \
	"$s" "$f" -d "0-9a-e"