1 | #!/bin/sh
|
---|
2 | # Test 's' and 'y' non-slash delimiters in multibyte locales
|
---|
3 |
|
---|
4 | # Copyright (C) 2016-2022 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 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed
|
---|
19 | print_ver_ sed
|
---|
20 |
|
---|
21 | require_en_utf8_locale_
|
---|
22 |
|
---|
23 | # These tests use the following unicode character in various ways:
|
---|
24 | # GREEK CAPITAL LETTER PHI (U+03A6)
|
---|
25 | # UTF-8: hex: 0xCE 0xA6
|
---|
26 | # oct: 0316 0246
|
---|
27 | # bin: 11001110 10100110
|
---|
28 | #
|
---|
29 | # Octal encoding is used due to printf not supporting hex on older systems.
|
---|
30 | # Using the first octet alone (\316) causes various multibyte related functions
|
---|
31 | # to return '-2' (incomplete multibyte sequence).
|
---|
32 | # using the second octet alone (\246) causess same functions to return '-1'
|
---|
33 | # (ivalid multibyte sequence).
|
---|
34 |
|
---|
35 |
|
---|
36 | # Reject a valid multibyte delimiter (instead of slash).
|
---|
37 | printf 's\316\246a\316\246b\316\246' > prog1 || framework_failure_
|
---|
38 |
|
---|
39 | cat <<\EOF > exp-err1 || framework_failure_
|
---|
40 | sed: file prog1 line 1: delimiter character is not a single-byte character
|
---|
41 | EOF
|
---|
42 |
|
---|
43 | returns_ 1 env LC_ALL=en_US.UTF-8 sed -f prog1 < /dev/null 2>err1 || fail=1
|
---|
44 | compare_ exp-err1 err1 || fail=1
|
---|
45 |
|
---|
46 |
|
---|
47 | # Reject an incomplete multibyte delimiter (instead of slash).
|
---|
48 | # This is an implmentation-specific behavior:
|
---|
49 | # error is triggered upon first octet, before entire multibyte character
|
---|
50 | # is scanned.
|
---|
51 | printf 's\316a\316b\316' > prog2 || framework_failure_
|
---|
52 |
|
---|
53 | cat <<\EOF > exp-err2 || framework_failure_
|
---|
54 | sed: file prog2 line 1: delimiter character is not a single-byte character
|
---|
55 | EOF
|
---|
56 |
|
---|
57 | returns_ 1 env LC_ALL=en_US.UTF-8 sed -f prog2 </dev/null 2>err2 || fail=1
|
---|
58 | compare_ exp-err2 err2 || fail=1
|
---|
59 |
|
---|
60 | # ... but accept octet \316 as delimiter in C locale
|
---|
61 | echo a > in2 || framework_failure_
|
---|
62 | echo b > exp2 || framework_failure_
|
---|
63 | LC_ALL=C sed -f prog2 <in2 >out2 || fail=1
|
---|
64 | compare_ exp2 out2 || fail=1
|
---|
65 |
|
---|
66 |
|
---|
67 |
|
---|
68 | # An invalid multibyte sequence is treated as a valid single byte,
|
---|
69 | # thus accepted as a delimter (instead of slash).
|
---|
70 | # This is an implmentation-specific behavior.
|
---|
71 | printf 's\246a\246b\246' > prog3 || framework_failure_
|
---|
72 | echo a > in3 || framework_failure_
|
---|
73 | echo b > exp3 || framework_failure_
|
---|
74 |
|
---|
75 | LC_ALL=en_US.UTF-8 sed -f prog3 <in3 >out3 || fail=1
|
---|
76 | compare_ exp3 out3 || fail=1
|
---|
77 |
|
---|
78 | # Expect identical result in C locale
|
---|
79 | LC_ALL=C sed -f prog3 <in3 >out4 || fail=1
|
---|
80 | compare_ exp3 out4 || fail=1
|
---|
81 |
|
---|
82 |
|
---|
83 | Exit $fail
|
---|