2 # Test case conversion classes
4 # Copyright (C) 2010-2024 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 .
"${srcdir=.}/tests/init.sh"; path_prepend_ .
/src
22 # Ensure we support translation of case classes with extension
23 echo '01234567899999999999999999' > exp
24 echo 'abcdefghijklmnopqrstuvwxyz' |
25 tr '[:lower:]' '0-9' > out || fail
=1
26 compare exp out || fail
=1
27 echo 'abcdefghijklmnopqrstuvwxyz' |
28 tr '[:lower:][:lower:]' '[:upper:]0-9' > out || fail
=1
29 compare exp out || fail
=1
31 # Validate the alignment of case classes
32 returns_
1 tr 'A-Z[:lower:]' 'a-y[:upper:]' </dev
/null || fail
=1
33 returns_
1 tr '[:upper:][:lower:]' 'a-y[:upper:]' </dev
/null || fail
=1
34 returns_
1 tr 'A-Y[:lower:]' 'a-z[:upper:]' </dev
/null || fail
=1
35 returns_
1 tr 'A-Z[:lower:]' '[:lower:][:upper:]' </dev
/null || fail
=1
36 returns_
1 tr 'A-Z[:lower:]' '[:lower:]A-Z' </dev
/null || fail
=1
37 tr '[:upper:][:lower:]' 'a-z[:upper:]' < /dev
/null || fail
=1
38 tr '[:upper:][:lower:]' '[:upper:]a-z' < /dev
/null || fail
=1
40 # Before coreutils 8.6 the trailing space in string1
41 # caused the case class in string2 to be extended.
42 # However that was not portable, dependent on locale
43 # and in contravention of POSIX.
44 tr '[:upper:] ' '[:lower:]' < /dev
/null
2>out
&& fail
=1
45 echo 'tr: when translating with string1 longer than string2,
46 the latter string must not end with a character class' > exp
47 compare exp out || fail
=1
49 # Up to coreutils-6.9, tr rejected an unmatched [:lower:] or [:upper:] in SET1.
50 echo '#$%123abcABC' |
tr '[:lower:]' '[.*]' > out || fail
=1
51 echo '#$%123...ABC' > exp
52 compare exp out || fail
=1
53 echo '#$%123abcABC' |
tr '[:upper:]' '[.*]' > out || fail
=1
54 echo '#$%123abc...' > exp
55 compare exp out || fail
=1
57 # When doing a case-converting translation with something after the
58 # [:upper:] and [:lower:] elements, ensure that tr honors the following byte.
59 echo 'abc.' |
tr '[:lower:].' '[:upper:]x' > out || fail
=1
61 compare exp out || fail
=1
63 # Before coreutils 8.6 the disparate number of upper and lower
64 # characters in some locales, triggered abort()s and invalid behavior
65 export LC_ALL
=en_US.ISO-8859-1
67 if test "$(locale charmap 2>/dev/null)" = ISO-8859-1
; then
68 # Up to coreutils-6.9.91, this would fail with the diagnostic:
69 # tr: misaligned [:upper:] and/or [:lower:] construct
70 # with LC_CTYPE=en_US.ISO-8859-1.
71 tr '[:upper:]' '[:lower:]' < /dev
/null || fail
=1
73 tr '[:upper:] ' '[:lower:]' < /dev
/null
2>out
&& fail
=1
74 echo 'tr: when translating with string1 longer than string2,
75 the latter string must not end with a character class' > exp
76 compare exp out || fail
=1
78 # Ensure when there are a different number of elements
79 # in each string, we validate the case mapping correctly
81 tr 'ab[:lower:]' '0-1[:upper:]' > out || fail
=1
83 compare exp out || fail
=1
85 # Ensure we extend string2 appropriately
87 tr '[:upper:]- ' '[:lower:]_' > out || fail
=1
89 compare exp out || fail
=1
91 # Ensure the size of the case classes are accounted
93 echo 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
94 tr '[:upper:]A-B' '[:lower:]0' >out || fail
=1
95 echo '00cdefghijklmnopqrstuvwxyz' > exp
96 compare exp out || fail
=1
98 # Ensure the size of the case classes are accounted
101 tr -t '[:lower:]a' '[:upper:]0' >out || fail
=1
103 compare exp out || fail
=1
105 # Ensure the size of the case classes are accounted
108 tr -t '[:lower:][:lower:]a' '[:lower:][:upper:]0' >out || fail
=1
110 compare exp out || fail
=1
113 # coreutils 8.6 - 8.32 inclusive, would abort trying to validate the following
114 returns_
1 tr -c '[:upper:]\000-\370' '[:lower:]' < /dev
/null || fail
=1