summaryrefslogtreecommitdiff
path: root/testsuite/cmd-0r.sh
blob: 5c6fcf96e977273eae2dc01d08514e79b2b27eb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh
# Test '0rFILE' command

# Copyright (C) 2021-2023 Free Software Foundation, Inc.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
. "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed
print_ver_ sed

cat <<\EOF >in1 || framework_failure_
HELLO
WORLD
EOF

cat <<\EOF >in2 || framework_failure_
1
2
3
EOF

cat <<\EOF >exp1 || framework_failure_
HELLO
WORLD
1
2
3
EOF

cat <<\EOF >exp2 || framework_failure_
1
HELLO
WORLD
2
HELLO
WORLD
3
EOF

cat <<\EOF> exp-err-addr0 || framework_failure_
sed: -e expression #1, char 4: invalid usage of line address 0
EOF

# Typical usage
sed '0rin1' in2 >out1 || fail=1
compare_ exp1 out1 || fail=1

# Ensure no regression for '0,/REGEXP/r'
sed '0,/2/rin1' in2 >out2 || fail=1
compare_ exp2 out2 || fail=1

# Ensure '0r' doesn't accept a numeric address range
returns_ 1 sed '0,4rin1' in2 2>err3 || fail=1
compare_ exp-err-addr0 err3 || fail=1

# Test with -i
sed -i '0rin1' in2 || fail=1
compare_ exp1 in2 || fail=1

Exit $fail