summaryrefslogtreecommitdiff
path: root/testsuite/subst-options.sh
blob: 7daf9dc22dbccb38de3bdf33d0a0c77b1510bc38 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/sh
# Test Substitute options (for code-coverage purposes as well)

# Copyright (C) 2016-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

#
# Simple modifiers to s//
# (specific characters included as make_subst_opts's implementation
#  checks for them before returning control)
printf "%s\n" a a a a a a > subst-in1 || framework_failure_
printf "%s\n" x x x x x x > subst-exp1 || framework_failure_
cat << \EOF >> subst-prog1 || framework_failure_
1s/A/x/i
2s/A/x/I

# s// followed by '}'
3{s/./x/}
# s// followed by '#'
4s/./x/#
# s// followed by ';'
5s/./x/;
# s// followed by '\n
6s/./x/
EOF

sed -f subst-prog1 subst-in1 > subst-out1 || fail=1
compare_ subst-exp1 subst-out1 || fail=1


#
# Number modifiers to s//
#

cat << \EOF >subst-in2 || framework_failure_
bbbbbbbbbb
bbbbbbbbbb
bbbbbbbbbb
bbbbbbbbbb
bbbbbbbbbb
bbbbbbbbbb
bbbbbbbbbb
bbbbbbbbbb
bbbbbbbbbb
bbbbbbbbbb
EOF

cat << \EOF >subst-prog2 || framework_failure_
1s/./x/g
2s/./x/1
3s/./x/2
4s/./x/3
5s/./x/4
6s/./x/5
7s/./x/6
8s/./x/7
9s/./x/8
10s/./x/9
EOF

cat << \EOF >subst-exp2
xxxxxxxxxx
xbbbbbbbbb
bxbbbbbbbb
bbxbbbbbbb
bbbxbbbbbb
bbbbxbbbbb
bbbbbxbbbb
bbbbbbxbbb
bbbbbbbxbb
bbbbbbbbxb
EOF

sed -f subst-prog2 subst-in2 > subst-out2 || fail=1
compare_ subst-exp2 subst-out2 || fail=1

#
# Multiline modifier: s///m
# ('N' will read and concatenate the second line
#  into the patten space, making it "foo\nbar".
#  s// will then operate on it as one string).
printf "foo\nbar\n" > subst-in3 || fail=1
printf "Xoo\nXar\n" > subst-exp3 || fail=1

sed 'N;s/^./X/gm' subst-in3 > subst-out3-1 || fail=1
compare_ subst-exp3 subst-out3-1 || fail=1
sed 'N;s/^./X/gM' subst-in3 > subst-out3-2 || fail=1
compare_ subst-exp3 subst-out3-2 || fail=1

# sanity-check: without m, only the first line should match
printf "Xoo\nbar\n" > subst-exp3-3 || fail=1
sed 'N;s/^./X/g' subst-in3 > subst-out3-3 || fail=1
compare_ subst-exp3-3 subst-out3-3 || fail=1


#
# s// followed by \r\n
#

printf "s/./X/\r\n" > subst-prog4 || framework_failure_
echo a > subst-in4 || framework_failure_
echo X > subst-exp4 || framework_failure_
sed -f subst-prog4 subst-in4 > subst-out4 || fail=1
compare_ subst-exp4 subst-out4 || fail=1




Exit $fail