Root/b2/test/subre

1#!/bin/bash
2. ./Common
3
4###############################################################################
5
6tst "substitutions: match fixed string, return other string (match)" \
7    -ds -q FOO=x <<EOF
8!-s
9FOO=x { BAR=y }
10EOF
11
12expect <<EOF
13FOO=RE {
14    BAR=y
15}
16BAR=y
17EOF
18
19#------------------------------------------------------------------------------
20
21tst "substitutions: match fixed string, return other string (no match)" \
22    -q FOO=y <<EOF
23!-s
24FOO=x { BAR=y }
25EOF
26
27expect <<EOF
28EOF
29
30#------------------------------------------------------------------------------
31
32tst "substitutions: match fixed string, return input" -ds -q FOO=x <<EOF
33!-s
34FOO=x { BAR=\$\$ }
35EOF
36
37expect <<EOF
38FOO=RE {
39    BAR=\$\$
40}
41BAR=x
42EOF
43
44#------------------------------------------------------------------------------
45
46tst "substitutions: match *, return input" -q FOO=xyz <<EOF
47!-s
48FOO=* { BAR=\$\$ }
49EOF
50
51expect <<EOF
52BAR=xyz
53EOF
54
55#------------------------------------------------------------------------------
56
57tst "substitutions: match ??? with xyz" -q FOO=xyz <<EOF
58!-s
59FOO=??? { BAR=x }
60EOF
61
62expect <<EOF
63BAR=x
64EOF
65
66#------------------------------------------------------------------------------
67
68tst "substitutions: don't match ??? with axyz" -q FOO=axyz <<EOF
69!-s
70FOO=??? { BAR=x }
71EOF
72
73expect <<EOF
74EOF
75
76#------------------------------------------------------------------------------
77
78tst "substitutions: don't match ??? with xyza" -q FOO=xyza <<EOF
79!-s
80FOO=??? { BAR=x }
81EOF
82
83expect <<EOF
84EOF
85
86#------------------------------------------------------------------------------
87
88tst "substitutions: match ?.? with x.z" -q FOO=x.z <<EOF
89!-s
90FOO=?.? { BAR=x }
91EOF
92
93expect <<EOF
94BAR=x
95EOF
96
97#------------------------------------------------------------------------------
98
99tst "substitutions: don't match ?.? with xyz" -q FOO=xyz <<EOF
100!-s
101FOO=?.? { BAR=x }
102EOF
103
104expect <<EOF
105EOF
106
107#------------------------------------------------------------------------------
108
109tst "substitutions: match ?(?)?, return \$1" -q FOO=xyz <<EOF
110!-s
111FOO=?(?)? { BAR=\$1 }
112EOF
113
114expect <<EOF
115BAR=y
116EOF
117
118#------------------------------------------------------------------------------
119
120tst "substitutions: match ?(*)?, return \$1" -q FOO=xyzzy <<EOF
121!-s
122FOO=?(*)? { BAR=\$1 }
123EOF
124
125expect <<EOF
126BAR=yzz
127EOF
128
129#------------------------------------------------------------------------------
130
131tst_fail "substitutions: $0 does not exist" -q FOO=xyzzy <<EOF
132!-s
133FOO=?(*)? { BAR=\$0 }
134EOF
135
136expect <<EOF
137s:1: invalid variable name
138EOF
139
140#------------------------------------------------------------------------------
141
142tst_fail "substitutions: $2 with only one () pair" -q FOO=xyzzy <<EOF
143!-s
144FOO=?(*)? { BAR=\$2 }
145EOF
146
147expect <<EOF
148s:2: \$2 but only 1 parenthesis
149EOF
150
151#------------------------------------------------------------------------------
152
153tst "substitutions: $2 with two () pairs" -q FOO=xyzzy <<EOF
154!-s
155FOO=?(?)(*)? { BAR=\$2 }
156EOF
157
158expect <<EOF
159BAR=zz
160EOF
161
162#------------------------------------------------------------------------------
163
164tst_fail "substitutions: $3 with only two () pairs" -q FOO=xyzzy <<EOF
165!-s
166FOO=?(?)(*)? { BAR=\$3 }
167EOF
168
169expect <<EOF
170s:2: \$3 but only 2 parentheses
171EOF
172
173#------------------------------------------------------------------------------
174
175tst "substitutions: [ab], match a" -q FOO=abc <<EOF
176!-s
177FOO=([ab])* { BAR=\$1 }
178EOF
179
180expect <<EOF
181BAR=a
182EOF
183
184#------------------------------------------------------------------------------
185
186tst "substitutions: [ab], match b" -q FOO=abc <<EOF
187!-s
188FOO=*([ab])* { BAR=\$1 }
189EOF
190
191expect <<EOF
192BAR=b
193EOF
194
195#------------------------------------------------------------------------------
196
197tst_fail "substitutions: [ab is invalid" <<EOF
198!-s
199FOO=[ab { BAR=x }
200EOF
201
202expect <<EOF
203s:2: Unmatched [ or [^
204EOF
205
206#------------------------------------------------------------------------------
207
208tst "substitutions: (a|b), match a" -q FOO=xa <<EOF
209!-s
210FOO=*(a|b) { BAR=\$1 }
211EOF
212
213expect <<EOF
214BAR=a
215EOF
216
217#------------------------------------------------------------------------------
218
219tst "substitutions: (a|b), match b" -q FOO=xb <<EOF
220!-s
221FOO=*(a|b) { BAR=\$1 }
222EOF
223
224expect <<EOF
225BAR=b
226EOF
227
228#------------------------------------------------------------------------------
229
230tst "substitutions: (|x), match the empty part" -q FOO=y <<EOF
231!-s
232FOO=(|x)y { BAR=\$1 }
233EOF
234
235expect <<EOF
236BAR=
237EOF
238
239###############################################################################
240

Archive Download this file

Branches:
master



interactive