1#!/bin/sh 2# Test case conversion classes 3 4# Copyright (C) 2010-2023 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 <https://www.gnu.org/licenses/>. 18 19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src 20print_ver_ tr 21 22# Ensure we support translation of case classes with extension 23echo '01234567899999999999999999' > exp 24echo 'abcdefghijklmnopqrstuvwxyz' | 25tr '[:lower:]' '0-9' > out || fail=1 26compare exp out || fail=1 27echo 'abcdefghijklmnopqrstuvwxyz' | 28tr '[:lower:][:lower:]' '[:upper:]0-9' > out || fail=1 29compare exp out || fail=1 30 31# Validate the alignment of case classes 32returns_ 1 tr 'A-Z[:lower:]' 'a-y[:upper:]' </dev/null || fail=1 33returns_ 1 tr '[:upper:][:lower:]' 'a-y[:upper:]' </dev/null || fail=1 34returns_ 1 tr 'A-Y[:lower:]' 'a-z[:upper:]' </dev/null || fail=1 35returns_ 1 tr 'A-Z[:lower:]' '[:lower:][:upper:]' </dev/null || fail=1 36returns_ 1 tr 'A-Z[:lower:]' '[:lower:]A-Z' </dev/null || fail=1 37tr '[:upper:][:lower:]' 'a-z[:upper:]' < /dev/null || fail=1 38tr '[: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. 44tr '[:upper:] ' '[:lower:]' < /dev/null 2>out && fail=1 45echo 'tr: when translating with string1 longer than string2, 46the latter string must not end with a character class' > exp 47compare exp out || fail=1 48 49# Up to coreutils-6.9, tr rejected an unmatched [:lower:] or [:upper:] in SET1. 50echo '#$%123abcABC' | tr '[:lower:]' '[.*]' > out || fail=1 51echo '#$%123...ABC' > exp 52compare exp out || fail=1 53echo '#$%123abcABC' | tr '[:upper:]' '[.*]' > out || fail=1 54echo '#$%123abc...' > exp 55compare 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. 59echo 'abc.' | tr '[:lower:].' '[:upper:]x' > out || fail=1 60echo 'ABCx' > exp 61compare 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 65export LC_ALL=en_US.ISO-8859-1 66 67if 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, 75the 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 111fi 112 113# coreutils 8.6 - 8.32 inclusive, would abort trying to validate the following 114returns_ 1 tr -c '[:upper:]\000-\370' '[:lower:]' < /dev/null || fail=1 115 116Exit $fail 117