1 | #!/bin/sh
|
---|
2 | # Test Substitute options (for code-coverage purposes as well)
|
---|
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 | #
|
---|
22 | # Simple modifiers to s//
|
---|
23 | # (specific characters included as make_subst_opts's implementation
|
---|
24 | # checks for them before returning control)
|
---|
25 | printf "%s\n" a a a a a a > subst-in1 || framework_failure_
|
---|
26 | printf "%s\n" x x x x x x > subst-exp1 || framework_failure_
|
---|
27 | cat << \EOF >> subst-prog1 || framework_failure_
|
---|
28 | 1s/A/x/i
|
---|
29 | 2s/A/x/I
|
---|
30 |
|
---|
31 | # s// followed by '}'
|
---|
32 | 3{s/./x/}
|
---|
33 | # s// followed by '#'
|
---|
34 | 4s/./x/#
|
---|
35 | # s// followed by ';'
|
---|
36 | 5s/./x/;
|
---|
37 | # s// followed by '\n
|
---|
38 | 6s/./x/
|
---|
39 | EOF
|
---|
40 |
|
---|
41 | sed -f subst-prog1 subst-in1 > subst-out1 || fail=1
|
---|
42 | compare_ subst-exp1 subst-out1 || fail=1
|
---|
43 |
|
---|
44 |
|
---|
45 | #
|
---|
46 | # Number modifiers to s//
|
---|
47 | #
|
---|
48 |
|
---|
49 | cat << \EOF >subst-in2 || framework_failure_
|
---|
50 | bbbbbbbbbb
|
---|
51 | bbbbbbbbbb
|
---|
52 | bbbbbbbbbb
|
---|
53 | bbbbbbbbbb
|
---|
54 | bbbbbbbbbb
|
---|
55 | bbbbbbbbbb
|
---|
56 | bbbbbbbbbb
|
---|
57 | bbbbbbbbbb
|
---|
58 | bbbbbbbbbb
|
---|
59 | bbbbbbbbbb
|
---|
60 | EOF
|
---|
61 |
|
---|
62 | cat << \EOF >subst-prog2 || framework_failure_
|
---|
63 | 1s/./x/g
|
---|
64 | 2s/./x/1
|
---|
65 | 3s/./x/2
|
---|
66 | 4s/./x/3
|
---|
67 | 5s/./x/4
|
---|
68 | 6s/./x/5
|
---|
69 | 7s/./x/6
|
---|
70 | 8s/./x/7
|
---|
71 | 9s/./x/8
|
---|
72 | 10s/./x/9
|
---|
73 | EOF
|
---|
74 |
|
---|
75 | cat << \EOF >subst-exp2
|
---|
76 | xxxxxxxxxx
|
---|
77 | xbbbbbbbbb
|
---|
78 | bxbbbbbbbb
|
---|
79 | bbxbbbbbbb
|
---|
80 | bbbxbbbbbb
|
---|
81 | bbbbxbbbbb
|
---|
82 | bbbbbxbbbb
|
---|
83 | bbbbbbxbbb
|
---|
84 | bbbbbbbxbb
|
---|
85 | bbbbbbbbxb
|
---|
86 | EOF
|
---|
87 |
|
---|
88 | sed -f subst-prog2 subst-in2 > subst-out2 || fail=1
|
---|
89 | compare_ subst-exp2 subst-out2 || fail=1
|
---|
90 |
|
---|
91 | #
|
---|
92 | # Multiline modifier: s///m
|
---|
93 | # ('N' will read and concatenate the second line
|
---|
94 | # into the patten space, making it "foo\nbar".
|
---|
95 | # s// will then operate on it as one string).
|
---|
96 | printf "foo\nbar\n" > subst-in3 || fail=1
|
---|
97 | printf "Xoo\nXar\n" > subst-exp3 || fail=1
|
---|
98 |
|
---|
99 | sed 'N;s/^./X/gm' subst-in3 > subst-out3-1 || fail=1
|
---|
100 | compare_ subst-exp3 subst-out3-1 || fail=1
|
---|
101 | sed 'N;s/^./X/gM' subst-in3 > subst-out3-2 || fail=1
|
---|
102 | compare_ subst-exp3 subst-out3-2 || fail=1
|
---|
103 |
|
---|
104 | # sanity-check: without m, only the first line should match
|
---|
105 | printf "Xoo\nbar\n" > subst-exp3-3 || fail=1
|
---|
106 | sed 'N;s/^./X/g' subst-in3 > subst-out3-3 || fail=1
|
---|
107 | compare_ subst-exp3-3 subst-out3-3 || fail=1
|
---|
108 |
|
---|
109 |
|
---|
110 | #
|
---|
111 | # s// followed by \r\n
|
---|
112 | #
|
---|
113 |
|
---|
114 | printf "s/./X/\r\n" > subst-prog4 || framework_failure_
|
---|
115 | echo a > subst-in4 || framework_failure_
|
---|
116 | echo X > subst-exp4 || framework_failure_
|
---|
117 | sed -f subst-prog4 subst-in4 > subst-out4 || fail=1
|
---|
118 | compare_ subst-exp4 subst-out4 || fail=1
|
---|
119 |
|
---|
120 |
|
---|
121 |
|
---|
122 |
|
---|
123 | Exit $fail
|
---|