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
|
---|
20 | print_ver_ sed
|
---|
21 |
|
---|
22 | #
|
---|
23 | # Test \dNNN conversions
|
---|
24 | #
|
---|
25 | printf "%s\n" a a a a a a a > in-d || framework_failure_
|
---|
26 |
|
---|
27 | # Each line is a separate test case
|
---|
28 | cat <<\EOF >prog-d
|
---|
29 | # Expected output: ASCII 0x0D '\r'
|
---|
30 | 1s/./\d13/
|
---|
31 |
|
---|
32 | # Expected output: ASCII 0xff '\3ff'
|
---|
33 | 2s/./\d255/
|
---|
34 |
|
---|
35 | # Expected (?) output: 'dB'
|
---|
36 | # (\d followed by character >= base 10, treated as '\d', which is 'd').
|
---|
37 | 3s/./\dB/
|
---|
38 |
|
---|
39 | # Expected (?) output: 'dQ'
|
---|
40 | # (\d followed by non-hex character, treated as '\d', which is 'd').
|
---|
41 | 4s/./\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.
|
---|
46 | 5s/./\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.
|
---|
52 | 6s/./\d513/
|
---|
53 |
|
---|
54 | # Expected output: '\0','7'
|
---|
55 | # (three digit limit)
|
---|
56 | 7s/./\d0007/
|
---|
57 | EOF
|
---|
58 |
|
---|
59 | printf '\r\n\377\ndB\ndQ\n{4\n\1\n\0007\n' > exp-d || framework_failure_
|
---|
60 |
|
---|
61 | sed -f prog-d in-d > out-d || fail=1
|
---|
62 | compare_ exp-d out-d || fail=1
|
---|
63 |
|
---|
64 | if test "$fail" -eq 1 ; then
|
---|
65 | od -tx1c prog-d
|
---|
66 | od -tx1c exp-d
|
---|
67 | od -tx1c out-d
|
---|
68 | fi
|
---|
69 |
|
---|
70 |
|
---|
71 |
|
---|
72 |
|
---|
73 | #
|
---|
74 | # Test \oNNN conversions
|
---|
75 | #
|
---|
76 | printf "%s\n" a a a a a a > in-o || framework_failure_
|
---|
77 |
|
---|
78 | # Each line is a separate test case
|
---|
79 | cat <<\EOF >prog-o
|
---|
80 | # Expected output: '\5'
|
---|
81 | 1s/./\o5/
|
---|
82 |
|
---|
83 | # Expected output: ASCII 0xff '\3ff'
|
---|
84 | 2s/./\o377/
|
---|
85 |
|
---|
86 | # Expected (?) output: 'o9'
|
---|
87 | # (\o followed by character >= base 18, treated as '\o', which is 'o').
|
---|
88 | 3s/./\o9/
|
---|
89 |
|
---|
90 | # Expected (?) output: 'oQ'
|
---|
91 | # (\o followed by non-hex character, treated as '\o', which is 'o').
|
---|
92 | 4s/./\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.
|
---|
97 | 5s/./\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.
|
---|
103 | 6s/./\o401/
|
---|
104 | EOF
|
---|
105 |
|
---|
106 | printf '\5\n\377\no9\noQ\nS4\n\1\n' > exp-o || framework_failure_
|
---|
107 |
|
---|
108 | sed -f prog-o in-o > out-o || fail=1
|
---|
109 | compare_ exp-o out-o || fail=1
|
---|
110 |
|
---|
111 | if test "$fail" -eq 1 ; then
|
---|
112 | od -tx1c prog-o
|
---|
113 | od -tx1c exp-o
|
---|
114 | od -tx1c out-o
|
---|
115 | fi
|
---|
116 |
|
---|
117 |
|
---|
118 |
|
---|
119 |
|
---|
120 |
|
---|
121 | #
|
---|
122 | # Test \xNN conversions
|
---|
123 | #
|
---|
124 | printf "%s\n" a a a a > in-x || framework_failure_
|
---|
125 |
|
---|
126 | # Each line is a separate test case
|
---|
127 | cat <<\EOF >prog-x
|
---|
128 | # Expected output: ASCII 0x06 '\6'
|
---|
129 | 1s/./\x6/
|
---|
130 |
|
---|
131 | # Expected output: ASCII 0xCE '\316'
|
---|
132 | 2s/./\xce/
|
---|
133 |
|
---|
134 | # Expected (?) output: 'xy'
|
---|
135 | # (\x followed by non-hex character, treated as '\x', which is 'x').
|
---|
136 | 3s/./\xy/
|
---|
137 |
|
---|
138 | # Expected output: '\253' 'c' (0xAB = 253 octal)
|
---|
139 | # \xNN is limited to two digits.
|
---|
140 | 4s/./\xabc/
|
---|
141 | EOF
|
---|
142 |
|
---|
143 | printf '\6\n\316\nxy\n\253c\n' > exp-x || framework_failure_
|
---|
144 |
|
---|
145 | sed -f prog-x in-x > out-x || fail=1
|
---|
146 | compare_ exp-x out-x || fail=1
|
---|
147 |
|
---|
148 | if test "$fail" -eq 1 ; then
|
---|
149 | od -tx1c prog-x
|
---|
150 | od -tx1c exp-x
|
---|
151 | od -tx1c out-x
|
---|
152 | fi
|
---|
153 |
|
---|
154 |
|
---|
155 | # for completeness, cover all possible letters/digits
|
---|
156 |
|
---|
157 | printf "%s\n" a a a a a a a a a a a > cnv-num-in || framework_failure_
|
---|
158 | cat << \EOF > cnv-num-prog || framework_failure_
|
---|
159 | 1s/./\x01/
|
---|
160 | 2s/./\x23/
|
---|
161 | 3s/./\x45/
|
---|
162 | 4s/./\x67/
|
---|
163 | 5s/./\x89/
|
---|
164 | 6s/./\xAB/
|
---|
165 | 7s/./\xab/
|
---|
166 | 8s/./\xCD/
|
---|
167 | 9s/./\xcd/
|
---|
168 | 10s/./\xef/
|
---|
169 | 11s/./\xEF/
|
---|
170 | EOF
|
---|
171 |
|
---|
172 | printf '\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 |
|
---|
175 | sed -f cnv-num-prog cnv-num-in > cnv-num-out || fail=1
|
---|
176 | compare_ cnv-num-exp cnv-num-out || fail=1
|
---|
177 |
|
---|
178 | Exit $fail
|
---|