source: trunk/src/sed/testsuite/convert-number.sh@ 3670

Last change on this file since 3670 was 3613, checked in by bird, 10 months ago

src/sed: Merged in changes between 4.1.5 and 4.9 from the vendor branch. (svn merge /vendor/sed/4.1.5 /vendor/sed/current .)

  • Property svn:executable set to *
File size: 4.0 KB
Line 
1#!/bin/sh
2# Test number conversion from escape sequences \xNN \oNNN \dNNN
3# (compile.c:convert_number())
4
5# Copyright (C) 2016-2022 Free Software Foundation, Inc.
6
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <https://www.gnu.org/licenses/>.
19. "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed
20print_ver_ sed
21
22#
23# Test \dNNN conversions
24#
25printf "%s\n" a a a a a a a > in-d || framework_failure_
26
27# Each line is a separate test case
28cat <<\EOF >prog-d
29# Expected output: ASCII 0x0D '\r'
301s/./\d13/
31
32# Expected output: ASCII 0xff '\3ff'
332s/./\d255/
34
35# Expected (?) output: 'dB'
36# (\d followed by character >= base 10, treated as '\d', which is 'd').
373s/./\dB/
38
39# Expected (?) output: 'dQ'
40# (\d followed by non-hex character, treated as '\d', which is 'd').
414s/./\dQ/
42
43# Expected output: '{4'
44# \dNNN is limited to three digits.
45# The first three digits are 123 = 0x7b = '{'. '4' is treated as-is.
465s/./\d1234/
47
48# Expected (?) output: '\1'
49# undocumented implementation-specific limitation:
50# After 3 digit limits, the 8-bit value is used,
51# decimal 513 wraps-around to 1.
526s/./\d513/
53
54# Expected output: '\0','7'
55# (three digit limit)
567s/./\d0007/
57EOF
58
59printf '\r\n\377\ndB\ndQ\n{4\n\1\n\0007\n' > exp-d || framework_failure_
60
61sed -f prog-d in-d > out-d || fail=1
62compare_ exp-d out-d || fail=1
63
64if test "$fail" -eq 1 ; then
65 od -tx1c prog-d
66 od -tx1c exp-d
67 od -tx1c out-d
68fi
69
70
71
72
73#
74# Test \oNNN conversions
75#
76printf "%s\n" a a a a a a > in-o || framework_failure_
77
78# Each line is a separate test case
79cat <<\EOF >prog-o
80# Expected output: '\5'
811s/./\o5/
82
83# Expected output: ASCII 0xff '\3ff'
842s/./\o377/
85
86# Expected (?) output: 'o9'
87# (\o followed by character >= base 18, treated as '\o', which is 'o').
883s/./\o9/
89
90# Expected (?) output: 'oQ'
91# (\o followed by non-hex character, treated as '\o', which is 'o').
924s/./\oQ/
93
94# Expected output: 'S4'
95# \oNNN is limited to three digits.
96# The first three digits are o123 = 0x53 = 'S'. '4' is treated as-is.
975s/./\o1234/
98
99# Expected (?) output: '\1'
100# undocumented implementation-specific limitation:
101# After 3 digit limits, the 8-bit value is used,
102# octal 401 wraps-around to 1.
1036s/./\o401/
104EOF
105
106printf '\5\n\377\no9\noQ\nS4\n\1\n' > exp-o || framework_failure_
107
108sed -f prog-o in-o > out-o || fail=1
109compare_ exp-o out-o || fail=1
110
111if test "$fail" -eq 1 ; then
112 od -tx1c prog-o
113 od -tx1c exp-o
114 od -tx1c out-o
115fi
116
117
118
119
120
121#
122# Test \xNN conversions
123#
124printf "%s\n" a a a a > in-x || framework_failure_
125
126# Each line is a separate test case
127cat <<\EOF >prog-x
128# Expected output: ASCII 0x06 '\6'
1291s/./\x6/
130
131# Expected output: ASCII 0xCE '\316'
1322s/./\xce/
133
134# Expected (?) output: 'xy'
135# (\x followed by non-hex character, treated as '\x', which is 'x').
1363s/./\xy/
137
138# Expected output: '\253' 'c' (0xAB = 253 octal)
139# \xNN is limited to two digits.
1404s/./\xabc/
141EOF
142
143printf '\6\n\316\nxy\n\253c\n' > exp-x || framework_failure_
144
145sed -f prog-x in-x > out-x || fail=1
146compare_ exp-x out-x || fail=1
147
148if test "$fail" -eq 1 ; then
149 od -tx1c prog-x
150 od -tx1c exp-x
151 od -tx1c out-x
152fi
153
154
155# for completeness, cover all possible letters/digits
156
157printf "%s\n" a a a a a a a a a a a > cnv-num-in || framework_failure_
158cat << \EOF > cnv-num-prog || framework_failure_
1591s/./\x01/
1602s/./\x23/
1613s/./\x45/
1624s/./\x67/
1635s/./\x89/
1646s/./\xAB/
1657s/./\xab/
1668s/./\xCD/
1679s/./\xcd/
16810s/./\xef/
16911s/./\xEF/
170EOF
171
172printf '\1\n#\nE\ng\n\211\n\253\n\253\n\315\n\315\n\357\n\357\n' \
173 > cnv-num-exp || framework_failure_
174
175sed -f cnv-num-prog cnv-num-in > cnv-num-out || fail=1
176compare_ cnv-num-exp cnv-num-out || fail=1
177
178Exit $fail
Note: See TracBrowser for help on using the repository browser.