summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am1
-rwxr-xr-xtests/misc/tr26
-rwxr-xr-xtests/misc/tr-case-class112
3 files changed, 113 insertions, 26 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5619d0b76..3236637c6 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -260,6 +260,7 @@ TESTS = \
misc/timeout \
misc/timeout-parameters \
misc/tr \
+ misc/tr-case-class \
misc/truncate-dangling-symlink \
misc/truncate-dir-fail \
misc/truncate-fail-diag \
diff --git a/tests/misc/tr b/tests/misc/tr
index ca7a960bb..00cd8e62c 100755
--- a/tests/misc/tr
+++ b/tests/misc/tr
@@ -155,34 +155,8 @@ my @Tests =
# Up to coreutils-6.9, this would provoke a failed assertion.
['no-abort-1', qw(-c a '[b*256]'), {IN=>'abc'}, {OUT=>'abb'}],
-
- # Up to coreutils-6.9, tr rejected an unmatched [:lower:] or [:upper:] in SET1.
- ['s1-lower', qw('[:lower:]' '[.*]'),
- {IN=>'#$%123abcABC'}, {OUT=>'#$%123...ABC'}],
- ['s1-upper', qw('[:upper:]' '[.*]'),
- {IN=>'#$%123abcABC'}, {OUT=>'#$%123abc...'}],
-
- # Up to coreutils-6.9.91, this would fail with the diagnostic:
- # tr: misaligned [:upper:] and/or [:lower:] construct
- # with LC_CTYPE=en_US.ISO-8859-1.
- ['tolower-F', qw('[:upper:]' '[:lower:]'), {IN=>'A'}, {OUT=>'a'}],
-
- # When doing a case-converting translation with something after the
- # [:upper:] and [:lower:] elements, ensure that tr honors the following byte.
- ['upcase-xtra', qw('[:lower:].' '[:upper:]x'), {IN=>'abc.'}, {OUT=>'ABCx'}],
- ['dncase-xtra', qw('[:upper:].' '[:lower:]x'), {IN=>'ABC.'}, {OUT=>'abcx'}],
);
-# Set LC_CTYPE=en_US.ISO-8859-1 in the environment of the tolower-F test.
-foreach my $t (@Tests)
- {
- if ($t->[0] eq 'tolower-F')
- {
- push @$t, {ENV=>'LC_CTYPE=en_US.ISO-8859-1'};
- last;
- }
- }
-
@Tests = triple_test \@Tests;
# tr takes its input only from stdin, not from a file argument, so
diff --git a/tests/misc/tr-case-class b/tests/misc/tr-case-class
new file mode 100755
index 000000000..d81c676c3
--- /dev/null
+++ b/tests/misc/tr-case-class
@@ -0,0 +1,112 @@
+#!/bin/sh
+# Test case conversion classes
+
+# Copyright (C) 2010 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+# Ensure we support translation of case classes with extension
+echo '01234567899999999999999999' > exp
+echo 'abcdefghijklmnopqrstuvwxyz' |
+tr '[:lower:]' '0-9' > out || fail=1
+compare out exp || fail=1
+echo 'abcdefghijklmnopqrstuvwxyz' |
+tr '[:lower:][:lower:]' '[:upper:]0-9' > out || fail=1
+compare out exp || fail=1
+
+# Validate the alignment of case classes
+tr 'A-Z[:lower:]' 'a-y[:upper:]' < /dev/null && fail=1
+tr '[:upper:][:lower:]' 'a-y[:upper:]' < /dev/null && fail=1
+tr 'A-Y[:lower:]' 'a-z[:upper:]' < /dev/null && fail=1
+tr 'A-Z[:lower:]' '[:lower:][:upper:]' < /dev/null && fail=1
+tr 'A-Z[:lower:]' '[:lower:]A-Z' < /dev/null && fail=1
+tr '[:upper:][:lower:]' 'a-z[:upper:]' < /dev/null || fail=1
+tr '[:upper:][:lower:]' '[:upper:]a-z' < /dev/null || fail=1
+
+# Before coreutils 8.6 the trailing space in string1
+# caused the case class in string2 to be extended.
+# However that was not portable, dependent on locale
+# and in contravention of POSIX.
+tr '[:upper:] ' '[:lower:]' < /dev/null 2>out && fail=1
+echo 'tr: when translating with string1 longer than string2,
+the latter string must not end with a character class' > exp
+compare out exp || fail=1
+
+# Up to coreutils-6.9, tr rejected an unmatched [:lower:] or [:upper:] in SET1.
+echo '#$%123abcABC' | tr '[:lower:]' '[.*]' > out || fail=1
+echo '#$%123...ABC' > exp
+compare out exp || fail=1
+echo '#$%123abcABC' | tr '[:upper:]' '[.*]' > out || fail=1
+echo '#$%123abc...' > exp
+compare out exp || fail=1
+
+# When doing a case-converting translation with something after the
+# [:upper:] and [:lower:] elements, ensure that tr honors the following byte.
+echo 'abc.' | tr '[:lower:].' '[:upper:]x' > out || fail=1
+echo 'ABCx' > exp
+compare out exp || fail=1
+
+# Before coreutils 8.6 the disparate number of upper and lower
+# characters in some locales, triggered abort()s and invalid behavior
+export LC_ALL=en_US.ISO-8859-1
+
+if test "$(locale charmap 2>/dev/null)" = ISO-8859-1; then
+ # Up to coreutils-6.9.91, this would fail with the diagnostic:
+ # tr: misaligned [:upper:] and/or [:lower:] construct
+ # with LC_CTYPE=en_US.ISO-8859-1.
+ tr '[:upper:]' '[:lower:]' < /dev/null || fail=1
+
+ tr '[:upper:] ' '[:lower:]' < /dev/null 2>out && fail=1
+ echo 'tr: when translating with string1 longer than string2,
+the latter string must not end with a character class' > exp
+ compare out exp || fail=1
+
+ # Ensure when there are a different number of elements
+ # in each string, we validate the case mapping correctly
+ echo 'abc.xyz' |
+ tr 'ab[:lower:]' '0-1[:upper:]' > out || fail=1
+ echo 'ABC.XYZ' > exp
+ compare out exp || fail=1
+
+ # Ensure we extend string2 appropriately
+ echo 'ABC- XYZ' |
+ tr '[:upper:]- ' '[:lower:]_' > out || fail=1
+ echo 'abc__xyz' > exp
+ compare out exp || fail=1
+
+ # Ensure the size of the case classes are accounted
+ # for as a unit.
+ echo 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
+ tr '[:upper:]A-B' '[:lower:]0' >out || fail=1
+ echo '00cdefghijklmnopqrstuvwxyz' > exp
+ compare out exp || fail=1
+
+ # Ensure the size of the case classes are accounted
+ # for as a unit.
+ echo 'a' |
+ tr -t '[:lower:]a' '[:upper:]0' >out || fail=1
+ echo '0' > exp
+ compare out exp || fail=1
+
+ # Ensure the size of the case classes are accounted
+ # for as a unit.
+ echo 'a' |
+ tr -t '[:lower:][:lower:]a' '[:lower:][:upper:]0' >out || fail=1
+ echo '0' > exp
+ compare out exp || fail=1
+fi
+
+Exit $fail