- Notifications
You must be signed in to change notification settings - Fork 135
/
Copy path09-configuration.t
303 lines (247 loc) · 8.33 KB
/
09-configuration.t
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
useTest;
plan98;
my ($r, $s);
my$p=0;
=beginpod
=begincode :allow<B>
=endcode
=endpod
$r=$=pod[$p++].contents[0];
isa-ok$r, Pod::Block::Code;
is$r.config<allow>, 'B';
=beginpod
=confighead2 :like<head1> :formatted<I>
=endpod
$r=$=pod[$p++].contents[0];
isa-ok$r, Pod::Config;
is$r.type, 'head2';
is$r.config<like>, 'head1';
is$r.config<formatted>, 'I';
=beginpod
=forpod :number(42) :zebras :!sheep :feist<1 2 3 4>
=endpod
$r=$=pod[$p++].contents[0];
is$r.config<number>, 42;
{ # https://github.com/Raku/old-issue-tracker/issues/4958
is-deeply$r.config<zebras>, True, 'bool config uses Bool type (True)';
is-deeply$r.config<sheep>, False, 'bool config uses Bool type (False)';
}
#?rakudo todo 'https://github.com/Raku/old-issue-tracker/issues/3778'
is-deeply$r.config<feist>, <1 2 3 4>;
=beginpod
=forDESCRIPTION :title<presentation template>
= :author<John Brown> :pubdate(2011)
=endpod
$r=$=pod[$p++].contents[0];
is$r.config<title>, 'presentation template';
is$r.config<author>, 'John Brown';
is$r.config<pubdate>, 2011;
=beginpod
=fortable :caption<Table of contents>
foo bar
=endpod
$r=$=pod[$p++].contents[0];
isa-ok$r, Pod::Block::Table;
is$r.config<caption>, 'Table of contents';
=beginpod
=begincode :allow<B>
These words have some B<importance>.
=endcode
=endpod
$r=$=pod[$p++].contents[0].contents[1];
isa-ok$r, Pod::FormattingCode;
# Value is... Specify with... Or with... Or with...
# =============== ======================= ================= ===========
# List :key[$e1,$e2,...] :key($e1,$e2,...)
# Hash :key{$k1=>$v1,$k2=>$v2}
# Boolean (true) :key :key(True)
# Boolean (false) :!key :key(False)
# String :key<str> :key('str') :key("str")
# Number :key(42) :key(2.3)
# Where '$e1,$e2,...' are list elements of type Str, Int, Num, or
# Bool. Lists may have mixed element types. Note that one-element
# lists are converted to the type of their element (Str, Int, Num, or
# Bool).
#
# For hashes, '$k1,$k2,...' are keys of type Str and '$v1,$2,...'
# are values of type Str, Int, Num, or Bool.
# Strings may use any of the single Q/q quote constructs, e.g.,
# :key(Q[str]), which is equivalent to the :key<str> format and
# results in an uninterpreted string literal.
# tests for fixes for bugs:
# colonpairs in POD config options always produce strings: https://github.com/Raku/old-issue-tracker/issues/3778
# config items should not include quotes for string values: https://github.com/Raku/old-issue-tracker/issues/4789
#
# Pod config parses colopairs but simply stringifies whatever it matched: https://github.com/Raku/old-issue-tracker/issues/5962
#
# List and hash configuration value formats are not yet implemented (NYI): https://github.com/Raku/old-issue-tracker/issues/6652
#====================================================
#=== strings
#====================================================
=begintable :k1<str> :k2('str') :k3("str") :k4["str"] :k5(Q[str])
foo
=endtable
$r=$=pod[$p++];
say"=== testing strings";
isa-ok$r.config<k1>, Str;
isa-ok$r.config<k2>, Str;
isa-ok$r.config<k3>, Str;
isa-ok$r.config<k4>, Str;
isa-ok$r.config<k5>, Str;
$s='str';
is$r.config<k1>, $s, Q|<str>|;
is$r.config<k2>, $s, Q|'str'|;
is$r.config<k3>, $s, Q|"str"|;
is$r.config<k4>, $s, Q|"str"|;
is$r.config<k4>, $s, Q|using a Q/q quote|;
#====================================================
#=== ints
#====================================================
# max val int (int32): +2_147_483_647 <= 10 digits
# max val int (int64): +9_223_372_036_854_775_807 <= 19 digits
# TODO make a dynamic test that changes config test with hardware int bit size
=begintable :k1<1> :k2(2) :k3[2] :k4[+2000000000] :k5[-2000000000] :k6[+99999999999999999] :k7[-99999999999999999]
foo
=endtable
$r=$=pod[$p++];
say"=== testing string and ints";
isa-ok$r.config<k1>, Str;
isa-ok$r.config<k2>, Int;
isa-ok$r.config<k3>, Int;
isa-ok$r.config<k4>, Int;
isa-ok$r.config<k5>, Int;
isa-ok$r.config<k6>, Int;
isa-ok$r.config<k7>, Int;
is$r.config<k1>, '1', Q|'1'|;
is$r.config<k2>, 2, Q|2|;
is$r.config<k3>, 2, Q|2|;
is$r.config<k4>, 2_000_000_000, Q|+2000000000|;
is$r.config<k5>, -2_000_000_000, Q|-2000000000|;
# bigints with 18 digits each:
is$r.config<k6>, +99999999999999999, Q|+99999999999999999|;
is$r.config<k7>, -99999999999999999, Q|-99999999999999999|;
#====================================================
#=== nums
#====================================================
=begintable :k1(2.3) :k2[-2.3] :k3[+1e4] :k4(3.1e+04) :k5[-3.1E-04]
foo
=endtable
$r=$=pod[$p++];
say"=== testing nums";
#?rakudo 2 todo '2.3 and -2.3 are Rats, not Nums'
isa-ok$r.config<k1>, Rat;
isa-ok$r.config<k2>, Rat;
isa-ok$r.config<k3>, Num;
isa-ok$r.config<k4>, Num;
isa-ok$r.config<k5>, Num;
is$r.config<k1>, 2.3, Q|2.3|;
is$r.config<k2>, -2.3, Q|-2.3|;
is$r.config<k3>, +1e4, Q|+1e4|;
is$r.config<k4>, 3.1e+04, Q|3.1e+04|;
is$r.config<k5>, -3.1E-04, Q|-3.1E-04|;
#====================================================
#=== bools
#====================================================
=begintable :k1 :!k2 :k3(True) :k4[True] :k5(False) :k6[False]
foo
=endtable
$r=$=pod[$p++];
say"=== testing booleans";
isa-ok$r.config<k1>, Bool;
isa-ok$r.config<k2>, Bool;
isa-ok$r.config<k3>, Bool;
isa-ok$r.config<k4>, Bool;
isa-ok$r.config<k5>, Bool;
isa-ok$r.config<k6>, Bool;
ok$r.config<k1>, Q|:key|;
nok$r.config<k2>, Q|:!key|;
ok$r.config<k3>, Q|:key(True)|;
ok$r.config<k4>, Q|:key[True]|;
nok$r.config<k5>, Q|:key(False)|;
nok$r.config<k6>, Q|:key[False]|;
#====================================================
#=== lists
#====================================================
say"=== testing lists";
=begintable :k1(1, 'b c', 2.3, True, False) :k2[1, 'b c', 2.3, True, False]
foo
=endtable
$r=$=pod[$p++];
isa-ok$r.config<k1>, List;
isa-ok$r.config<k2>, List;
is$r.config<k1>[0], 1, Q|1|;
is$r.config<k1>[1], "b c", Q|'b c'|;
is$r.config<k1>[2], 2.3, Q|2.3|;
ok$r.config<k1>[3], Q|True|;
nok$r.config<k1>[4], Q|False|;
is$r.config<k2>[0], 1, Q|1|;
is$r.config<k2>[1], "b c", Q|'b c'|;
is$r.config<k2>[2], 2.3, Q|2.3|;
ok$r.config<k2>[3], Q|True|;
nok$r.config<k2>[4], Q|False|;
#====================================================
#=== hashes
#====================================================
say"=== testing hashes";
=begintable :k1{a => 1, 2 => 'b', c => True, d => 2.3, e => False}
foo
=endtable
$r=$=pod[$p++];
isa-ok$r.config<k1>, Map;
is$r.config<k1><a>, 1, Q|1|;
is$r.config<k1><2>, 'b', Q|'b'|;
ok$r.config<k1><c>, Q|True|;
is$r.config<k1><d>, 2.3, Q|2.3|;
nok$r.config<k1><e>, Q|False|;
#====================================================
#=== troublesome hashes
#====================================================
say"=== testing troublesome hashes";
=begintable :k1{2 => 'b => ?', c => ",", d => 2.3}
foo
=endtable
$r=$=pod[$p++];
isa-ok$r.config<k1>, Map;
is$r.config<k1><2>, 'b => ?', Q|'b => ?'|;
is$r.config<k1><c>, ",", Q|","|;
is$r.config<k1><d>, 2.3, Q|2.3|;
=begintable :k1{2 , 'b => "', d => '"', 4 => "\""}
foo
=endtable
$r=$=pod[$p++];
isa-ok$r.config<k1>, Map;
is$r.config<k1><2>, 'b => "', Q|'b => "'|;
is$r.config<k1><d>, '"', Q|'"'|;
is$r.config<k1><4>, "\"", Q|"\""|;
#====================================================
#=== bigints
#====================================================
# 30 digits
=begintable :k6[+999999999999999999999999999999] :k7[-999999999999999999999999999999]
foo
=endtable
$r=$=pod[$p++];
say"=== testing string and ints";
# bigints with 30 digits each:
isa-ok$r.config<k6>, Int;
isa-ok$r.config<k7>, Int;
is$r.config<k6>, 999_999_999_999_999_999_999_999_999_999, Q|+9 ** 30|;
is$r.config<k7>, -999_999_999_999_999_999_999_999_999_999, Q|-9 ** 30|;
#=====================================
# GH issue #2793
=for info :034foo
:034foo
$r=$=pod[$p++];
isa-ok$r.config<foo>, Int, '034foo: foo => 34';
is$r.config<foo>, 34, 'foo => 34';
=for info :0foo
:0foo
$r=$=pod[$p++];
isa-ok$r.config<foo>, Int, '0foo: foo => 0';
is$r.config<foo>, 0, 'foo => 0';
=for info :1foo
:0foo
$r=$=pod[$p++];
isa-ok$r.config<foo>, Int, '1foo: foo => 1';
is$r.config<foo>, 1, 'foo => 1';
# vim: expandtab shiftwidth=4