Date:2012-06-03 14:51:20 (11 years 9 months ago)
Author:Werner Almesberger
Commit:12b21f032c5a07657b7d0cfc5dab34e2ad3253ea
Message:b2/test/: more substitution tests

Total number of tests is now 109.
Files: b2/test/sublast (1 diff)
b2/test/subunit (1 diff)

Change Details

b2/test/sublast
1#!/bin/bash
2. ./Common
3
4###############################################################################
5
6tst "substitutions: expand \$ from regular var" -q X=foo <<EOF
7!-s
8X=?*? { Y=\$\$ }
9EOF
10
11expect <<EOF
12Y=foo
13EOF
14
15#------------------------------------------------------------------------------
16
17tst "substitutions: expand \$ from FN" -q F1=bar <<EOF
18!-s
19FN=?*? { Y=\$\$ }
20EOF
21
22expect <<EOF
23Y=bar
24EOF
25
26#------------------------------------------------------------------------------
27
28tst_fail "substitutions: expand \$ without match" <<EOF
29!-s
30X=\$\$
31EOF
32
33expect <<EOF
34s:2: \$\$ without match
35EOF
36
37#------------------------------------------------------------------------------
38
39tst "substitutions: assign to \$ from regular var" -q X=bar <<EOF
40!-s
41X=?*? { \$=foo }
42EOF
43
44expect <<EOF
45X=foo
46EOF
47
48#------------------------------------------------------------------------------
49
50tst "substitutions: assign to \$ from FN" -q F1=foo <<EOF
51!-s
52FN=?*? { \$=bar }
53EOF
54
55expect <<EOF
56F1=bar
57EOF
58
59#------------------------------------------------------------------------------
60
61tst_fail "substitutions: assign to \$ without match" <<EOF
62!-s
63\$=bar
64EOF
65
66expect <<EOF
67s:2: \$ without match
68EOF
69
70#------------------------------------------------------------------------------
71
72tst "substitutions: match \$ from regular var" -q X=bar <<EOF
73!-s
74X=?*? { \$=b(*) { Y=\$1 } }
75EOF
76
77expect <<EOF
78Y=ar
79EOF
80
81#------------------------------------------------------------------------------
82
83tst "substitutions: match \$ from FN" -q F1=foo <<EOF
84!-s
85FN=?*? { \$=(*)o { Y=\$1 } }
86EOF
87
88expect <<EOF
89Y=fo
90EOF
91
92#------------------------------------------------------------------------------
93
94tst_fail "substitutions: match \$ without match" <<EOF
95!-s
96\$=* { X=X }
97EOF
98
99expect <<EOF
100s:2: \$ without match
101EOF
102
103###############################################################################
b2/test/subunit
1#!/bin/bash
2. ./Common
3
4###############################################################################
5
6tst "substitutions: expand \$1 from unit pattern (100R)" -ds -q X=100R <<EOF
7!-s
8X=(#R) { Y=\$1 }
9EOF
10
11expect <<EOF
12X=RE {
13    Y=\$1
14}
15Y=100R
16EOF
17
18#------------------------------------------------------------------------------
19
20tst "substitutions: expand \$\$ from unit pattern (100R)" -q X=100R <<EOF
21!-s
22X=(#R) { Y=\$\$ }
23EOF
24
25# this seems to do the right thing but is still wrong
26expect <<EOF
27Y=100R
28EOF
29
30#------------------------------------------------------------------------------
31
32tst "substitutions: expand \$1 from unit pattern (1k2)" -q X=1k2 <<EOF
33!-s
34X=(#R) { Y=\$1 }
35EOF
36
37expect <<EOF
38Y=1.2kR
39EOF
40
41#------------------------------------------------------------------------------
42
43tst "substitutions: expand \$\$ from unit pattern (1k2)" -q X=1k2 <<EOF
44!-s
45X=(#R) { Y=\$\$ }
46EOF
47
48# this isn't what we normally want
49expect <<EOF
50Y=1k2
51EOF
52
53#------------------------------------------------------------------------------
54
55tst "substitutions: expand src var from unit pattern (1R2)" -q X=1R2 <<EOF
56!-s
57X=(#R) { Y=\$X }
58EOF
59
60# this isn't what we normally want
61expect <<EOF
62Y=1R2
63EOF
64
65#------------------------------------------------------------------------------
66
67tst "substitutions: convert 100 with unit pattern" -q X=100 <<EOF
68!-s
69X=(#R) { Y=\$1 }
70EOF
71
72expect <<EOF
73Y=100R
74EOF
75
76#------------------------------------------------------------------------------
77
78tst "substitutions: convert 56k with unit pattern" -q X=56k <<EOF
79!-s
80X=(#R) { Y=\$1 }
81EOF
82
83expect <<EOF
84Y=56kR
85EOF
86
87#------------------------------------------------------------------------------
88
89tst "substitutions: convert 4u7 with unit pattern" -q X=4u7 <<EOF
90!-s
91X=(#F) { Y=\$1 }
92EOF
93
94expect <<EOF
95Y=4.7uF
96EOF
97
98#------------------------------------------------------------------------------
99
100tst "substitutions: convert 3V3 with unit pattern" -q X=3V3 <<EOF
101!-s
102X=(#V) { Y=\$1 }
103EOF
104
105expect <<EOF
106Y=3.3V
107EOF
108
109#------------------------------------------------------------------------------
110
111tst "substitutions: convert 0.8A with unit pattern" -q X=0.8A <<EOF
112!-s
113X=(#A) { Y=\$1 }
114EOF
115
116expect <<EOF
117Y=0.8A
118EOF
119
120#------------------------------------------------------------------------------
121
122tst "substitutions: convert 100mV with unit pattern" -q X=100mV <<EOF
123!-s
124X=(#V) { Y=\$1 }
125EOF
126
127expect <<EOF
128Y=100mV
129EOF
130
131#------------------------------------------------------------------------------
132
133tst "substitutions: convert -1.5A with unit pattern" -q X=-1.5A <<EOF
134!-s
135X=(#A) { Y=\$1 }
136EOF
137
138expect <<EOF
139Y=-1.5A
140EOF
141
142#------------------------------------------------------------------------------
143
144tst "substitutions: try to match 1k8R with unit pattern" -q X=1k8R <<EOF
145!-s
146X=(#R) { Y=X }
147EOF
148
149expect <<EOF
150EOF
151
152#------------------------------------------------------------------------------
153
154tst "substitutions: try to match 2R2k with unit pattern" -q X=2R2k <<EOF
155!-s
156X=(#R) { Y=X }
157EOF
158
159expect <<EOF
160EOF
161
162#------------------------------------------------------------------------------
163
164tst "substitutions: try to match 1.2.3 with unit pattern" -q X=1.2.3 <<EOF
165!-s
166X=(#R) { Y=X }
167EOF
168
169expect <<EOF
170EOF
171
172#------------------------------------------------------------------------------
173
174tst "substitutions: unit pattern (#%)" -q X=10% <<EOF
175!-s
176X=(#%) { Y=\$1 }
177EOF
178
179expect <<EOF
180Y=10%
181EOF
182
183#------------------------------------------------------------------------------
184
185tst "substitutions: unit pattern (##)" -q X=1M2 <<EOF
186!-s
187X=(##) { Y=\$1 }
188EOF
189
190expect <<EOF
191Y=1.2M
192EOF
193
194#------------------------------------------------------------------------------
195
196tst_fail "substitutions: unit pattern (#ppm)" -q X=20ppm <<EOF
197!-s
198X=(#ppm) { Y=\$1 }
199EOF
200
201expect <<EOF
202s:2: invalid (#unit) syntax
203EOF
204
205###############################################################################

Archive Download the corresponding diff file

Branches:
master



interactive