~ubuntu-branches/ubuntu/utopic/coreutils/utopic-proposed

« back to all changes in this revision

Viewing changes to tests/misc/tr-case-class.sh

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-11-28 03:03:42 UTC
  • mfrom: (8.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20121128030342-21zanj8354gas5gr
Tags: 8.20-3ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Make 'uname -i -p' return the real processor/hardware, instead of
    unknown.
  - Build-depend on gettext:any instead of on gettext, so that apt-get can
    properly resolve build-dependencies on the tool when cross-building.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
# Test case conversion classes
 
3
 
 
4
# Copyright (C) 2010-2012 Free Software Foundation, Inc.
 
5
 
 
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.
 
10
 
 
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.
 
15
 
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 
 
19
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 
20
print_ver_ tr
 
21
 
 
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
 
30
 
 
31
# Validate the alignment of case classes
 
32
tr 'A-Z[:lower:]' 'a-y[:upper:]' < /dev/null && fail=1
 
33
tr '[:upper:][:lower:]' 'a-y[:upper:]' < /dev/null && fail=1
 
34
tr 'A-Y[:lower:]' 'a-z[:upper:]' < /dev/null && fail=1
 
35
tr 'A-Z[:lower:]' '[:lower:][:upper:]' < /dev/null && fail=1
 
36
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
 
39
 
 
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
 
48
 
 
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
 
56
 
 
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
 
60
echo 'ABCx' > exp
 
61
compare exp out || fail=1
 
62
 
 
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
 
66
 
 
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
 
72
 
 
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
 
77
 
 
78
  # Ensure when there are a different number of elements
 
79
  # in each string, we validate the case mapping correctly
 
80
  echo 'abc.xyz' |
 
81
  tr 'ab[:lower:]' '0-1[:upper:]' > out || fail=1
 
82
  echo 'ABC.XYZ' > exp
 
83
  compare exp out || fail=1
 
84
 
 
85
  # Ensure we extend string2 appropriately
 
86
  echo 'ABC- XYZ' |
 
87
  tr '[:upper:]- ' '[:lower:]_' > out || fail=1
 
88
  echo 'abc__xyz' > exp
 
89
  compare exp out || fail=1
 
90
 
 
91
  # Ensure the size of the case classes are accounted
 
92
  # for as a unit.
 
93
  echo 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
 
94
  tr '[:upper:]A-B' '[:lower:]0' >out || fail=1
 
95
  echo '00cdefghijklmnopqrstuvwxyz' > exp
 
96
  compare exp out || fail=1
 
97
 
 
98
  # Ensure the size of the case classes are accounted
 
99
  # for as a unit.
 
100
  echo 'a' |
 
101
  tr -t '[:lower:]a' '[:upper:]0' >out || fail=1
 
102
  echo '0' > exp
 
103
  compare exp out || fail=1
 
104
 
 
105
  # Ensure the size of the case classes are accounted
 
106
  # for as a unit.
 
107
  echo 'a' |
 
108
  tr -t '[:lower:][:lower:]a' '[:lower:][:upper:]0' >out || fail=1
 
109
  echo '0' > exp
 
110
  compare exp out || fail=1
 
111
fi
 
112
 
 
113
Exit $fail