reg 0.4.8 → 0.5.0a0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -0
- data/COPYING +0 -0
- data/History.txt +14 -0
- data/Makefile +59 -0
- data/README +87 -40
- data/article.txt +838 -0
- data/{assert.rb → lib/assert.rb} +3 -3
- data/{reg.rb → lib/reg.rb} +11 -4
- data/lib/reg/version.rb +21 -0
- data/lib/regarray.rb +455 -0
- data/{regarrayold.rb → lib/regarrayold.rb} +33 -7
- data/lib/regbackref.rb +73 -0
- data/lib/regbind.rb +230 -0
- data/{regcase.rb → lib/regcase.rb} +15 -5
- data/lib/regcompiler.rb +2341 -0
- data/{regcore.rb → lib/regcore.rb} +196 -85
- data/{regdeferred.rb → lib/regdeferred.rb} +35 -4
- data/{regposition.rb → lib/regevent.rb} +36 -38
- data/lib/reggraphpoint.rb +28 -0
- data/lib/reghash.rb +631 -0
- data/lib/reginstrumentation.rb +36 -0
- data/{regitem_that.rb → lib/regitem_that.rb} +32 -11
- data/{regknows.rb → lib/regknows.rb} +4 -2
- data/{reglogic.rb → lib/reglogic.rb} +76 -59
- data/{reglookab.rb → lib/reglookab.rb} +31 -21
- data/lib/regmatchset.rb +323 -0
- data/{regold.rb → lib/regold.rb} +27 -27
- data/{regpath.rb → lib/regpath.rb} +91 -1
- data/lib/regposition.rb +79 -0
- data/lib/regprogress.rb +1522 -0
- data/lib/regrepeat.rb +307 -0
- data/lib/regreplace.rb +254 -0
- data/lib/regslicing.rb +581 -0
- data/lib/regsubseq.rb +72 -0
- data/lib/regsugar.rb +361 -0
- data/lib/regvar.rb +180 -0
- data/lib/regxform.rb +212 -0
- data/{trace.rb → lib/trace_during.rb} +6 -4
- data/lib/warning.rb +37 -0
- data/parser.txt +26 -8
- data/philosophy.txt +18 -0
- data/reg.gemspec +58 -25
- data/regguide.txt +18 -0
- data/test/andtest.rb +46 -0
- data/test/regcompiler_test.rb +346 -0
- data/test/regdemo.rb +20 -0
- data/{item_thattest.rb → test/regitem_thattest.rb} +2 -2
- data/test/regtest.rb +2125 -0
- data/test/test_all.rb +32 -0
- data/test/test_reg.rb +19 -0
- metadata +108 -73
- data/calc.reg +0 -73
- data/forward_to.rb +0 -49
- data/numberset.rb +0 -200
- data/regarray.rb +0 -675
- data/regbackref.rb +0 -126
- data/regbind.rb +0 -74
- data/reggrid.csv +1 -2
- data/reghash.rb +0 -318
- data/regprogress.rb +0 -1054
- data/regreplace.rb +0 -114
- data/regsugar.rb +0 -230
- data/regtest.rb +0 -1078
- data/regvar.rb +0 -76
data/test/andtest.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
=begin copyright
|
2
|
+
reg - the ruby extended grammar
|
3
|
+
Copyright (C) 2016 Caleb Clausen
|
4
|
+
|
5
|
+
This library is free software; you can redistribute it and/or
|
6
|
+
modify it under the terms of the GNU Lesser General Public
|
7
|
+
License as published by the Free Software Foundation; either
|
8
|
+
version 2.1 of the License, or (at your option) any later version.
|
9
|
+
|
10
|
+
This library is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
Lesser General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU Lesser General Public
|
16
|
+
License along with this library; if not, write to the Free Software
|
17
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18
|
+
=end
|
19
|
+
$Debug=1
|
20
|
+
require 'reg'
|
21
|
+
r1=+[Reg::And.new(-[])]
|
22
|
+
r2=+[-[]&1]
|
23
|
+
|
24
|
+
|
25
|
+
GC.start
|
26
|
+
origcounts={}
|
27
|
+
origcounts.default=0
|
28
|
+
ObjectSpace.each_object{|obj| origcounts[obj.class]+=1 }
|
29
|
+
|
30
|
+
10000.times {|n|
|
31
|
+
STDERR.print "." if n.&(0x7F).zero?; STDERR.flush
|
32
|
+
r1===[] or fail "empty data fail at iteration #{n}"
|
33
|
+
r2===[] and fail "empty data fail at iteration #{n}"
|
34
|
+
r2===[1] or fail "fail at iteration #{n}" }
|
35
|
+
|
36
|
+
p Thread.list
|
37
|
+
|
38
|
+
r1=r2=nil
|
39
|
+
GC.start
|
40
|
+
p Thread.list
|
41
|
+
|
42
|
+
counts={}
|
43
|
+
counts.default=0
|
44
|
+
ObjectSpace.each_object{|obj| counts[obj.class]+=1 }
|
45
|
+
require 'pp'
|
46
|
+
pp counts.map{|(cl,num)| [cl,num-origcounts[cl]]}.sort_by{|pair| pair.last}
|
@@ -0,0 +1,346 @@
|
|
1
|
+
=begin copyright
|
2
|
+
reg - the ruby extended grammar
|
3
|
+
Copyright (C) 2016 Caleb Clausen
|
4
|
+
|
5
|
+
This library is free software; you can redistribute it and/or
|
6
|
+
modify it under the terms of the GNU Lesser General Public
|
7
|
+
License as published by the Free Software Foundation; either
|
8
|
+
version 2.1 of the License, or (at your option) any later version.
|
9
|
+
|
10
|
+
This library is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
Lesser General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU Lesser General Public
|
16
|
+
License along with this library; if not, write to the Free Software
|
17
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18
|
+
=end
|
19
|
+
+[1,2,3]
|
20
|
+
|
21
|
+
def ===(other)
|
22
|
+
cu=other.to_sequence
|
23
|
+
cu.scan 1 and cu.scan 2 and cu.scan 3 and cu.eof?
|
24
|
+
end
|
25
|
+
|
26
|
+
generic ===:
|
27
|
+
def ===(other)
|
28
|
+
pr=Progress.new self,other.to_sequence
|
29
|
+
cu=pr.cursor
|
30
|
+
catch :RegMatchSucceed {catch :RegMatchFail {
|
31
|
+
@seq.cmatch pr { cu.eof? ? throw(:RegMatchSucceed, true) : throw(:RegMatchFail) }
|
32
|
+
}}
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
Seq=-[1,1.5]|-:foo
|
37
|
+
|
38
|
+
def cmatch(progress)
|
39
|
+
cu=progress.cursor
|
40
|
+
progress.bt_stop
|
41
|
+
catch(:RegMatchFail) {(cu.scan 1 and cu.scan 1.5 ) and yield}
|
42
|
+
progress.bt_backup
|
43
|
+
progress.bt_stop
|
44
|
+
catch(:RegMatchFail) {(cu.scan -:foo) and yield}
|
45
|
+
progress.bt_backup
|
46
|
+
throw :RegMatchFail
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
+[Seq,2,3]
|
51
|
+
|
52
|
+
def ===(other)
|
53
|
+
pr=Progress.new other.to_sequence
|
54
|
+
cu=pr.cursor
|
55
|
+
catch :RegMatchSucceed {catch :RegMatchFail {
|
56
|
+
Seq.cmatch pr { (cu.scan 2 and cu.scan 3 and cu.eof?) ? throw(:RegMatchSucceed, true) : throw :RegMatchFail }
|
57
|
+
}}
|
58
|
+
end
|
59
|
+
--or--
|
60
|
+
def ===(other)
|
61
|
+
pr=Progress.new other.to_sequence
|
62
|
+
cu=progress.cursor
|
63
|
+
catch :RegMatchSucceed {catch :RegMatchFail {
|
64
|
+
rest=proc {(cu.scan 2 and cu.scan 3 and cu.eof?) ? throw(:RegMatchSucceed, true) : throw :RegMatchFail }
|
65
|
+
progress.bt_stop
|
66
|
+
catch(:RegMatchFail) {(cu.scan 1 and cu.scan 1.5 ) and rest[] }
|
67
|
+
progress.bt_backup
|
68
|
+
progress.bt_stop #optimize away
|
69
|
+
catch(:RegMatchFail) {(cu.scan -:foo) and rest[] }
|
70
|
+
progress.bt_backup #optimize away
|
71
|
+
throw :RegMatchFail #optimize -> false
|
72
|
+
}}
|
73
|
+
end
|
74
|
+
|
75
|
+
-[0,1,Seq]
|
76
|
+
def cmatch(progress)
|
77
|
+
cu=progress.cursor
|
78
|
+
cu.scan 0 and cu.scan 1 and Seq.cmatch progress{yield}
|
79
|
+
throw :RegMatchFail
|
80
|
+
end
|
81
|
+
|
82
|
+
-[0,1,Seq,Seq2]
|
83
|
+
def cmatch(progress)
|
84
|
+
cu=progress.cursor
|
85
|
+
cu.scan 0 and cu.scan 1 and Seq.cmatch progress{Seq2.cmatch progress {yield}}
|
86
|
+
throw :RegMatchFail
|
87
|
+
end
|
88
|
+
|
89
|
+
-[0,1,Seq,Seq2,2,3]
|
90
|
+
def cmatch(progress)
|
91
|
+
cu=progress.cursor
|
92
|
+
cu.scan 0 and cu.scan 1 and
|
93
|
+
Seq.cmatch progress{Seq2.cmatch progress {
|
94
|
+
cu.scan 2 and cu.scan 3 and yield
|
95
|
+
throw :RegMatchFail
|
96
|
+
}}
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
Numeric-1
|
101
|
+
def cmatch(progress)
|
102
|
+
cu=progress.cursor
|
103
|
+
progress.bt_stop
|
104
|
+
catch(:RegMatchFail) {cu.scan Numeric and yield}
|
105
|
+
progress.bt_backup
|
106
|
+
yield
|
107
|
+
end
|
108
|
+
|
109
|
+
Seq2=Symbol*(1..2)
|
110
|
+
def cmatch(progress)
|
111
|
+
cu=progress.cursor
|
112
|
+
cu.scan Symbol or throw :RegMatchFail
|
113
|
+
progress.bt_stop
|
114
|
+
catch(:RegMatchFail) {cu.scan Symbol and yield}
|
115
|
+
progress.bt_backup
|
116
|
+
yield
|
117
|
+
end
|
118
|
+
|
119
|
+
Seq2*4
|
120
|
+
def cmatch(progress)
|
121
|
+
Seq2.cmatch progress { Seq2.cmatch progress { Seq2.cmatch progress { Seq2.cmatch progress {yield}}}}
|
122
|
+
end
|
123
|
+
|
124
|
+
Seq2-2
|
125
|
+
def cmatch(progress)
|
126
|
+
cu=progress.cursor
|
127
|
+
progress.bt_stop
|
128
|
+
catch(:RegMatchFail){Seq2.cmatch progress {
|
129
|
+
progress.bt_stop;
|
130
|
+
catch(:RegMatchFail){Seq2.cmatch progress {yield}};
|
131
|
+
progress.bt_backup
|
132
|
+
}}
|
133
|
+
progress.bt_backup
|
134
|
+
yield
|
135
|
+
end
|
136
|
+
|
137
|
+
Seq2-4
|
138
|
+
def cmatch(progress)
|
139
|
+
cu=progress.cursor
|
140
|
+
progress.bt_stop
|
141
|
+
catch(:RegMatchFail){Seq2.cmatch progress {
|
142
|
+
progress.bt_stop
|
143
|
+
catch(:RegMatchFail){Seq2.cmatch progress {
|
144
|
+
progress.bt_stop
|
145
|
+
catch(:RegMatchFail){Seq2.cmatch progress {
|
146
|
+
progress.bt_stop
|
147
|
+
catch(:RegMatchFail){Seq2.cmatch progress {
|
148
|
+
yield
|
149
|
+
}}
|
150
|
+
progress.bt_backup
|
151
|
+
yield
|
152
|
+
}}
|
153
|
+
progress.bt_backup
|
154
|
+
yield
|
155
|
+
}}
|
156
|
+
progress.bt_backup
|
157
|
+
yield
|
158
|
+
}}
|
159
|
+
progress.bt_backup
|
160
|
+
yield
|
161
|
+
end
|
162
|
+
|
163
|
+
Seq2-1
|
164
|
+
def cmatch(progress)
|
165
|
+
progress.bt_stop
|
166
|
+
catch(:RegMatchFail){Seq2.cmatch progress, {yield}}
|
167
|
+
progress.bt_backup
|
168
|
+
yield
|
169
|
+
end
|
170
|
+
|
171
|
+
Seq2+0
|
172
|
+
def cmatch(progress)
|
173
|
+
progress.bt_stop
|
174
|
+
catch(:RegMatchFail){Seq2.cmatch progress {cmatch progress {yield}}}
|
175
|
+
progress.bt_backup
|
176
|
+
yield
|
177
|
+
end
|
178
|
+
|
179
|
+
Seq2+4
|
180
|
+
def cmatch(progress)
|
181
|
+
rest2=proc{
|
182
|
+
progress.bt_stop
|
183
|
+
catch(:RegMatchFail){Seq2.cmatch progress, &rest2}
|
184
|
+
progress.bt_backup
|
185
|
+
yield
|
186
|
+
}
|
187
|
+
Seq2.cmatch progress { Seq2.cmatch progress { Seq2.cmatch progress { Seq2.cmatch progress, &rest2}}}
|
188
|
+
end
|
189
|
+
--or--
|
190
|
+
def cmatch(progress)
|
191
|
+
rest2=proc{
|
192
|
+
progress.bt_stop
|
193
|
+
catch(:RegMatchFail){Seq2.cmatch progress{
|
194
|
+
progress.bt_stop
|
195
|
+
catch(:RegMatchFail){Seq2.cmatch progress{
|
196
|
+
rest2[]
|
197
|
+
}}
|
198
|
+
progress.bt_backup
|
199
|
+
yield
|
200
|
+
}}
|
201
|
+
progress.bt_backup
|
202
|
+
yield
|
203
|
+
}
|
204
|
+
Seq2.cmatch progress { Seq2.cmatch progress { Seq2.cmatch progress { Seq2.cmatch progress, &rest2}}}
|
205
|
+
end
|
206
|
+
|
207
|
+
:a<<Seq
|
208
|
+
def cmatch(progress)
|
209
|
+
cu=progress.cursor
|
210
|
+
origpos=cu.pos
|
211
|
+
Seq.cmatch progress {
|
212
|
+
catch :RegMatchFail {
|
213
|
+
progress.register_var(:a,cu[origpos...cu.pos])
|
214
|
+
yield
|
215
|
+
}
|
216
|
+
progress.unregister_var(:a)
|
217
|
+
throw :RegMatchFail
|
218
|
+
}
|
219
|
+
end
|
220
|
+
|
221
|
+
BR(:a)
|
222
|
+
def cmatch(progress)
|
223
|
+
cu=progress.cursor
|
224
|
+
cu.readahead( (br_a=progress.var_lookup(:a)).size )==br_a and cu.pos+=br_a.size and yield
|
225
|
+
throw :RegMatchFail
|
226
|
+
end
|
227
|
+
|
228
|
+
-[:a<<Seq,BR(:a)]
|
229
|
+
def cmatch(progress)
|
230
|
+
cu=progress.cursor
|
231
|
+
origpos=cu.pos
|
232
|
+
Seq.cmatch progress {
|
233
|
+
catch :RegMatchFail {
|
234
|
+
progress.register_var(:a,cu[origpos...cu.pos])
|
235
|
+
cu.readahead( (br_a=progress.var_lookup(:a)).size )==br_a and cu.pos+=br_a.size and yield
|
236
|
+
}
|
237
|
+
progress.unregister_var(:a)
|
238
|
+
throw :RegMatchFail
|
239
|
+
}
|
240
|
+
end
|
241
|
+
|
242
|
+
|
243
|
+
Seq&Seq2&Seq3
|
244
|
+
def cmatch(progress)
|
245
|
+
cu=progress.cursor
|
246
|
+
origpos=cu.pos
|
247
|
+
ands=AndMachine.new(progress,Seq,Seq2,Seq3)
|
248
|
+
loop{
|
249
|
+
progress.bt_stop
|
250
|
+
ands.try_match {
|
251
|
+
catch :RegMatchFail {
|
252
|
+
yield
|
253
|
+
}
|
254
|
+
progress.bt_backup
|
255
|
+
}
|
256
|
+
}
|
257
|
+
end
|
258
|
+
|
259
|
+
Seq^Seq2^Seq3
|
260
|
+
def cmatch(progress)
|
261
|
+
cu=progress.cursor
|
262
|
+
origpos=cu.pos
|
263
|
+
catch :RegXorFail {
|
264
|
+
(0...@regs.size).each{|i|
|
265
|
+
catch :RegMatchFail{
|
266
|
+
@regs[i].cmatch progress {
|
267
|
+
(i+1...@regs.size).each{|j|
|
268
|
+
catch :RegMatchFail{
|
269
|
+
@regs[j].cmatch progress {
|
270
|
+
throw :RegXorFail #fail whole xor matcher
|
271
|
+
}
|
272
|
+
}
|
273
|
+
}
|
274
|
+
yield
|
275
|
+
}
|
276
|
+
}
|
277
|
+
throw :RegMatchFail
|
278
|
+
}
|
279
|
+
}
|
280
|
+
throw :RegMatchFail
|
281
|
+
end
|
282
|
+
--or--
|
283
|
+
Seq^Seq2^Seq3
|
284
|
+
def xortail(h,progress)
|
285
|
+
(h...@regs.size).each{|j|
|
286
|
+
catch :RegMatchFail{
|
287
|
+
@regs[j].cmatch progress {
|
288
|
+
throw :RegXorFail #fail whole xor matcher
|
289
|
+
}
|
290
|
+
}
|
291
|
+
}
|
292
|
+
end
|
293
|
+
|
294
|
+
def cmatch(progress)
|
295
|
+
|
296
|
+
catch :RegXorFail {
|
297
|
+
catch :RegMatchFail{Seq.cmatch progress {xortail(1,progress);yield}}
|
298
|
+
catch :RegMatchFail{Seq2.cmatch progress {xortail(2,progress);yield}}
|
299
|
+
catch :RegMatchFail{Seq3.cmatch progress {yield}}
|
300
|
+
}
|
301
|
+
throw :RegMatchFail
|
302
|
+
end
|
303
|
+
|
304
|
+
|
305
|
+
Seq>>33
|
306
|
+
def cmatch(progress)
|
307
|
+
cu=progress.cursor
|
308
|
+
origpos=cu.pos
|
309
|
+
Seq.cmatch progress {
|
310
|
+
progress.register_replace(origpos...cu.pos,33)
|
311
|
+
yield
|
312
|
+
}
|
313
|
+
end
|
314
|
+
|
315
|
+
+{/foo/>>33 => 77..88, OB=>OB}
|
316
|
+
def bmatch(progress)
|
317
|
+
cu=progress.cursor
|
318
|
+
hash=cu.read1
|
319
|
+
hash.each{|k,v|
|
320
|
+
if /foo/===k and (77..88)===v
|
321
|
+
progress.register_replace GraphPoint::HashKey.new(hash,k,33)
|
322
|
+
elsif OB===k and OB===v
|
323
|
+
else return
|
324
|
+
end
|
325
|
+
}
|
326
|
+
return true
|
327
|
+
end
|
328
|
+
|
329
|
+
+{Rep => 77..88, OB=>OB}
|
330
|
+
def bmatch(progress)
|
331
|
+
cu=progress.cursor
|
332
|
+
hash=cu.read1
|
333
|
+
hash.each{|k,v|
|
334
|
+
if Rep===k and (77..88)===v
|
335
|
+
Rep.replacing(progress,GraphPoint::HashKey,hash,k)
|
336
|
+
elsif OB===k and OB===v
|
337
|
+
else return
|
338
|
+
end
|
339
|
+
}
|
340
|
+
return true
|
341
|
+
end
|
342
|
+
class Transform
|
343
|
+
def replacing(progress,gp_class,cntr,idx)
|
344
|
+
progress.register_replace gp_class.new(cntr,idx,@rep)
|
345
|
+
end
|
346
|
+
end
|
data/test/regdemo.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
=begin copyright
|
2
|
+
reg - the ruby extended grammar
|
3
|
+
Copyright (C) 2016 Caleb Clausen
|
4
|
+
|
5
|
+
This library is free software; you can redistribute it and/or
|
6
|
+
modify it under the terms of the GNU Lesser General Public
|
7
|
+
License as published by the Free Software Foundation; either
|
8
|
+
version 2.1 of the License, or (at your option) any later version.
|
9
|
+
|
10
|
+
This library is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
Lesser General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU Lesser General Public
|
16
|
+
License along with this library; if not, write to the Free Software
|
17
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18
|
+
=end
|
19
|
+
+[1,2,3]===[1,2,3]
|
20
|
+
+[1,2,3,+[1,2,3]]===[1,2,3,[1,2,3]]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
=begin copyright
|
2
2
|
reg - the ruby extended grammar
|
3
|
-
Copyright (C) 2005 Caleb Clausen
|
3
|
+
Copyright (C) 2005, 2016 Caleb Clausen
|
4
4
|
|
5
5
|
This library is free software; you can redistribute it and/or
|
6
6
|
modify it under the terms of the GNU Lesser General Public
|
@@ -26,7 +26,7 @@ require 'test/unit'
|
|
26
26
|
res=["#<",self.class,": ",instance_variables.sort.collect{|v|
|
27
27
|
[v,"=",instance_variable_get(v).inspect," "].join
|
28
28
|
}]
|
29
|
-
res.last.chop!
|
29
|
+
#res.last.last.chop!
|
30
30
|
res.push('>')
|
31
31
|
res.join
|
32
32
|
end
|
data/test/regtest.rb
ADDED
@@ -0,0 +1,2125 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
=begin copyright
|
3
|
+
reg - the ruby extended grammar
|
4
|
+
Copyright (C) 2005, 2016 Caleb Clausen
|
5
|
+
|
6
|
+
This library is free software; you can redistribute it and/or
|
7
|
+
modify it under the terms of the GNU Lesser General Public
|
8
|
+
License as published by the Free Software Foundation; either
|
9
|
+
version 2.1 of the License, or (at your option) any later version.
|
10
|
+
|
11
|
+
This library 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 GNU
|
14
|
+
Lesser General Public License for more details.
|
15
|
+
|
16
|
+
You should have received a copy of the GNU Lesser General Public
|
17
|
+
License along with this library; if not, write to the Free Software
|
18
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
=end
|
20
|
+
$VERBOSE=true
|
21
|
+
$Debug=true #turn on assertions
|
22
|
+
|
23
|
+
require "reg"
|
24
|
+
require 'getoptlong'
|
25
|
+
|
26
|
+
|
27
|
+
warn "hrm, it seems like many of these tests are not running, for whatever reason"
|
28
|
+
|
29
|
+
unless ENV['NO_TEST_UNIT']
|
30
|
+
require 'test/unit' #gets in the way of my debug output
|
31
|
+
class TC_Reg < Test::Unit::TestCase; end
|
32
|
+
end
|
33
|
+
|
34
|
+
class TC_Reg
|
35
|
+
# class <<self
|
36
|
+
|
37
|
+
|
38
|
+
def randsym
|
39
|
+
as=Symbol.all_symbols
|
40
|
+
as[rand(as.size)]
|
41
|
+
end
|
42
|
+
|
43
|
+
def makelendata(num=20,mask=0b11111111111,mischief=false)
|
44
|
+
result=[]
|
45
|
+
(1..num).each do
|
46
|
+
begin type=rand(11) end until 0 != mask&(1<<type)
|
47
|
+
len=type==0 ? 0 : rand(4)
|
48
|
+
|
49
|
+
result<<case type
|
50
|
+
when 0 then [0]
|
51
|
+
when 1 then [len]+(1..len).map{randsym}
|
52
|
+
when 2 then (1..len).map{randsym}+[-len]
|
53
|
+
when 3 then (1..len).map{randsym}+["infix#{len}"]+(1..len).map{randsym}
|
54
|
+
when 4
|
55
|
+
[:Q] +
|
56
|
+
(1..len).map{randsym}.delete_if {|x|:Q==x} +
|
57
|
+
(1..rand(4)).map{randsym}.delete_if {|x|:Q==x} +
|
58
|
+
[:Q]
|
59
|
+
when 5
|
60
|
+
[:Q] +
|
61
|
+
(1..len).map{randsym}.delete_if {|x|:Q==x} +
|
62
|
+
[:'\\', :Q] +
|
63
|
+
(1..rand(4)).map{randsym}.delete_if {|x|:Q==x} +
|
64
|
+
[:Q]
|
65
|
+
|
66
|
+
when 6
|
67
|
+
[:q]+(1..len).map{randsym}.delete_if {|x|:q==x}+[:q]
|
68
|
+
|
69
|
+
when 7
|
70
|
+
[:begin]+
|
71
|
+
(1..len).map{randsym}.delete_if {|x| :begin==x or :end==x} +
|
72
|
+
(1..rand(4)).map{randsym}.delete_if {|x| :begin==x or :end==x} +
|
73
|
+
[:end]
|
74
|
+
|
75
|
+
when 8
|
76
|
+
[:begin]+
|
77
|
+
(1..len).map{randsym}.delete_if {|x| :begin==x or :end==x} +
|
78
|
+
[:'\\', 0==rand(1) ? :begin : :end] +
|
79
|
+
(1..rand(4)).map{randsym}.delete_if {|x| :begin==x or :end==x} +
|
80
|
+
[:end]
|
81
|
+
|
82
|
+
when 9
|
83
|
+
[:begin]+
|
84
|
+
(1..len).map{randsym}.delete_if {|x| :begin==x or :end==x} +
|
85
|
+
[:begin]+(1..len).map{randsym}.delete_if {|x| :begin==x or :end==x} +[:end]+
|
86
|
+
(1..rand(4)).map{randsym}.delete_if {|x| :begin==x or :end==x} +
|
87
|
+
[:end]
|
88
|
+
|
89
|
+
when 10
|
90
|
+
[:begin]+
|
91
|
+
(1..len).map{randsym}.delete_if {|x| :begin==x or :end==x} +
|
92
|
+
[:'\\', 0==rand(1)? :begin : :end] +
|
93
|
+
(1..rand(4)).map{randsym}.delete_if {|x| :begin==x or :end==x} +
|
94
|
+
[:begin]+(1..len).map{randsym}.delete_if {|x| :begin==x or :end==x} +[:end]+
|
95
|
+
(1..rand(4)).map{randsym}.delete_if {|x| :begin==x or :end==x} +
|
96
|
+
[:end]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
mischief and result.insert(rand(result.size),mischief)
|
100
|
+
return result
|
101
|
+
end
|
102
|
+
|
103
|
+
def rand_ambig
|
104
|
+
nestlevel=rand(5)+1
|
105
|
+
corepat=rand(1)==0 ? 'OB' : 'Numeric.reg'
|
106
|
+
pat=corepat
|
107
|
+
product=1
|
108
|
+
nestlevel.times {
|
109
|
+
op=case rand(3)
|
110
|
+
when 0; :*
|
111
|
+
when 1; :+
|
112
|
+
when 2; :-
|
113
|
+
end
|
114
|
+
num=rand(6)+1
|
115
|
+
product*=num
|
116
|
+
pat=["(",pat,")",op,num].to_s
|
117
|
+
product>50 and break
|
118
|
+
}
|
119
|
+
|
120
|
+
pat=eval "+[#{pat}]"
|
121
|
+
$verbose and print "testing #{pat.inspect} with #{product} items\n"
|
122
|
+
assert_eee pat,(1..product).to_a
|
123
|
+
end
|
124
|
+
|
125
|
+
def disabled_test_rand_reg #causes 0*inf too often
|
126
|
+
20.times { rand_ambig }
|
127
|
+
end
|
128
|
+
|
129
|
+
def begin_end_pattern op, val
|
130
|
+
innerbe=Reg::const
|
131
|
+
innerbe.set! -[:begin, (
|
132
|
+
~/^(begin|end|\\)$/.sym |
|
133
|
+
-[:'\\',OB] |
|
134
|
+
innerbe
|
135
|
+
).send(op,val), :end]
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_replacement_construction
|
140
|
+
assert_nothing_raised{ Class>>[ (~:op).foo ] }
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_replacement_of_subseq_can_be_constructed
|
144
|
+
assert_nothing_raised{-[Float.-]>>:accept}
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_object_matcher
|
148
|
+
#object matcher tests
|
149
|
+
ob=AnyStruct[:aa=>1,:b=>"foob",:c=>[1,2,3]]
|
150
|
+
assert_eee Rob(:aa=>1), ob
|
151
|
+
assert_eee Rob(:@aa=>1), ob
|
152
|
+
assert_eee Rob(:aa=>1,:b=>/foo/), ob
|
153
|
+
assert_eee Rob(:@aa=>1,:@b=>/foo/), ob
|
154
|
+
|
155
|
+
assert_ene Rob(:aa=>Float), ob
|
156
|
+
assert_ene Rob(:@aa=>Float), ob
|
157
|
+
assert_ene Rob(:aa=>1,:b=>/fu/), ob
|
158
|
+
assert_ene Rob(:@aa=>1,:@b=>/fu/), ob
|
159
|
+
|
160
|
+
assert_eee Rob(), ob
|
161
|
+
assert_ene Rob(:d=>item_that.size>33), ob
|
162
|
+
|
163
|
+
|
164
|
+
assert_eee Rob(/aa$/=>1), ob
|
165
|
+
#assert_eee Rob(/@aa/=>1), ob
|
166
|
+
assert_eee Rob(/aa$/=>1,:b=>/foo/), ob
|
167
|
+
#assert_eee Rob(/@aa/=>1,:@b=>/foo/), ob
|
168
|
+
|
169
|
+
assert_ene Rob(/aab$/=>1), ob
|
170
|
+
assert_ene Rob(/aab$/=>1,:b=>/foo/), ob
|
171
|
+
|
172
|
+
assert_ene Rob(/aa$/=>Float), ob
|
173
|
+
#assert_ene Rob(/@aa/=>Float), ob
|
174
|
+
assert_ene Rob(/aa$/=>1,:b=>/fu/), ob
|
175
|
+
#assert_ene Rob(/@aa/=>1,:@b=>/fu/), ob
|
176
|
+
|
177
|
+
assert_ene Rob(/ddd/=>item_that.size>33), ob
|
178
|
+
|
179
|
+
assert_eee Rob(/aa$/=>1,:b=>/foo/,:@c=>OB), ob
|
180
|
+
#assert_eee Rob(/@aa/=>1,:@b=>/foo/,OB=>item_that.size<33), ob
|
181
|
+
#assert_eee Rob(/@aa/=>1,:@b=>/foo/,:@c=>Array,OB=>nil), ob
|
182
|
+
|
183
|
+
assert_ene Rob(/a$/=>1,:bb=>/foo/,:@c=>OB), ob
|
184
|
+
#assert_ene Rob(/@a/=>1,:@b=>/foo/,OB=>item_that.size>33), ob
|
185
|
+
#assert_ene Rob(/@a/=>1,:@b=>/foo/,:@c=>Array,OB=>Symbol), ob
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_hash_matcher
|
189
|
+
h={}
|
190
|
+
h.default=:b
|
191
|
+
check_hash_matcher Rah(:a=>:b), :matches=>[{:a=>:b},h],
|
192
|
+
:unmatches=>[ {:a=>:c}, {} ] #=> false
|
193
|
+
|
194
|
+
check_hash_matcher Rah(/^(a|b)$/=>33),
|
195
|
+
:matches=>[{"a"=>33}, {"b"=>33}, {"a"=>33,"b"=>33} ],
|
196
|
+
:unmatches=>[
|
197
|
+
{"a"=>33,"c"=>33},
|
198
|
+
{"b"=>33,"c"=>33}, {"a"=>33,"c"=>133}, {"b"=>33,"c"=>133}, {"a"=>133}, {"b"=>133} ,
|
199
|
+
{"c"=>33}, {"c"=>133} , {"a"=>33,"b"=>133}, {"a"=>133,"b"=>33}, {"a"=>133,"b"=>133}
|
200
|
+
]
|
201
|
+
|
202
|
+
=begin disabled.... Reg::Hash#|(Hash) not special anymore
|
203
|
+
assert_eee Rah("a"=>33)|{"b"=>33}, {"a"=>33,"b"=>33} #=> true
|
204
|
+
assert_eee Rah("a"=>33)|{"b"=>33}, {"a"=>33,"b"=>133} #=> true
|
205
|
+
assert_ene Rah("a"=>33)|{"b"=>33}, {"a"=>133,"b"=>33} #=> false
|
206
|
+
assert_ene Rah("a"=>33)|{"b"=>33}, {"a"=>133,"b"=>133} #=> false
|
207
|
+
|
208
|
+
assert_eee Rah("a"=>33)|{"b"=>33}, {"b"=>33} #=> true
|
209
|
+
=end
|
210
|
+
check_hash_matcher Rah(:a.reg|:b => 44), :matches=>[{:a => 44},{:b => 44}],
|
211
|
+
:unmatches=> [{:a => 144}, {:b => 144}]
|
212
|
+
|
213
|
+
|
214
|
+
check_hash_matcher( +{OB=>6}, :unmatches=>{} )
|
215
|
+
|
216
|
+
check_hash_matcher( +{/fo+/=>8, /ba+r/=>9}, :matches=> {"foo"=>8,"bar"=>9})
|
217
|
+
|
218
|
+
check_hash_matcher(
|
219
|
+
hm=+{:foo=>:bar, 1=>/flux/, (2..10)=>"zork",
|
220
|
+
("r".."s")=>item_that.reverse, (11..20)=>NilClass|"fizzle",
|
221
|
+
Array=>Enumerable|nil, OB=>Integer
|
222
|
+
},
|
223
|
+
:matches=>[{:foo=>:bar, 1=>"flux", 2=>"zork", "r"=>"a string",
|
224
|
+
11=>"fizzle", []=>(9..99), :rest=>3**99},
|
225
|
+
{:foo=>:bar, 1=>"flux", 2=>"zork", "r"=>"a string",
|
226
|
+
:rest=>3**99},
|
227
|
+
{:foo=>:bar, 1=>"flux cap", 3=>"zork", "rat"=>"long string", String=>4**99}
|
228
|
+
],
|
229
|
+
:unmatches=>[
|
230
|
+
{:foo=>:bar, 1=>"flux", 2=>"zork", "r"=>"a string",
|
231
|
+
11=>"fizzle", []=>(9..99), :rest=>3**99, :fibble=>:foomp},
|
232
|
+
{:foo=>:baz, 1=>"flux", 2=>"zork", "r"=>"a string",
|
233
|
+
11=>"fizzle", []=>(9..99), :rest=>3**99},
|
234
|
+
{:foo=>:bar, 2=>"zork", "r"=>"a string",
|
235
|
+
11=>"fizzle", []=>(9..99), :rest=>3**99}
|
236
|
+
]
|
237
|
+
)
|
238
|
+
|
239
|
+
|
240
|
+
check_hash_matcher(
|
241
|
+
hm=+{:foo=>:bar, 1=>/flux/, item_that<10=>"zork",
|
242
|
+
/^[rs]/=>item_that.reverse, item_that>10=>NilClass|"fizzle",
|
243
|
+
Array=>Enumerable|nil, OB=>Integer
|
244
|
+
},
|
245
|
+
:matches=>[{:foo=>:bar, 1=>"flux", 2=>"zork", "r"=>"a string",
|
246
|
+
11=>"fizzle", []=>(9..99), :rest=>3**99},
|
247
|
+
{:foo=>:bar, 1=>"flux cap", 3=>"zork", "rat"=>"long string", String=>4**99}
|
248
|
+
],
|
249
|
+
:unmatches=>[{:foo=>:bar, 1=>"flux", 2=>"zork", "r"=>"a string",
|
250
|
+
11=>"fizzle", []=>(9..99), :rest=>3**99, :fibble=>:foomp},
|
251
|
+
{:foo=>:baz, 1=>"flux", 2=>"zork", "r"=>"a string",
|
252
|
+
11=>"fizzle", []=>(9..99), :rest=>3**99},
|
253
|
+
{:foo=>:bar, 2=>"zork", "r"=>"a string",
|
254
|
+
11=>"fizzle", []=>(9..99), :rest=>3**99}
|
255
|
+
]
|
256
|
+
)
|
257
|
+
|
258
|
+
check_hash_matcher(
|
259
|
+
+{1=>Set[1,2,3]},
|
260
|
+
:matches=>[{1=>1}, {1=>2}],
|
261
|
+
:unmatches=>[{1=>4}, {1=>Set[1,2,3]}]
|
262
|
+
)
|
263
|
+
|
264
|
+
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_recursive_itemrange
|
268
|
+
be=begin_end_pattern :+, 0
|
269
|
+
|
270
|
+
be1=begin_end_pattern :+, 1
|
271
|
+
#minlen == 1 + min(1,2,minlen)*1 + 1
|
272
|
+
|
273
|
+
be2=begin_end_pattern :*, 2
|
274
|
+
|
275
|
+
be10=begin_end_pattern :*,2..5
|
276
|
+
#maxlen == 1 + max(1,2,maxlen)*5 + 1
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
assert_equal 0..0, (+[]).subitemrange
|
281
|
+
assert_equal 0..0, ::Reg::var.set!(+[]).subitemrange
|
282
|
+
assert_equal 1..1, (+[1]).subitemrange
|
283
|
+
assert_equal 1..1, ::Reg::var.set!(+[1]).subitemrange
|
284
|
+
assert_equal 2..2, (+[1,1]).subitemrange
|
285
|
+
assert_equal 2..2, ::Reg::var.set!(+[1,1]).subitemrange
|
286
|
+
|
287
|
+
assert_range_could_be_conservative_approx( 2..Infinity, be.itemrange ) #illegal instruction
|
288
|
+
assert_range_could_be_conservative_approx( 2..Infinity, be.subitemrange )
|
289
|
+
|
290
|
+
assert_range_could_be_conservative_approx( 3..Infinity, be1.itemrange )
|
291
|
+
assert_range_could_be_conservative_approx( 3..Infinity, be1.subitemrange )
|
292
|
+
|
293
|
+
assert_range_could_be_conservative_approx( 4..Infinity, be2.itemrange )
|
294
|
+
assert_range_could_be_conservative_approx( 4..Infinity, be2.subitemrange )
|
295
|
+
|
296
|
+
assert_range_could_be_conservative_approx( 4..Infinity, be10.itemrange )
|
297
|
+
assert_range_could_be_conservative_approx( 4..Infinity, be10.subitemrange )
|
298
|
+
end
|
299
|
+
|
300
|
+
def assert_range_could_be_conservative_approx expected, actual
|
301
|
+
if expected==actual
|
302
|
+
assert true
|
303
|
+
else
|
304
|
+
assert (0..Infinity)==actual
|
305
|
+
warning "conservative approximation accepted for recursive matcher's itemrange"
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
def test_recursive_inspect
|
310
|
+
|
311
|
+
var=Reg::var
|
312
|
+
|
313
|
+
#Reg::Var#inspect should not be using Recursive (tho its ok for Reg::Const...)
|
314
|
+
#and the tests here should not require it to!
|
315
|
+
var.set!( +[var] )
|
316
|
+
assert_eee( /^\Recursive\(var(\d+)=\{\}, \+\[var\1\]\)$/, var.inspect )
|
317
|
+
var.set!( -[var.-] )
|
318
|
+
assert_eee( /^\Recursive\(var(\d+)=\{\}, \-\[\(?var\1\)?(\.-|-1)\]\)$/, var.inspect )
|
319
|
+
|
320
|
+
# huh "actual patterns to match tbd"
|
321
|
+
var.set!( +{var=>1} )
|
322
|
+
assert_eee /^Recursive\(var(\d+)=\{\}, \+\{-\[\(var\1\)-1\]=>1\}\)$/, var.inspect
|
323
|
+
var.set! +{1=>var}
|
324
|
+
assert_eee /^Recursive\(var(\d+)=\{\}, \+\{1=>var\1\}\)$/, var.inspect
|
325
|
+
var.set! -{:foo=>var,1=>2}
|
326
|
+
assert_equal var.inspect, ''
|
327
|
+
var.set! -{:foo=>var}
|
328
|
+
assert_equal var.inspect, ''
|
329
|
+
|
330
|
+
var.set! +{var=>1|nil}
|
331
|
+
assert_equal var.inspect, ''
|
332
|
+
var.set! -{:foo=>var|nil}
|
333
|
+
assert_equal var.inspect, ''
|
334
|
+
|
335
|
+
var.set! +{var=>1.reg.-}
|
336
|
+
assert_equal var.inspect, ''
|
337
|
+
|
338
|
+
var.set! -{:foo=>var.-}
|
339
|
+
assert_equal var.inspect, ''
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
var=Reg::const
|
345
|
+
var.set! +[var]
|
346
|
+
assert_eee /^\Recursive\(var(\d+)=\{\}, \+\[var\1\]\)$/, var.inspect
|
347
|
+
assert_raises(RuntimeError) {var.set! 0}
|
348
|
+
|
349
|
+
var=Reg::const
|
350
|
+
var.set! -[var.-]
|
351
|
+
assert_eee /^\Recursive\(var(\d+)=\{\}, \-\[\(?var\1\)?(\.-|-1)\]\)$/, var.inspect
|
352
|
+
assert_raises(RuntimeError) {var.set! 0}
|
353
|
+
|
354
|
+
# huh "actual patterns to match tbd"
|
355
|
+
|
356
|
+
var=Reg::const
|
357
|
+
var.set! +{var=>1}
|
358
|
+
assert_eee /^Recursive\(var(\d+)=\{\}, \+\{-\[\(var\1\)-1\]=>1\}\)$/, var.inspect
|
359
|
+
assert_raises(RuntimeError) {var.set! 0}
|
360
|
+
|
361
|
+
var=Reg::const
|
362
|
+
var.set! +{1=>var}
|
363
|
+
assert_eee /^Recursive\(var(\d+)=\{\}, \+\{1=>var\1\}\)$/, var.inspect
|
364
|
+
assert_raises(RuntimeError) {var.set! 0}
|
365
|
+
|
366
|
+
var=Reg::const
|
367
|
+
var.set! -{:foo=>var,1=>2}
|
368
|
+
assert_equal var.inspect, ''
|
369
|
+
assert_raises(RuntimeError) {var.set! 0}
|
370
|
+
|
371
|
+
var=Reg::const
|
372
|
+
var.set! -{:foo=>var}
|
373
|
+
assert_equal var.inspect, ''
|
374
|
+
assert_raises(RuntimeError) {var.set! 0}
|
375
|
+
|
376
|
+
|
377
|
+
var=Reg::const
|
378
|
+
var.set! +{var=>1|nil}
|
379
|
+
assert_equal var.inspect, ''
|
380
|
+
assert_raises(RuntimeError) {var.set! 0}
|
381
|
+
|
382
|
+
|
383
|
+
var=Reg::const
|
384
|
+
var.set! -{:foo=>var|nil}
|
385
|
+
assert_equal var.inspect, ''
|
386
|
+
assert_raises(RuntimeError) {var.set! 0}
|
387
|
+
|
388
|
+
|
389
|
+
var=Reg::const
|
390
|
+
var.set! +{var=>1.reg.-}
|
391
|
+
assert_equal var.inspect, ''
|
392
|
+
assert_raises(RuntimeError) {var.set! 0}
|
393
|
+
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
var=Reg::const
|
398
|
+
var.set! -{:foo=>var.-}
|
399
|
+
assert_equal var.inspect, ''
|
400
|
+
assert_raises(RuntimeError) {var.set! 0}
|
401
|
+
end
|
402
|
+
|
403
|
+
def test_ordered_hash_matcher
|
404
|
+
m=[ Object**1, Enumerable**2, ::Array**3,
|
405
|
+
+[OB-20]**4, +[OB-19]**5, +[OB-18]**6, +[OB-17]**7,
|
406
|
+
+[Integer, Integer]**8, +[item_that<4, Integer]**9, +[item_that<4, item_that**2>9]**10
|
407
|
+
].reverse.+@
|
408
|
+
assert_eee m, {[2,4]=>10, [2,1]=>9, [5,0]=>8, [nil]*17=>7, [nil]*18=>6, [nil]*19=>5,
|
409
|
+
[nil]*20=>4, [nil]*100=>3, {}=>2, nil=>1
|
410
|
+
}
|
411
|
+
|
412
|
+
|
413
|
+
end
|
414
|
+
|
415
|
+
def test_backtracking_to_inner_array
|
416
|
+
m=+[ BR[:b] ]
|
417
|
+
|
418
|
+
assert_ene m, []
|
419
|
+
assert_ene m, [1]
|
420
|
+
|
421
|
+
m=+[ -[]%:b,BR[:b] ]
|
422
|
+
|
423
|
+
assert_eee m, []
|
424
|
+
assert_ene m, [1]
|
425
|
+
|
426
|
+
|
427
|
+
m=+[ -[/k/.-%:a, OBS], BR[:a] ]
|
428
|
+
|
429
|
+
assert_eee m, ['k',99, 'k']
|
430
|
+
assert_eee m, ['k',99]
|
431
|
+
assert_eee m, [99]
|
432
|
+
|
433
|
+
m=+[ +[/k/.-%:a, OBS], BR[:a] ]
|
434
|
+
|
435
|
+
assert_eee m, [['k',99], 'k']
|
436
|
+
assert_eee m, [['k',99]]
|
437
|
+
assert_eee m, [[99]]
|
438
|
+
|
439
|
+
m=+[ +[(/k/%:a).-, OBS], Range ]
|
440
|
+
|
441
|
+
assert_ene m, [['k',99], 'k']
|
442
|
+
assert_ene m, [['k',99]]
|
443
|
+
assert_ene m, [[99]]
|
444
|
+
|
445
|
+
m=+[ +[(/k/%:a).-, OBS], BR[:a] ]
|
446
|
+
|
447
|
+
assert_eee m, [['k',99], 'k']
|
448
|
+
assert_ene m, [['k',99]]
|
449
|
+
assert_ene m, [[99]]
|
450
|
+
|
451
|
+
|
452
|
+
m=+[ +[/k/.-%:a, Integer.*], BR[:a] ]
|
453
|
+
|
454
|
+
assert_eee m, [['k',99], 'k']
|
455
|
+
assert_ene m, [['k',99]]
|
456
|
+
assert_eee m, [[99]]
|
457
|
+
|
458
|
+
|
459
|
+
#backreference to something in a nested array
|
460
|
+
assert_eee( +[1,2,3,+[OB*(1..2)%:a,OB*(1..2)],BR(:a)], [1,2,3,[4,5,6],4,5] )
|
461
|
+
|
462
|
+
#backtracking should work in nested Reg::Array
|
463
|
+
assert_eee( +[1,2,3,+[OB*(1..2)%:a,OB*(1..2)],BR(:a)], [1,2,3,[4,5,6],4] )
|
464
|
+
end
|
465
|
+
|
466
|
+
|
467
|
+
def test_backtracking_in_heterogeneous_data_stuctures
|
468
|
+
#backreference to something in a nested array in a nested hash
|
469
|
+
assert_eee( +{:foo=>+[OB*(1..2)%:a,OB*(1..2)]}, {:foo=>[4,5,6]} )
|
470
|
+
assert_eee( +[1,2,3,+{:foo=>+[OB*(1..2)%:a,OB*(1..2)]},BR(:a)], [1,2,3,{:foo=>[4,5,6]},4,5] )
|
471
|
+
|
472
|
+
#backtracking should work in nested Reg::Array in Reg::Hash or the like
|
473
|
+
assert_eee( +[1,2,3,+{:foo=>+[OB*(1..2)%:a,OB*(1..2)]},BR(:a)], [1,2,3,{:foo=>[4,5,6]},4] )
|
474
|
+
|
475
|
+
|
476
|
+
#...also do eg backtracking in reg::object... what else?
|
477
|
+
end
|
478
|
+
|
479
|
+
|
480
|
+
def test_finally
|
481
|
+
puts=nil
|
482
|
+
assert_eee( +[ OB.finally{|p| puts= :foop}],[99] )
|
483
|
+
assert_equal :foop, puts
|
484
|
+
puts=nil
|
485
|
+
assert_eee( +[ -[(OB%:a).finally{|p| puts= :foop}],],[99] )
|
486
|
+
assert_equal :foop, puts
|
487
|
+
puts=nil
|
488
|
+
assert_eee( +[ -[(OB%:a).finally{|p| puts= p[:a]}],],[99] )
|
489
|
+
assert_equal 99, puts
|
490
|
+
puts=nil
|
491
|
+
assert_eee( +[ -[(OB%:a).-.finally{|p| puts= p[:a]}],],[99] )
|
492
|
+
assert_equal 99, puts
|
493
|
+
puts=nil
|
494
|
+
assert_eee( +[ -[(OB%:a).-.finally{|p| puts= p[:a]}, OBS],],[99] )
|
495
|
+
assert_equal 99, puts
|
496
|
+
puts=nil
|
497
|
+
assert_eee( +[ -[(OB%:a).-.finally{|p| puts= p[:a]}, OBS],],[99,100] )
|
498
|
+
assert_equal 99, puts
|
499
|
+
puts=nil
|
500
|
+
assert_eee( +[ -[(OB%:a).-.finally{|p| puts= p[:a]}, OBS],],[99,100,101] )
|
501
|
+
assert_equal 99, puts
|
502
|
+
puts=nil
|
503
|
+
assert_ene( +[ -[(OB%:a).-.finally{|p| puts= p[:a]}, 5],],[999,6] )
|
504
|
+
assert_equal nil, puts
|
505
|
+
end
|
506
|
+
|
507
|
+
def test_later
|
508
|
+
puts=puts2=nil
|
509
|
+
assert_eee( +[ -[(OB%:a).-.later{|p| puts= p[:a]}, OBS],],[99] )
|
510
|
+
assert_equal 99, puts
|
511
|
+
assert_eee( +[ (OB%:a).later{|p| puts= p[:a]}, OBS ], [9] )
|
512
|
+
assert_equal 9, puts
|
513
|
+
assert_eee( +[ OB.later{|p| puts= 8}, OBS ], [88] )
|
514
|
+
assert_equal 8, puts
|
515
|
+
assert_ene( +[ -[(OB%:a).-.later{|p| puts2= 1}, 5],],[999,6] )
|
516
|
+
assert_equal nil, puts2
|
517
|
+
assert_ene( +[ -[OB.later{|p| puts2= 1}, 5],],[999,6] )
|
518
|
+
assert_equal nil, puts2
|
519
|
+
end
|
520
|
+
|
521
|
+
def test_side_effect
|
522
|
+
puts=puts2=nil
|
523
|
+
assert_eee( +[ -[(OB%:a).-.side_effect{|p| puts= p[:a]}, OBS],],[99] )
|
524
|
+
assert_equal 99, puts
|
525
|
+
assert_eee( +[ (OB%:a).side_effect{|p| puts= p[:a]}, OBS ], [9] )
|
526
|
+
assert_equal 9, puts
|
527
|
+
assert_eee( +[ OB.side_effect{|p| puts= 8}, OBS ], [88] )
|
528
|
+
assert_equal 8, puts
|
529
|
+
assert_ene( +[ -[(OB%:a).-.side_effect{|p| puts2= p[:a]}, 5],],[999,6] )
|
530
|
+
assert_equal 999, puts2
|
531
|
+
end
|
532
|
+
|
533
|
+
def test_undo
|
534
|
+
puts=puts2=nil
|
535
|
+
|
536
|
+
assert_eee( +[ -[(OB%:a).-.side_effect{|p| puts2= p[:a]}.undo{puts2=nil}, 5],],[999,6] )
|
537
|
+
assert_equal nil, puts2
|
538
|
+
|
539
|
+
assert_eee( +[ OB.side_effect{|p| puts2= 1}.undo{puts2=nil}, 66,],[99,66] )
|
540
|
+
assert_equal nil, puts2
|
541
|
+
|
542
|
+
assert_eee( +[ OB.side_effect{|p| puts2= 1}.undo{puts2=false}, 66,],[99,66] )
|
543
|
+
assert_equal false, puts2
|
544
|
+
end
|
545
|
+
|
546
|
+
|
547
|
+
def test_backtracking_in_ordered_hash
|
548
|
+
assert_eee( +[:foo.reg**+[OB.-%:a,OB.-], :bar.reg**+[BR[:a]]], {:foo=>[1], :bar=>[1]} )
|
549
|
+
assert_eee( +[:foo.reg**+[OB.-%:a,OB.-], :bar.reg**+[BR[:a]]], {:foo=>[1], :bar=>[]} )
|
550
|
+
|
551
|
+
assert_eee( +[:foo.reg**+[OB.-,OB.-%:a], :bar.reg**+[BR[:a]]], {:foo=>[1], :bar=>[1]} )
|
552
|
+
assert_eee( +[:foo.reg**+[OB.-,OB.-%:a], :bar.reg**+[BR[:a]]], {:foo=>[1], :bar=>[]} )
|
553
|
+
|
554
|
+
assert_eee( +[:foo.reg**+[OB*(1..2)%:a,OB*(1..2)], :bar.reg**+[BR[:a]]], {:foo=>[1,1,1], :bar=>[1]} )
|
555
|
+
assert_eee( +[:foo.reg**+[OB*(1..2)%:a,OB*(1..2)], :bar.reg**+[BR[:a]]], {:foo=>[1,1,1], :bar=>[1,1]} )
|
556
|
+
end
|
557
|
+
|
558
|
+
|
559
|
+
def test_backtracking_from_value_to_key_in_hash
|
560
|
+
assert_ene( +{+[OB.-%:a,OB.-]=>+[BR[:a]]}, {[1,2,3]=>[1]} )
|
561
|
+
assert_eee( +{+[OB.-%:a,OB.-]=>+[BR[:a]]}, {[1,2]=>[1]} )
|
562
|
+
assert_eee( +{+[OB.-%:a,OB.-]=>+[BR[:a]]}, {[1]=>[1]} )
|
563
|
+
assert_eee( +{+[OB.-%:a,OB.-]=>+[BR[:a]]}, {[1]=>[]} )
|
564
|
+
|
565
|
+
assert_ene( +{+[OB.-,OB.-%:a]=>+[BR[:a]]}, {[3,2,1]=>[1]} )
|
566
|
+
assert_eee( +{+[OB.-,OB.-%:a]=>+[BR[:a]]}, {[2,1]=>[1]} )
|
567
|
+
assert_eee( +{+[OB.-,OB.-%:a]=>+[BR[:a]]}, {[1]=>[1]} )
|
568
|
+
assert_eee( +{+[OB.-,OB.-%:a]=>+[BR[:a]]}, {[1]=>[]} )
|
569
|
+
|
570
|
+
assert_eee( +{+[OB*(1..2)%:a,OB*(1..2)]=>+[BR[:a]]}, {[1,1,1]=>[1]} )
|
571
|
+
assert_eee( +{+[OB*(1..2)%:a,OB*(1..2)]=>+[BR[:a]]}, {[1,1,1]=>[1,1]} )
|
572
|
+
assert_eee( +{+[OB*(1..2),OB*(1..2)%:a]=>+[BR[:a]]}, {[1,1,1]=>[1]} )
|
573
|
+
assert_eee( +{+[OB*(1..2),OB*(1..2)%:a]=>+[BR[:a]]}, {[1,1,1]=>[1,1]} )
|
574
|
+
|
575
|
+
assert_ene( +[+[OB.-%:a,OB.-]**+[BR[:a]]], {[1,2,3]=>[1]} )
|
576
|
+
assert_eee( +[+[OB.-%:a,OB.-]**+[BR[:a]]], {[1,2]=>[1]} )
|
577
|
+
assert_eee( +[+[OB.-%:a,OB.-]**+[BR[:a]]], {[1]=>[1]} )
|
578
|
+
assert_eee( +[+[OB.-%:a,OB.-]**+[BR[:a]]], {[1]=>[]} )
|
579
|
+
|
580
|
+
assert_ene( +[+[OB.-,OB.-%:a]**+[BR[:a]]], {[3,2,1]=>[1]} )
|
581
|
+
assert_eee( +[+[OB.-,OB.-%:a]**+[BR[:a]]], {[2,1]=>[1]} )
|
582
|
+
assert_eee( +[+[OB.-,OB.-%:a]**+[BR[:a]]], {[1]=>[1]} )
|
583
|
+
assert_eee( +[+[OB.-,OB.-%:a]**+[BR[:a]]], {[1]=>[]} )
|
584
|
+
|
585
|
+
assert_eee( +[+[OB*(1..2)%:a,OB*(1..2)]**+[BR[:a]]], {[1,1,1]=>[1]} )
|
586
|
+
assert_eee( +[+[OB*(1..2)%:a,OB*(1..2)]**+[BR[:a]]], {[1,1,1]=>[1,1]} )
|
587
|
+
assert_eee( +[+[OB*(1..2),OB*(1..2)%:a]**+[BR[:a]]], {[1,1,1]=>[1]} )
|
588
|
+
assert_eee( +[+[OB*(1..2),OB*(1..2)%:a]**+[BR[:a]]], {[1,1,1]=>[1,1]} )
|
589
|
+
end
|
590
|
+
|
591
|
+
|
592
|
+
def test_object_matcher2
|
593
|
+
om=-{:f=>1, /^[gh]+$/=>3..4, :@v=>/=[a-z]+$/}
|
594
|
+
|
595
|
+
eval %{ #use eval to avoid error adding with class inside def
|
596
|
+
class Example
|
597
|
+
attr_reader *%w{f g h v}
|
598
|
+
def initialize(f,g,h,v)
|
599
|
+
@f,@g,@h,@v=f,g,h,v
|
600
|
+
end
|
601
|
+
end
|
602
|
+
}
|
603
|
+
|
604
|
+
assert_eee om, Example.new(1,3,4,"foo=bar")
|
605
|
+
assert_eee om, Example.new(1,4,3,"foo=bar")
|
606
|
+
|
607
|
+
assert_ene om, Example.new(2,3,4,"foo=bar")
|
608
|
+
assert_ene om, Example.new(1,33,4,"foo=bar")
|
609
|
+
assert_ene om, Example.new(1,3,44,"foo=bar")
|
610
|
+
assert_ene om, Example.new(1,3,4,"foo=BAR")
|
611
|
+
|
612
|
+
end
|
613
|
+
|
614
|
+
|
615
|
+
|
616
|
+
def test_constructors_create_right_syntax_nodes
|
617
|
+
#most of the examples use the longer, tla form for the outermost reg....
|
618
|
+
#to avoid warnigns without (). anyway, here are the basic equivalences between the
|
619
|
+
#operator, tla, and long forms or Reg.
|
620
|
+
#operator form
|
621
|
+
assert_eee Reg::Array, +[]
|
622
|
+
assert_eee Reg::Subseq, -[]
|
623
|
+
assert_eee Reg::Hash, +{}
|
624
|
+
assert_eee Reg::Object, -{}
|
625
|
+
|
626
|
+
#tla form (square and round brackets)
|
627
|
+
assert_eee Reg::Array, Reg[]
|
628
|
+
assert_eee Reg::Subseq, Res[]
|
629
|
+
assert_eee Reg::Hash, Rah[]
|
630
|
+
assert_eee Reg::Object, Rob[]
|
631
|
+
|
632
|
+
assert_eee Reg::Array, Reg()
|
633
|
+
assert_eee Reg::Subseq, Res()
|
634
|
+
assert_eee Reg::Hash, Rah()
|
635
|
+
assert_eee Reg::Object, Rob()
|
636
|
+
|
637
|
+
assert_eee Reg::Or, /a/|/b/
|
638
|
+
assert_eee Reg::And, /a/&/b/
|
639
|
+
assert_eee Reg::Xor, /a/^/b/
|
640
|
+
|
641
|
+
end
|
642
|
+
|
643
|
+
|
644
|
+
def test_OBS_guts
|
645
|
+
if defined? $MMATCH_PROGRESS #cvt to cmatch someday
|
646
|
+
data=[1]
|
647
|
+
r=1.reg.*
|
648
|
+
pr=Reg::Progress.new(+[r],data.to_sequence)
|
649
|
+
ms=r.mmatch(pr)
|
650
|
+
assert ms.next_match(data,0).last==1
|
651
|
+
assert ms.next_match(data,0).last==0
|
652
|
+
assert ms.next_match(data,0)==nil
|
653
|
+
|
654
|
+
data=[1]
|
655
|
+
r=-[nil.reg.-]
|
656
|
+
pr=Reg::Progress.new(+[r],data.to_sequence)
|
657
|
+
ms=r.mmatch(pr)
|
658
|
+
assert ms.next_match(data,0).last==0
|
659
|
+
assert ms.next_match(data,0)==nil
|
660
|
+
|
661
|
+
data=[1]
|
662
|
+
r=-[nil]
|
663
|
+
pr=Reg::Progress.new(+[r],data.to_sequence)
|
664
|
+
ms=r.mmatch(pr)
|
665
|
+
assert ms.nil?
|
666
|
+
|
667
|
+
data=[1]
|
668
|
+
r=-[1.reg.-,nil]
|
669
|
+
pr=Reg::Progress.new(+[r],data.to_sequence)
|
670
|
+
ms=r.mmatch(pr)
|
671
|
+
assert ms.nil?
|
672
|
+
|
673
|
+
data=[1]
|
674
|
+
r=-[1.reg.*,nil]
|
675
|
+
pr=Reg::Progress.new(+[r],data.to_sequence)
|
676
|
+
ms=r.mmatch(pr)
|
677
|
+
assert ms.nil?
|
678
|
+
|
679
|
+
data=[1]
|
680
|
+
r=-[OBS,nil]
|
681
|
+
pr=Reg::Progress.new(+[r],data.to_sequence)
|
682
|
+
ms=r.mmatch(pr)
|
683
|
+
assert ms.nil?
|
684
|
+
|
685
|
+
data=[1]
|
686
|
+
r=-[-[OBS,nil]|1]
|
687
|
+
pr=Reg::Progress.new(+[r],data.to_sequence)
|
688
|
+
ms=r.mmatch(pr)
|
689
|
+
assert ms.next_match(data,0).last==1
|
690
|
+
assert ms.next_match(data,0)==nil
|
691
|
+
end
|
692
|
+
end
|
693
|
+
|
694
|
+
def try_OBS(exp=+[1,2,3])
|
695
|
+
[
|
696
|
+
[1,2,3],
|
697
|
+
[nil,nil,nil,1,2,3,nil,nil,nil],
|
698
|
+
[1,2,3,nil,nil,nil],
|
699
|
+
[nil,nil,nil,1,2,3]
|
700
|
+
].map{|data| exp===data ? true : false }
|
701
|
+
end
|
702
|
+
|
703
|
+
def test_OBS
|
704
|
+
assert_eee( +[], [] )
|
705
|
+
assert_eee( +[1.reg.-,1], [1] )
|
706
|
+
assert_eee( +[1.reg-2,1], [1,1] )
|
707
|
+
assert_eee( +[1.reg.*,1], [1,1] )
|
708
|
+
assert_eee( +[OBS], [] )
|
709
|
+
assert_eee( +[-[]], [] )
|
710
|
+
check_matcher(
|
711
|
+
[ +[OBS], ],
|
712
|
+
:matches=>[[],[1],[2],["1"]], :unmatches=>[{},1,:foo,nil,proc{}]
|
713
|
+
)
|
714
|
+
check_matcher(
|
715
|
+
[ +[1,OBS], +[1.reg.*,1], +[OBS,1], +[OBS,OBS,1], +[OBS,OBS,OBS,1] ],
|
716
|
+
:matches=>[[1],[1,1]], :unmatches=>[[2],["1"],[]]
|
717
|
+
)
|
718
|
+
check_matcher(
|
719
|
+
[ +[OBS|1] ],
|
720
|
+
:matches=>[[1],[2],["1"],[],[1,1]]
|
721
|
+
)
|
722
|
+
|
723
|
+
|
724
|
+
assert_ene(+[OBS,3], [3,nil,nil,nil])
|
725
|
+
assert_ene(+[1,2,OBS,3], [1,2,3,nil,nil,nil]) #delete this once it works again
|
726
|
+
assert_eee try_OBS, [true,false,false,false]
|
727
|
+
assert_eee try_OBS(+[1,2,3,OBS]), [true,false,true,false]
|
728
|
+
assert_eee try_OBS(+[1,2,OBS,3]), [true,false,false,false]
|
729
|
+
assert_eee try_OBS(+[1,OBS,2,3]), [true,false,false,false]
|
730
|
+
assert_eee try_OBS(+[OBS,1,2,3]), [true,false,false,true]
|
731
|
+
assert_eee try_OBS(+[OBS,1,2,3,OBS]), [true,true,true,true]
|
732
|
+
10.times { #seemingly, this one's not deterministic
|
733
|
+
check_matcher(
|
734
|
+
[ +[nil.reg|1], +[-[OBS,nil]|1] ],
|
735
|
+
:matches=>[[1]], :unmatches=>[[2],["1"],[],[1,1]]
|
736
|
+
)
|
737
|
+
}
|
738
|
+
end
|
739
|
+
|
740
|
+
|
741
|
+
|
742
|
+
def test_and
|
743
|
+
assert_ene( -[], [] )
|
744
|
+
assert_ene( Reg::And.new(-[]), [] )
|
745
|
+
assert_eee( Reg::And.new(+[]), [] )
|
746
|
+
assert_eee( +[Reg::And.new(-[])], [] )
|
747
|
+
10.times { assert_ene( +[-[]&1], [] ) }
|
748
|
+
10.times { assert_eee( +[-[]&1], [1] ) }
|
749
|
+
10.times {
|
750
|
+
assert_eee( +[1.reg&1], [1] )
|
751
|
+
assert_eee( +[1.reg.-.&(1)], [1] )
|
752
|
+
assert_eee( +[1.reg.*.&(1)], [1] )
|
753
|
+
assert_eee( +[1.reg.+.&(1)], [1] )
|
754
|
+
assert_eee( +[OB&1], [1] )
|
755
|
+
assert_eee( +[OBS&1], [1] )
|
756
|
+
assert_eee( +[OBS&1], [1,1] )
|
757
|
+
}
|
758
|
+
|
759
|
+
assert_equal +[OB&(-[])],[]
|
760
|
+
assert_equal +[OB&(-[])],nil
|
761
|
+
check_matcher(
|
762
|
+
[ +[OBS&1] ],
|
763
|
+
:matches=>[[1],[1,1],[1,2]], :unmatches=>[[2],["1"],[]]
|
764
|
+
)
|
765
|
+
|
766
|
+
|
767
|
+
|
768
|
+
end
|
769
|
+
|
770
|
+
|
771
|
+
def test_reg
|
772
|
+
# assert_eee( +[OB-1+1]===[1] ) #the 0*infinity problem #not working
|
773
|
+
# assert_eee( +[OB-1-2+1]===[1,2] ) #the 0*infinity problem #not working
|
774
|
+
|
775
|
+
|
776
|
+
assert_eee( +[], [] )
|
777
|
+
assert_eee( +[1], [1] )
|
778
|
+
|
779
|
+
assert_eee( +[ 1.reg.-], [] )
|
780
|
+
assert_eee( +[ 1.reg.-, 3], [3] )
|
781
|
+
assert_eee( +[ 1.reg.-, 3], [1,3] ) #is the world flat?
|
782
|
+
assert_ene( +[ 1.reg.-, 3], [1,4] ) #is the world flat?
|
783
|
+
assert_eee( +[ 1.reg.-, 1], [1] )
|
784
|
+
|
785
|
+
assert_eee( +[-[ 1.reg.-,3]], [1,3] ) #is the world flat?
|
786
|
+
assert_ene( +[-[ 1.reg.-,3]], [1,4] ) #is the world flat?
|
787
|
+
assert_eee( +[-[ 1.reg.-, 2.reg.-], 3], [1,2,3] ) #is the world flat?
|
788
|
+
assert_ene( +[-[ 1.reg.-, 2.reg.-], 3], [1,2,4] ) #is the world flat?
|
789
|
+
assert_eee( +[ 1.reg.-, 2.reg-2, 3], [1,2,2,3] ) #is the world flat?
|
790
|
+
assert_ene( +[ 1.reg.-, 2.reg-2, 3], [1,2,2,4] ) #is the world flat?
|
791
|
+
assert_eee( +[-[ 1.reg.-, 2.reg-2], 3], [1,2,2,3] ) #is the world flat?
|
792
|
+
assert_ene( +[-[2.reg*2], 3], [2,2,4] ) #is the world flat?
|
793
|
+
#$RegTraceEnable=1 #debugging zone:
|
794
|
+
#require 'reginstrumentation'
|
795
|
+
assert_ene Reg[-[OB,OB]*(1..2)], [:foo]*3
|
796
|
+
assert_ene Reg[-[OB*2]*(1..2)], [:foo]*3
|
797
|
+
assert_eee Reg[-[OB+2]*(1..2)], [:foo]*3
|
798
|
+
assert_eee Reg[-[OB-2]*(1..2)], [:foo]*3
|
799
|
+
assert_ene( +[-[2.reg-2], 3.reg], [2,2,4] ) #is the world flat?
|
800
|
+
assert_eee( +[-[2.reg-2], 3], [2,2,3] ) #is the world flat?
|
801
|
+
assert_ene( +[-[ 1.reg.-, 2.reg-2], 3], [1,2,2,4] ) #is the world flat?
|
802
|
+
assert_eee( +[0,-[ 1.reg.-, 2.reg-2], 3], [0,1,2,2,3] ) #is the world flat?
|
803
|
+
assert_ene( +[0,-[ 1.reg.-, 2.reg-2], 3], [0,1,2,2,4] ) #is the world flat?
|
804
|
+
assert_eee( +[0,-[ 1.reg.-, 2.reg-2], 3], [0,1,2,3] ) #is the world flat?
|
805
|
+
assert_ene( +[0,-[ 1.reg.-, 2.reg-2], 3], [0,1,2,4] ) #is the world flat?
|
806
|
+
assert_eee( +[-[ 1.reg.-, 2.reg-2], 3], [1,2,3] ) #is the world flat?
|
807
|
+
assert_ene( +[-[ 1.reg.-, 2.reg-2], 3], [1,2,4] ) #is the world flat?
|
808
|
+
|
809
|
+
assert_eee( +[1.reg.+, 1], [1,1] )
|
810
|
+
|
811
|
+
#...someday convert to use cmatch in these tests
|
812
|
+
if defined? $MMATCH_PROGRESS
|
813
|
+
data=[:foo]*2
|
814
|
+
r=(OB)*(1..2)
|
815
|
+
pr=Reg::Progress.new(+[r],data.to_sequence)
|
816
|
+
ms=r.mmatch(pr)
|
817
|
+
assert ms.next_match(data,0).last==2
|
818
|
+
assert ms.next_match(data,0).last==1
|
819
|
+
assert ms.next_match(data,0)==nil
|
820
|
+
|
821
|
+
data=[:foo]*2
|
822
|
+
r=(OB*1)*(1..2)
|
823
|
+
pr=Reg::Progress.new(+[r],data.to_sequence)
|
824
|
+
ms=r.mmatch(pr)
|
825
|
+
assert ms.next_match(data,0).last==2
|
826
|
+
assert ms.next_match(data,0).last==1
|
827
|
+
assert ms.next_match(data,0)==nil
|
828
|
+
|
829
|
+
data=[:foo]*3
|
830
|
+
r=(OB*1)*(1..3)
|
831
|
+
pr=Reg::Progress.new(+[r],data.to_sequence)
|
832
|
+
ms=r.mmatch(pr)
|
833
|
+
assert ms.next_match(data,0).last==3
|
834
|
+
assert ms.next_match(data,0).last==2
|
835
|
+
assert ms.next_match(data,0).last==1
|
836
|
+
assert ms.next_match(data,0)==nil
|
837
|
+
|
838
|
+
data=[:foo]*4
|
839
|
+
r=(OB*2)*(1..2)
|
840
|
+
pr=Reg::Progress.new(+[r],data.to_sequence)
|
841
|
+
ms=r.mmatch(pr)
|
842
|
+
assert ms.next_match(data,0).last==4
|
843
|
+
assert ms.next_match(data,0).last==2
|
844
|
+
assert ms.next_match(data,0)==nil
|
845
|
+
|
846
|
+
data=[:foo]*6
|
847
|
+
r=(OB*2)*(1..2)*2
|
848
|
+
pr=Reg::Progress.new(+[r],data.to_sequence)
|
849
|
+
ms=r.mmatch(pr)
|
850
|
+
assert ms.next_match(data,0).last==6
|
851
|
+
assert ms.next_match(data,0).last==6
|
852
|
+
assert ms.next_match(data,0).last==4
|
853
|
+
assert ms.next_match(data,0)==nil
|
854
|
+
|
855
|
+
data=[:foo]*7
|
856
|
+
r=(OB*2)*(1..2)*2
|
857
|
+
pr=Reg::Progress.new(-[Symbol,r],data.to_sequence)
|
858
|
+
ms=r.mmatch(pr)
|
859
|
+
assert ms.next_match(data,0).last==7
|
860
|
+
assert ms.next_match(data,0).last==7
|
861
|
+
assert ms.next_match(data,0).last==5
|
862
|
+
assert ms.next_match(data,0)==nil
|
863
|
+
|
864
|
+
data=[:foo]*7
|
865
|
+
r=-[(OB*2)*(1..2),(OB*2)*(1..2)]
|
866
|
+
pr=Reg::Progress.new(-[Symbol,r],data.to_sequence)
|
867
|
+
ms=r.mmatch(pr)
|
868
|
+
assert ms.next_match(data,0).last==7
|
869
|
+
assert ms.next_match(data,0).last==7
|
870
|
+
assert ms.next_match(data,0).last==5
|
871
|
+
assert ms.next_match(data,0)==nil
|
872
|
+
|
873
|
+
data=[:foo]*7
|
874
|
+
r=(OB*2)*(1..2)*2
|
875
|
+
pr=Reg::Progress(+[r],data.to_sequence)
|
876
|
+
ms=r.mmatch(pr)
|
877
|
+
assert ms.nil?
|
878
|
+
|
879
|
+
data=[:foo]*8
|
880
|
+
r=(OB*2)*(1..2)*2
|
881
|
+
pr=Reg::Progress.new(+[r],data.to_sequence)
|
882
|
+
ms=r.mmatch(pr)
|
883
|
+
assert ms.next_match(data,0)==8
|
884
|
+
assert ms.next_match(data,0)==6
|
885
|
+
assert ms.next_match(data,0)==6
|
886
|
+
assert ms.next_match(data,0)==4
|
887
|
+
assert ms.next_match(data,0)==nil
|
888
|
+
$RegTraceEnable=false#end debug zone
|
889
|
+
end
|
890
|
+
|
891
|
+
|
892
|
+
|
893
|
+
|
894
|
+
|
895
|
+
assert_eee( +[ item_that.size], ["b"] )
|
896
|
+
|
897
|
+
|
898
|
+
|
899
|
+
assert_eee Reg[OB*(1..2)], [:foo]*2
|
900
|
+
assert_eee Reg[OB.*(1..2).l], [:foo]*2
|
901
|
+
|
902
|
+
assert_eee( +[-[ 1.reg.-], 3], [1,3] ) #is the world flat?
|
903
|
+
assert_ene( +[-[ 1.reg.-], 3], [1,4] ) #is the world flat?
|
904
|
+
assert_eee( +[-[ 1.reg.-, 2.reg.-], 3], [1,2,3] ) #is the world flat?
|
905
|
+
$RegTraceEnable=1 #debugging zone:
|
906
|
+
#require 'reginstrumentation'
|
907
|
+
assert_ene( +[-[ 1.reg.-, 2.reg.-], 3.reg], [1,2,4] ) #is the world flat?
|
908
|
+
assert_eee( +[-[ 1.reg.-, 2.reg-2], 3], [1,2,2,3] ) #is the world flat?
|
909
|
+
assert_ene( +[-[ 1.reg.-, 2.reg-2], 3], [1,2,2,4] ) #is the world flat?
|
910
|
+
|
911
|
+
#disabled til lazy matchers are invented
|
912
|
+
# assert_eee Reg[(OB*(1..2)).l*2], [:foo]*4
|
913
|
+
|
914
|
+
assert_eee Reg[-[OB]], [:foo]*1
|
915
|
+
assert_eee Reg[-[OB]*(1..2)], [:foo]*1
|
916
|
+
assert_eee Reg[-[OB]*(1..2)], [:foo]*2
|
917
|
+
assert_eee Reg[-[OB,OB]*(1..2)], [:foo]*2
|
918
|
+
assert_ene Reg[-[OB,OB]*(1..2)], [:foo]*3
|
919
|
+
assert_eee Reg[-[OB,OB]*(1..2)], [:foo]*4
|
920
|
+
|
921
|
+
assert_eee Reg[OB*2*(1..2)], [:foo]*2
|
922
|
+
assert_ene Reg[OB*2*(1..2)], [:foo]*3
|
923
|
+
assert_eee Reg[OB*2*(1..2)], [:foo]*4
|
924
|
+
|
925
|
+
|
926
|
+
assert_eee( +[Set[1,2,3]], [1] )
|
927
|
+
assert_eee( +[Set[1,2,3]], [2] )
|
928
|
+
assert_ene( +[Set[1,2,3]], [4] )
|
929
|
+
|
930
|
+
assert case Set[1,2,3]
|
931
|
+
when Set[1,2,3]; true
|
932
|
+
end
|
933
|
+
|
934
|
+
assert [Set[1,2,3]].grep Set[1,2,3]
|
935
|
+
assert !([1].grep Set[1,2,3] ).first
|
936
|
+
assert !([2].grep Set[1,2,3] ).first
|
937
|
+
assert !([3].grep Set[1,2,3] ).first
|
938
|
+
assert_eee( +[-[:foo, :foo]|-[:foo, :foo, :foo, :foo]], [:foo]*4 )
|
939
|
+
assert_eee( +[-[:foo, :foo, :foo, :foo]|-[:foo, :foo]], [:foo]*4 )
|
940
|
+
assert_eee( +[:foo.reg*2|:foo.reg*4], [:foo]*4 )
|
941
|
+
assert_eee( +[:foo.reg*4|:foo.reg*2], [:foo]*4 )
|
942
|
+
|
943
|
+
assert_eee( +[-[:foo, :foo]|-[:foo, :foo, :foo, :foo]], [:foo]*2 )
|
944
|
+
assert_eee( +[-[:foo, :foo, :foo, :foo]|-[:foo, :foo]], [:foo]*2 )
|
945
|
+
assert_eee( +[:foo.reg*2|:foo.reg*4], [:foo]*2 )
|
946
|
+
assert_eee( +[:foo.reg*4|:foo.reg*2], [:foo]*2 )
|
947
|
+
|
948
|
+
assert_eee Reg[(OB*2)*(1..2)*2, (OB*2)], [:foo]*6
|
949
|
+
assert_eee Reg[(OB+2)*(1..2)+2, OB+2], [:foo]*6
|
950
|
+
|
951
|
+
assert_eee Reg[-[(OB*2)*(1..2),(OB*2)*(1..2)], (OB*2)], [:foo]*6
|
952
|
+
assert_eee Reg[(OB*2)*(1..2),(OB*2)*(1..2), (OB*2)], [:foo]*6
|
953
|
+
|
954
|
+
assert_eee Reg[OB+1,OB+6], [:foo]*7
|
955
|
+
assert_eee Reg[OB+1,OB+26], [:foo]*27
|
956
|
+
assert_eee Reg[OB*(1..20),OB+7], [:foo]*27
|
957
|
+
assert_eee Reg[OB*(1..40),OB+7], [:foo]*27
|
958
|
+
assert_eee Reg[OB+6,OB+1], [:foo]*7
|
959
|
+
assert_eee Reg[OB+1,OB+1,OB+1], [:foo]*3
|
960
|
+
|
961
|
+
|
962
|
+
|
963
|
+
assert_eee( +[], [] )
|
964
|
+
assert_ene( +[], [:q] )
|
965
|
+
assert_eee( +[:q], [:q] )
|
966
|
+
assert_eee( +[-[]], [] )
|
967
|
+
assert_eee( +[-[-[]]], [] )
|
968
|
+
assert_ene( +[-[Reg::Xor[]]], [] )
|
969
|
+
assert_ene( +[-[Reg::And[]]], [] )
|
970
|
+
assert_ene( +[-[Reg::Or[]]], [] )
|
971
|
+
assert_eee( +[//*0], [] )
|
972
|
+
assert_eee( +[-[//*0]], [] )
|
973
|
+
assert_eee( +[-[//-0]], [] )
|
974
|
+
assert_eee( +[-[:q]], [:q] )
|
975
|
+
assert_eee( +[-[:q]*1], [:q] )
|
976
|
+
assert_eee( +[-[:q, :q]*1], [:q,:q] )
|
977
|
+
assert_eee( +[-[:q, :q]*(0..1)], [:q,:q] )
|
978
|
+
assert_eee( +[-[:q, :q]*(0..2)], [:q,:q] )
|
979
|
+
assert_eee( +[-[:q, :q]*(0..4)], [:q,:q] )
|
980
|
+
assert_eee( +[-[:q, :q]*(0..10)], [:q,:q] )
|
981
|
+
assert_eee( +[-[:q, :q]-1], [:q,:q] )
|
982
|
+
assert_eee( +[:q.reg+1], [:q] )
|
983
|
+
assert_eee( +[/q/+1], ['q'] )
|
984
|
+
assert_eee( +[-[:q]+1], [:q] )
|
985
|
+
assert_eee( +[-[:q, :q]+1], [:q,:q] )
|
986
|
+
assert_eee( +[-[:q, :q]+0], [:q,:q] )
|
987
|
+
|
988
|
+
|
989
|
+
|
990
|
+
|
991
|
+
lenheadalts=-[0]|-[1,OB]|-[2,OB*2]|-[3,OB*3]|-[4,OB*4]
|
992
|
+
lenheadlist=lenheadalts+1
|
993
|
+
|
994
|
+
lenheaddata=[0,0,0,1,:foo,4,:foo,:bar,:baz,:zork,3,:k,77,88]
|
995
|
+
lenheaddataj=lenheaddata+[:j]
|
996
|
+
|
997
|
+
lentailalts=-[OB,-1]|-[OB*2,-2]|-[OB*3,-3]|-[OB*4,-4]
|
998
|
+
lentaildata=lenheaddata.reverse.map {|x| Integer===x ? -x : x }
|
999
|
+
infixalts=-[OB,"infix1",OB]|-[OB*2,'infix2',OB*2]|
|
1000
|
+
-[OB*3,'infix3',OB*3]|-[OB*4,'infix4',OB*4]
|
1001
|
+
|
1002
|
+
|
1003
|
+
qq=-[:q, ~(:q.reg)+0, :q]
|
1004
|
+
_QQ=-[:Q, ( ~/^[Q\\]$/.sym | -[:'\\',OB] )+0, :Q]
|
1005
|
+
|
1006
|
+
be=begin_end_pattern :+, 0
|
1007
|
+
|
1008
|
+
lh_or_qq=lenheadalts|qq|_QQ
|
1009
|
+
lhqqbe=lh_or_qq|be
|
1010
|
+
|
1011
|
+
|
1012
|
+
|
1013
|
+
assert_eee( +[qq*1], [:q,:q] )
|
1014
|
+
assert_eee( +[qq+0], [:q,:q] )
|
1015
|
+
|
1016
|
+
assert_eee( +_QQ, [:Q,:Q] )
|
1017
|
+
assert_eee( +[_QQ], [:Q,:Q] )
|
1018
|
+
assert_eee( +[_QQ*1], [:Q,:Q] )
|
1019
|
+
assert_eee( +[_QQ+0], [:Q,:Q] )
|
1020
|
+
|
1021
|
+
assert_eee ::Reg::var.set!(+[1]), [1]
|
1022
|
+
|
1023
|
+
assert_eee( +[be], [:begin,:end] )
|
1024
|
+
assert_eee( +[be*1], [:begin,:end] )
|
1025
|
+
assert_eee( +[be+0], [:begin,:end] )
|
1026
|
+
assert_eee( +[be+0], [:begin,:end,:begin,:end] )
|
1027
|
+
|
1028
|
+
|
1029
|
+
assert_eee( +[], [] )
|
1030
|
+
assert_ene( +[], [1] )
|
1031
|
+
assert_eee( +[-[]], [] )
|
1032
|
+
assert_ene( +[-[]], [1] )
|
1033
|
+
|
1034
|
+
|
1035
|
+
assert_ene Reg[-[:foo,:bar]-1], [:bar,:foo]
|
1036
|
+
assert_ene Reg[-[:foo,:bar]-1], [:baz,:foo,:bar]
|
1037
|
+
assert_ene Reg[-[:foo,:bar]-1], [:foo,:bar,:baz]
|
1038
|
+
assert_eee Reg[-[:foo,:bar]-1], [:foo,:bar]
|
1039
|
+
assert_ene Reg[-[:foo,:bar]-1], [:foo]
|
1040
|
+
assert_ene Reg[-[:foo,:bar]-1], [:bar]
|
1041
|
+
assert_ene Reg[-[:foo,:bar]-1], [:baz]
|
1042
|
+
assert_eee Reg[-[:foo,:bar]-1], []
|
1043
|
+
|
1044
|
+
|
1045
|
+
|
1046
|
+
assert_eee Reg[OB.+], [1]
|
1047
|
+
assert_eee Reg[OB.+], [1,2,3]
|
1048
|
+
assert_eee Reg[OB.-], [1]
|
1049
|
+
assert_ene Reg[OB.-], [1,2,3]
|
1050
|
+
assert_ene Reg[:a, OB-1, :b, :b, :b, :b, :b], [:a, 1,1,1,1,1,1, :b, :b, :b, :b, :b]
|
1051
|
+
assert_eee Reg[:a, OB-1, :b, :b, :b, :b, :b], [:a, 1, :b, :b, :b, :b, :b]
|
1052
|
+
assert_eee Reg[:a, OB-1, :b, :b, :b, :b, :b], [:a, :b, :b, :b, :b, :b]
|
1053
|
+
assert_ene Reg[:a, OB-1, :b, :b, :b, :b, :b], [1, :b, :b, :b, :b, :b]
|
1054
|
+
assert_ene Reg[:a, OB-1, :b, :b, :b, :b, :b], [:b, :b, :b, :b, :b]
|
1055
|
+
assert_ene Reg[:a, OB-1, :b, :b, :b, :b, :b], [:a, 1, :b, :b, :b, :b]
|
1056
|
+
assert_ene Reg[:a, OB-1, :b, :b, :b, :b, :b], [:a, :b, :b, :b, :b]
|
1057
|
+
|
1058
|
+
|
1059
|
+
|
1060
|
+
if defined? NextMatchTests
|
1061
|
+
a=[:foo]
|
1062
|
+
x=(:foo.reg-1).mmatch a,0
|
1063
|
+
assert x.next_match(a,0)==[[[:foo]],1]
|
1064
|
+
assert x.next_match(a,0)==[[[]],0]
|
1065
|
+
assert x.next_match(a,0)==nil
|
1066
|
+
x=(:foo.reg-1).mmatch a,1
|
1067
|
+
assert x==[[[]],0]
|
1068
|
+
|
1069
|
+
a=[:foo]
|
1070
|
+
x=(:foo.reg-1-1).mmatch a,0
|
1071
|
+
assert x.next_match(a,0)==[[[[:foo]]],1]
|
1072
|
+
assert x.next_match(a,0)==[[[]],0]
|
1073
|
+
assert x.next_match(a,0)==nil
|
1074
|
+
|
1075
|
+
|
1076
|
+
|
1077
|
+
|
1078
|
+
|
1079
|
+
|
1080
|
+
a=(1..5).to_a
|
1081
|
+
r=OB+1+3
|
1082
|
+
x=r.mmatch a,0
|
1083
|
+
assert x.next_match(a,0)==[[ [[1, 2, 3]], [[4]], [[5]] ], 5]
|
1084
|
+
assert x.next_match(a,0)==[[ [[1, 2]], [[3, 4]], [[5]] ], 5]
|
1085
|
+
assert x.next_match(a,0)==[[ [[1, 2]], [[3]], [[4, 5]] ], 5]
|
1086
|
+
assert x.next_match(a,0)==[[ [[1, 2]], [[3]], [[4]], [[5]] ], 5]
|
1087
|
+
assert x.next_match(a,0)==[[ [[1, 2]], [[3]], [[4]] ], 4]
|
1088
|
+
assert x.next_match(a,0)==[[ [[1]], [[2, 3, 4]], [[5]] ], 5]
|
1089
|
+
assert x.next_match(a,0)==[[ [[1]], [[2, 3]], [[4, 5]] ], 5]
|
1090
|
+
assert x.next_match(a,0)==[[ [[1]], [[2, 3]], [[4]], [[5]] ], 5]
|
1091
|
+
assert x.next_match(a,0)==[[ [[1]], [[2, 3]], [[4]] ], 4]
|
1092
|
+
assert x.next_match(a,0)==[[ [[1]], [[2]], [[3, 4, 5]] ], 5]
|
1093
|
+
assert x.next_match(a,0)==[[ [[1]], [[2]], [[3, 4]], [[5]] ], 5]
|
1094
|
+
assert x.next_match(a,0)==[[ [[1]], [[2]], [[3, 4]] ], 4]
|
1095
|
+
assert x.next_match(a,0)==[[ [[1]], [[2]], [[3]], [[4, 5]] ], 5]
|
1096
|
+
assert x.next_match(a,0)==[[ [[1]], [[2]], [[3]], [[4]], [[5]] ], 5]
|
1097
|
+
assert x.next_match(a,0)==[[ [[1]], [[2]], [[3]], [[4]] ], 4]
|
1098
|
+
assert x.next_match(a,0)==[[ [[1]], [[2]], [[3]]], 3]
|
1099
|
+
assert x.next_match(a,0)==nil
|
1100
|
+
|
1101
|
+
end
|
1102
|
+
|
1103
|
+
|
1104
|
+
assert_ene Reg[OB+1+2+2], [:f]*3
|
1105
|
+
assert_ene Reg[OB+2+1+2], [:f]*3
|
1106
|
+
assert_eee Reg[OB+1+2+2], [:f]*4
|
1107
|
+
assert_eee Reg[OB+2+2+1], [:f]*4
|
1108
|
+
assert_eee Reg[OB+2+1+2], [:f]*4
|
1109
|
+
assert_ene Reg[OB+2+2+2], [:f]*7
|
1110
|
+
assert_eee Reg[OB+2+2+2], [:f]*8
|
1111
|
+
|
1112
|
+
|
1113
|
+
|
1114
|
+
|
1115
|
+
assert_ene Reg[OB+2+2+3], [:f]*11
|
1116
|
+
assert_eee Reg[OB+2+2+3], [:f]*12
|
1117
|
+
assert_eee Reg[OB+2+2+3], [:f]*16
|
1118
|
+
|
1119
|
+
assert_ene Reg[5.reg+1+3+2], [6]+[5]*5
|
1120
|
+
assert_ene Reg[5.reg+1+3+2], [5]+[6]+[5]*4
|
1121
|
+
assert_ene Reg[5.reg+1+3+2], [5]*2+[6]+[5]*3
|
1122
|
+
assert_ene Reg[5.reg+1+3+2], [5]*3+[6]+[5]*2
|
1123
|
+
assert_ene Reg[5.reg+1+3+2], [5]*4+[6,5]
|
1124
|
+
assert_ene Reg[5.reg+1+3+2], [5]*5+[6]
|
1125
|
+
|
1126
|
+
assert_eee Reg[OB+1+3+2], [6]+[5]*5
|
1127
|
+
assert_eee Reg[OB+1+3+2], [5]+[6]+[5]*4
|
1128
|
+
assert_eee Reg[OB+1+3+2], [5]*2+[6]+[5]*3
|
1129
|
+
assert_eee Reg[OB+1+3+2], [5]*3+[6]+[5]*2
|
1130
|
+
assert_eee Reg[OB+1+3+2], [5]*4+[6,5]
|
1131
|
+
assert_eee Reg[OB+1+3+2], [5]*5+[6]
|
1132
|
+
|
1133
|
+
assert_ene Reg[OB+1+3+2], [6]+[5]*4
|
1134
|
+
assert_ene Reg[OB+1+3+2], [5]+[6]+[5]*3
|
1135
|
+
assert_ene Reg[OB+1+3+2], [5]*2+[6]+[5]*2
|
1136
|
+
assert_ene Reg[OB+1+3+2], [5]*3+[6]+[5]
|
1137
|
+
assert_ene Reg[OB+1+3+2], [5]*4+[6]
|
1138
|
+
|
1139
|
+
|
1140
|
+
assert_eee Reg[5.reg+1+3+2], [5]*6
|
1141
|
+
assert_ene Reg[5.reg+2+2+2], [5]*8+[6]
|
1142
|
+
assert_ene Reg[:foo.reg*(1..2)*2*2], 0
|
1143
|
+
assert_ene Reg[:foo.reg*1], []
|
1144
|
+
assert_ene Reg[:foo.reg*2], []
|
1145
|
+
assert_ene Reg[:foo.reg*(1)*2], []
|
1146
|
+
|
1147
|
+
assert_ene Reg[OB*(1..2)], []
|
1148
|
+
assert_ene Reg[Symbol*(1..2)], []
|
1149
|
+
assert_ene Reg[:foo.reg*(1..2)], []
|
1150
|
+
assert_ene Reg[:foo.reg*(1..2)*2], []
|
1151
|
+
assert_ene Reg[:foo.reg*(1..2)*2*2], []
|
1152
|
+
assert_ene Reg[:foo.reg*(1..2)*2*2], [:foo]
|
1153
|
+
assert_ene Reg[:foo.reg*(1..2)*2*2], [:foo]*2
|
1154
|
+
assert_ene Reg[:foo.reg*(1..2)*(2..3)*(2..3)], [:foo]*2
|
1155
|
+
assert_ene Reg[:foo.reg*(1..2)*2*2], [:foo]*3
|
1156
|
+
assert_ene Reg[:foo.reg*(1..2)*(2..3)*(2..3)], [:foo]*3
|
1157
|
+
assert_ene Reg[:foo.reg*(1..2)*(2..3)*(2..3)*(2..3)], [:foo]*7
|
1158
|
+
assert_ene Reg[:foo.reg*(1)*(2)*(2)*(2)], [:foo]*7
|
1159
|
+
assert_eee Reg[:foo.reg*(1)*(2)*(2)*(2)], [:foo]*8
|
1160
|
+
assert_eee Reg[:foo.reg*(1..2)*(2)], [:foo]*2
|
1161
|
+
assert_eee Reg[:foo.reg*(1..2)*(3)], [:foo]*3
|
1162
|
+
assert_eee Reg[:foo.reg*(1..2)*(5)], [:foo]*5
|
1163
|
+
assert_eee Reg[:foo.reg*(1..2)*(8)], [:foo]*8
|
1164
|
+
assert_eee Reg[:foo.reg*(1..2)*(2)*(2)*(2)], [:foo]*8
|
1165
|
+
assert_eee Reg[:foo.reg*(1..2)*(2)*(2)*(2..3)], [:foo]*8
|
1166
|
+
assert_eee Reg[:foo.reg*(1..2)*(2)*(2..3)*(2)], [:foo]*8
|
1167
|
+
assert_eee Reg[:foo.reg*(1..2)*(2)*(2..3)*(2..3)], [:foo]*8
|
1168
|
+
assert_eee Reg[:foo.reg*(1..2)*(2..3)*(2)*(2..3)], [:foo]*8
|
1169
|
+
assert_eee Reg[:foo.reg*(1..2)*(2..3)*(2..3)*(2)], [:foo]*8
|
1170
|
+
assert_eee Reg[:foo.reg*(1..2)*(2..3)*(2..3)*(2..3)], [:foo]*8
|
1171
|
+
|
1172
|
+
#too slow
|
1173
|
+
#assert_ene Reg[:foo.reg*(1..2)*(2..3)*(2..3)*(2..3)*(2..3)], [:foo]*15
|
1174
|
+
#assert_eee Reg[:foo.reg*(1..2)*(2..3)*(2..3)*(2..3)*(2..3)], [:foo]*16
|
1175
|
+
#assert_eee Reg[:foo.reg*(1..2)*(2..3)*(2..3)*(2..3)*(2..3)], [:foo]*100
|
1176
|
+
|
1177
|
+
#cause stack overflows
|
1178
|
+
#assert_eee Reg[:foo.reg*(1..2)*(2..3)*(2..3)*(2..3)*(2..3)], [:foo]*160
|
1179
|
+
#assert_eee Reg[:foo.reg*(1..2)*(2..3)*(2..3)*(2..3)*(2..3)], [:foo]*161
|
1180
|
+
#assert_eee Reg[:foo.reg*(1..2)*(2..3)*(2..3)*(2..3)*(2..3)], [:foo]*162
|
1181
|
+
#assert_ene Reg[:foo.reg*(1..2)*(2..3)*(2..3)*(2..3)*(2..3)], [:foo]*163
|
1182
|
+
|
1183
|
+
assert_eee Reg[:foo.reg*(1..2)*(2..3)*(2..3)], [:foo]*4
|
1184
|
+
assert_ene Reg[OB*(1..2)*(2..3)*(2..3)], [:foo]*3
|
1185
|
+
assert_eee Reg[OB*(1..2)*(2..3)*(2..3)], [:foo]*4
|
1186
|
+
assert_ene Reg[OB*(1..2)*(2..3)+2], [:foo]*3
|
1187
|
+
assert_eee Reg[OB*(1..2)*(2..3)+2], [:foo]*4
|
1188
|
+
assert_ene Reg[OB+1+2+2], [:foo]*3
|
1189
|
+
assert_eee Reg[OB+1+2+2], [:foo]*4
|
1190
|
+
|
1191
|
+
assert_eee Reg[OB*(1..3)*(2..3)*2], [:foo]*4
|
1192
|
+
|
1193
|
+
|
1194
|
+
if defined? NextMatchTests
|
1195
|
+
|
1196
|
+
a=[:foo]*6
|
1197
|
+
x=(OB*2*(1..2)*2).mmatch(a,0)
|
1198
|
+
assert x.next_match(a,0)==
|
1199
|
+
[[ [[[:foo, :foo]], [[:foo, :foo]]], [[[:foo, :foo]]] ], 6]
|
1200
|
+
assert x.next_match(a,0)==
|
1201
|
+
[[ [[[:foo, :foo]]], [[[:foo, :foo]], [[:foo, :foo]]] ], 6]
|
1202
|
+
assert x.next_match(a,0)==
|
1203
|
+
[[ [[[:foo, :foo]]], [[[:foo, :foo]]] ], 4]
|
1204
|
+
assert x.next_match(a,0).nil?
|
1205
|
+
end
|
1206
|
+
|
1207
|
+
#$RegTraceEnable=true
|
1208
|
+
assert_eee Reg[OB*2*(1..2)*2], [:foo]*6
|
1209
|
+
assert_eee Reg[OB*2*(1..2)*2,OB,OB], [:foo]*6
|
1210
|
+
assert_eee Reg[OB*2*(1..2)*2,OB*2], [:foo]*6
|
1211
|
+
assert_eee Reg[OB*2*(1..2)*2,OB+2], [:foo]*6
|
1212
|
+
assert_eee Reg[OB*2*(1..2)*2, OB-1], [:foo]*6
|
1213
|
+
assert_eee Reg[OB*2*(1..2)*2, OB-1], [:foo]*7
|
1214
|
+
assert_eee Reg[OB*2*(1..2)*2], [:foo]*8
|
1215
|
+
assert_eee Reg[OB*2*(1..2)*2], [:foo]*4
|
1216
|
+
assert_eee Reg[OB*(2..3)*(1..2)*2], [:foo]*4
|
1217
|
+
assert_eee Reg[OB*(2..3)*(2..3)*(1..2)], [:foo]*4
|
1218
|
+
assert_eee Reg[OB*(2..2)*(2..3)*(2..3)], [:foo]*8
|
1219
|
+
assert_eee Reg[OB*(2..3)*(2..2)*(2..3)], [:foo]*8
|
1220
|
+
|
1221
|
+
assert_eee Reg[OB*(2..3)*(2..3)*2], [:foo]*8
|
1222
|
+
assert_eee Reg[OB*(2..3)*(2..3)*(2..3)], [:foo]*8
|
1223
|
+
assert_ene Reg[:foo.reg*(2..3)*(2..3)*2], [:foo]*7
|
1224
|
+
|
1225
|
+
if defined? NextMatchTests
|
1226
|
+
assert(!(Reg[OB*1*(1..2)]===[:f]).first.empty?)
|
1227
|
+
|
1228
|
+
|
1229
|
+
a=[:foo]*4
|
1230
|
+
x=(OB*(1..2)+2).mmatch(a,0)
|
1231
|
+
assert x.next_match(a,0)==[[ [[:foo, :foo]], [[:foo, :foo]] ], 4]
|
1232
|
+
assert x.next_match(a,0)==[[ [[:foo, :foo]], [[:foo]], [[:foo]] ], 4]
|
1233
|
+
assert x.next_match(a,0)==[[ [[:foo, :foo]], [[:foo]] ], 3]
|
1234
|
+
assert x.next_match(a,0)==[[ [[:foo]], [[:foo, :foo]], [[:foo]] ], 4]
|
1235
|
+
assert x.next_match(a,0)==[[ [[:foo]], [[:foo, :foo]] ], 3]
|
1236
|
+
assert x.next_match(a,0)==[[ [[:foo]], [[:foo]], [[:foo, :foo]] ], 4]
|
1237
|
+
assert x.next_match(a,0)==[[ [[:foo]], [[:foo]], [[:foo]], [[:foo]] ], 4]
|
1238
|
+
assert x.next_match(a,0)==[[ [[:foo]], [[:foo]], [[:foo]] ], 3]
|
1239
|
+
assert x.next_match(a,0)==[[ [[:foo]], [[:foo]] ], 2]
|
1240
|
+
assert x.next_match(a,0)==nil
|
1241
|
+
end
|
1242
|
+
assert_ene Reg[OB*(1..2)+2+2], [:foo]*3
|
1243
|
+
assert_eee Reg[OB*(1..2)+2+2], [:foo]*4
|
1244
|
+
|
1245
|
+
if defined? NextMatchTests
|
1246
|
+
|
1247
|
+
a=(1..9).to_a
|
1248
|
+
x=(OB+2+2+2).mmatch a,0
|
1249
|
+
assert x.next_match(a,0)===[[ [[[1, 2, 3]], [[4, 5]]], [[[6, 7]], [[8, 9]]] ], 9]
|
1250
|
+
assert x.next_match(a,0)===[[ [[[1, 2]], [[3, 4, 5]]], [[[6, 7]], [[8, 9]]] ], 9]
|
1251
|
+
assert x.next_match(a,0)===[[ [[[1, 2]], [[3, 4]]], [[[5, 6, 7]], [[8, 9]]] ], 9]
|
1252
|
+
assert x.next_match(a,0)===[[ [[[1, 2]], [[3, 4]]], [[[5, 6]], [[7, 8, 9]]] ], 9]
|
1253
|
+
assert x.next_match(a,0)===[[ [[[1, 2]], [[3, 4]]], [[[5, 6]], [[7, 8]]] ], 8]
|
1254
|
+
assert x.next_match(a,0)===nil
|
1255
|
+
end
|
1256
|
+
|
1257
|
+
assert_eee Reg[OB+2+2+2], [:foo]*8
|
1258
|
+
assert_eee Reg[OB+2+2+2, OB], [:foo]*9
|
1259
|
+
assert_eee Reg[OB+2+2+2, OB+1], [:foo]*9
|
1260
|
+
assert_eee Reg[OB+2+2+2, OB-1], [:foo]*9
|
1261
|
+
assert_eee Reg[OB+2+2+2], [:foo]*9
|
1262
|
+
|
1263
|
+
if defined? NextMatchTests
|
1264
|
+
a=[:foo]*4
|
1265
|
+
x=(OB*2*(1..2)).mmatch(a,2)
|
1266
|
+
assert x.next_match(a,2)==[[[[:foo, :foo]]], 2]
|
1267
|
+
assert x.next_match(a,2)==nil
|
1268
|
+
end
|
1269
|
+
|
1270
|
+
assert_eee( +[OB*(1..2)*2],[:foo]*2)
|
1271
|
+
|
1272
|
+
if defined? NextMatchTests
|
1273
|
+
a=[:foo]*3
|
1274
|
+
x=(OB*(1..2)*2).mmatch(a,0)
|
1275
|
+
assert x.next_match(a,0)==
|
1276
|
+
[[ [[:foo, :foo]], [[:foo]] ], 3]
|
1277
|
+
assert x.next_match(a,0)==
|
1278
|
+
[[ [[:foo]], [[:foo, :foo]] ], 3]
|
1279
|
+
assert x.next_match(a,0)==
|
1280
|
+
[[ [[:foo]], [[:foo]] ], 2]
|
1281
|
+
assert x.next_match(a,0).nil?
|
1282
|
+
end
|
1283
|
+
|
1284
|
+
assert_ene Reg[OB*(2..2)*(2..3)*(2..3)], [:foo]*7
|
1285
|
+
assert_ene Reg[OB*(2..3)*(2..2)*(2..3)], [:foo]*7
|
1286
|
+
assert_ene Reg[OB*(1..3)*(2..3)*2], [:foo]*3
|
1287
|
+
assert_ene Reg[OB*(2..3)*(1..3)*2], [:foo]*3
|
1288
|
+
assert_ene Reg[OB*(2..3)*(2..3)*(1..2)], [:foo]*3
|
1289
|
+
|
1290
|
+
assert_ene Reg[OB*(2..3)*(2..3)*2], [:foo]*7
|
1291
|
+
assert_ene Reg[OB*(2..3)*(2..3)*(2..3)], [:foo]*7
|
1292
|
+
assert_ene Reg[OB+2+2+2], [:foo]*7
|
1293
|
+
|
1294
|
+
|
1295
|
+
assert_eee Reg[OB*2*1*2], [:foo]*4
|
1296
|
+
assert_eee Reg[OB*1*(1..2)*2], [:foo]*2
|
1297
|
+
assert_eee Reg[OB*2*(1..2)*1], [:foo]*2
|
1298
|
+
assert_eee Reg[OB*1*(1..2)*2], [:foo]*3
|
1299
|
+
assert_ene Reg[OB*2*(1..2)*1], [:foo]*3
|
1300
|
+
assert_eee Reg[OB*1*(1..2)*2], [:foo]*4
|
1301
|
+
assert_eee Reg[OB*2*(1..2)*1], [:foo]*4
|
1302
|
+
|
1303
|
+
|
1304
|
+
if defined? NextMatchTests
|
1305
|
+
|
1306
|
+
a=[:foo]*3
|
1307
|
+
x=(:foo.reg*(1..2)).mmatch a,0
|
1308
|
+
assert x.next_match(a,0)==[[[:foo]*2],2]
|
1309
|
+
assert x.next_match(a,0)==[[[:foo]],1]
|
1310
|
+
assert x.next_match(a,0)==nil
|
1311
|
+
|
1312
|
+
x=(:foo.reg*(1..2)).mmatch a,1
|
1313
|
+
assert x.next_match(a,0)==[[[:foo]*2],2]
|
1314
|
+
assert x.next_match(a,0)==[[[:foo]],1]
|
1315
|
+
assert x.next_match(a,0)==nil
|
1316
|
+
|
1317
|
+
x=(:foo.reg*(1..2)).mmatch a,2
|
1318
|
+
assert x==[[[:foo]],1]
|
1319
|
+
|
1320
|
+
x=(:foo.reg*(1..2)).mmatch a,3
|
1321
|
+
assert x.nil?
|
1322
|
+
|
1323
|
+
x=(:foo.reg*(1..2)*(2..3)).mmatch a,0
|
1324
|
+
assert x.next_match(a,0)==[[[[:foo]*2],[[:foo]]], 3]
|
1325
|
+
assert x.instance_eval{@ri}==2
|
1326
|
+
assert x.next_match(a,0)==[[[[:foo]],[[:foo]*2]], 3]
|
1327
|
+
assert x.instance_eval{@ri}==2
|
1328
|
+
assert x.next_match(a,0)==[[[[:foo]],[[:foo]],[[:foo]]], 3]
|
1329
|
+
assert x.instance_eval{@ri}==3
|
1330
|
+
assert x.next_match(a,0)==[[[[:foo]],[[:foo]]], 2]
|
1331
|
+
assert x.instance_eval{@ri}==2
|
1332
|
+
assert x.next_match(a,0)==nil
|
1333
|
+
|
1334
|
+
x=(:foo.reg*(1..2)*(2..3)).mmatch a,1
|
1335
|
+
assert x.next_match(a,0)==[[[[:foo]],[[:foo]]], 2]
|
1336
|
+
assert x.instance_eval{@ri}==2
|
1337
|
+
assert x.next_match(a,0)==nil
|
1338
|
+
|
1339
|
+
x=(:foo.reg*(1..2)*(2..3)).mmatch a,2
|
1340
|
+
assert x.nil?
|
1341
|
+
|
1342
|
+
x=(:foo.reg*(1..2)*(2..3)).mmatch a,3
|
1343
|
+
assert x.nil?
|
1344
|
+
|
1345
|
+
assert((not (:foo.reg*(1..2)*(2..3)*(2..3)).mmatch [:foo]*3,0 ))
|
1346
|
+
end
|
1347
|
+
|
1348
|
+
|
1349
|
+
|
1350
|
+
|
1351
|
+
assert_eee Reg[5.reg+2+2], [5]*4
|
1352
|
+
assert_eee Reg[5.reg*(1..2)*(1..2)*(1..2)], [5]
|
1353
|
+
assert_eee Reg[5.reg*(1..2)*(1..2)*(2..3)], [5]*2
|
1354
|
+
assert_eee Reg[5.reg*(1..2)*(2..3)*(2..3)], [5]*4
|
1355
|
+
assert_eee Reg[(5.reg+1)*(2..3)*(2..3)], [5]*4
|
1356
|
+
assert_eee Reg[(5.reg+1+2)*(2..3)], [5]*4
|
1357
|
+
assert_eee Reg[5.reg+1+2+2], [5]*4
|
1358
|
+
assert_eee Reg[OB+3+2], [:f]*6
|
1359
|
+
|
1360
|
+
#stack overflow
|
1361
|
+
#aaa_patho=-[/^a/]|-[/^.a/, OB]|-[/^..a/, OB*2]
|
1362
|
+
#assert_ene( +[aaa_patho], ["aaa"]*200 )
|
1363
|
+
#assert_eee( +[aaa_patho+0], ["aaa"]*200 )
|
1364
|
+
|
1365
|
+
|
1366
|
+
|
1367
|
+
|
1368
|
+
assert_eee Reg[(-[-[:p]*(1..2)])], [:p]
|
1369
|
+
assert_eee Reg[(-[-[:p]*(1..2)])], [:p,:p]
|
1370
|
+
assert_ene Reg[(-[-[:p]*(1..2)])], [:p,:q]
|
1371
|
+
assert_ene Reg[(-[-[:p]*(1..2)])], [:q]
|
1372
|
+
assert_ene Reg[(-[-[:p]*(1..2)])], []
|
1373
|
+
assert_ene Reg[(-[-[:p]*(1..2)])], [:p,:p, :p]
|
1374
|
+
|
1375
|
+
|
1376
|
+
assert_eee Reg[OB+1], [:foo,:foo]
|
1377
|
+
assert_eee Reg[OB+1+1], [:foo,:foo]
|
1378
|
+
assert_eee Reg[OB+1+1+1], [:foo,:foo]
|
1379
|
+
assert_eee Reg[OB+1+1+1+1], [:foo,:foo]
|
1380
|
+
|
1381
|
+
assert_ene Reg[OB+2+3], [:f]*5
|
1382
|
+
assert_ene Reg[OB+2+2+1], [:f]*3
|
1383
|
+
end
|
1384
|
+
|
1385
|
+
def test_recursive_vector_pattern
|
1386
|
+
lenheadalts=-[0]|-[1,OB]|-[2,OB*2]|-[3,OB*3]|-[4,OB*4]
|
1387
|
+
lenheadlist=lenheadalts+1
|
1388
|
+
|
1389
|
+
lenheaddata=[0,0,0,1,:foo,4,:foo,:bar,:baz,:zork,3,:k,77,88]
|
1390
|
+
lenheaddataj=lenheaddata+[:j]
|
1391
|
+
|
1392
|
+
lentailalts=-[OB,-1]|-[OB*2,-2]|-[OB*3,-3]|-[OB*4,-4]
|
1393
|
+
lentaildata=lenheaddata.reverse.map {|x| Integer===x ? -x : x }
|
1394
|
+
infixalts=-[OB,"infix1",OB]|-[OB*2,'infix2',OB*2]|
|
1395
|
+
-[OB*3,'infix3',OB*3]|-[OB*4,'infix4',OB*4]
|
1396
|
+
|
1397
|
+
|
1398
|
+
qq=-[:q, ~(:q.reg)+0, :q]
|
1399
|
+
_QQ=-[:Q, ( ~/^[Q\\]$/.sym | -[:'\\',OB] )+0, :Q]
|
1400
|
+
|
1401
|
+
be=begin_end_pattern :+, 0
|
1402
|
+
|
1403
|
+
lh_or_qq=lenheadalts|qq|_QQ
|
1404
|
+
lhqqbe=lh_or_qq|be
|
1405
|
+
|
1406
|
+
assert_eee(+[be], [
|
1407
|
+
:begin, :SubseqMatchSet, :IndexError, :termsig, :"\\", :ll,
|
1408
|
+
:end]
|
1409
|
+
)
|
1410
|
+
assert_eee(+[be+0], [
|
1411
|
+
:begin, :SubseqMatchSet, :IndexError, :termsig, :"\\", :begin,
|
1412
|
+
:end]
|
1413
|
+
)
|
1414
|
+
assert_eee(+[be+0], [
|
1415
|
+
:begin, :SubseqMatchSet, :IndexError, :termsig, :"\\", :end,
|
1416
|
+
:end]
|
1417
|
+
)
|
1418
|
+
assert_eee(+[be+0], [
|
1419
|
+
:begin, :SubseqMatchSet, :IndexError, :termsig, :"\\",
|
1420
|
+
:begin, :right, :"\\",
|
1421
|
+
:begin, :f, :call, :safe_level, :"\\",
|
1422
|
+
:begin, :undefine_finalizer, :test_anonymous, :quote,
|
1423
|
+
:end]
|
1424
|
+
)
|
1425
|
+
assert_eee(+[lhqqbe+0], [
|
1426
|
+
:begin, :SubseqMatchSet, :IndexError, :termsig, :"\\",
|
1427
|
+
:begin, :right, :"\\",
|
1428
|
+
:begin, :f, :call, :safe_level, :"\\",
|
1429
|
+
:begin, :undefine_finalizer, :test_anonymous, :quote,
|
1430
|
+
:end]
|
1431
|
+
)
|
1432
|
+
|
1433
|
+
assert_eee Reg[be+0], [
|
1434
|
+
:begin, :popen, :"chomp!", :-@, :end, #:q, :q,
|
1435
|
+
:begin, :begin, :end, :end,
|
1436
|
+
:begin, :MINOR_VERSION, :"public_method_defined?", :"\\", :begin, :umask,
|
1437
|
+
:debug_print_help, :geteuid, :end,
|
1438
|
+
# :q, :public_methods, :option_name, :MUTEX, :q,
|
1439
|
+
:begin, :verbose=, :binding, :symlink, :lambda,
|
1440
|
+
:emacs_editing_mode, :"dst?", :end, #0,
|
1441
|
+
:begin, :test_to_s_with_iv, :"\\", :begin, :glob, :each_with_index,
|
1442
|
+
:initialize_copy, :begin, :$PROGRAM_NAME, :end,
|
1443
|
+
:ELIBACC, :setruid, :"success?", :end,
|
1444
|
+
:begin, :__size__, :width, :"\\", :begin, :$-a, :"sort!", :waitpid, :end,
|
1445
|
+
:begin, :Stat, :WadlerExample, :chr, :end,
|
1446
|
+
:begin, :+, :disable, :abstract,
|
1447
|
+
:begin, :__size__, :"symlink?", :"dst?", :end, :ljust, :end,
|
1448
|
+
:begin, :debug_method_info, :matchary, :"\\", :begin, :ftype,
|
1449
|
+
:thread_list_all, :eof, :begin, :abs, :GroupQueue, :end,
|
1450
|
+
:"slice!", :ordering=, :end,
|
1451
|
+
# :Q, :"\\", :Q, :ELIBMAX, :GetoptLong, :nlink, :Q,
|
1452
|
+
:begin, :Fixnum, :waitall, :"enclosed?", :"\\", :begin, :deep_copy,
|
1453
|
+
:getpgid, :strftime, :end,
|
1454
|
+
# :Q, :close_obj, :Q,
|
1455
|
+
# 3, :basic_quote_characters=, :rmdir, :"writable_real?",
|
1456
|
+
:begin, :test_hello_11_12, :utc_offset, :freeze,
|
1457
|
+
:begin, :kcode, :egid=, :ARGF, :end,
|
1458
|
+
:setuid, :lock, :gmtoff, :end,
|
1459
|
+
:begin, :$FILENAME, :test_tree_alt_20_49,
|
1460
|
+
:begin, :LOCK_SH, :EL3HLT, :end, :end,
|
1461
|
+
# :Q, :"\\", :Q, :ceil, :remainder, :group_sub, :Q, 0
|
1462
|
+
]
|
1463
|
+
assert_eee Reg[lhqqbe+0], [
|
1464
|
+
:begin, :popen, :"chomp!", :-@, :end, :q, :q,
|
1465
|
+
:begin, :begin, :end, :end,
|
1466
|
+
:begin, :MINOR_VERSION, :"public_method_defined?", :"\\", :begin, :umask,
|
1467
|
+
:debug_print_help, :geteuid, :end,
|
1468
|
+
:q, :public_methods, :option_name, :MUTEX, :q,
|
1469
|
+
:begin, :verbose=, :binding, :symlink, :lambda,
|
1470
|
+
:emacs_editing_mode, :"dst?", :end, 0,
|
1471
|
+
:begin, :test_to_s_with_iv, :"\\", :begin, :glob, :each_with_index,
|
1472
|
+
:initialize_copy, :begin, :$PROGRAM_NAME, :end,
|
1473
|
+
:ELIBACC, :setruid, :"success?", :end,
|
1474
|
+
:begin, :__size__, :width, :"\\", :begin, :$-a, :"sort!", :waitpid, :end,
|
1475
|
+
:begin, :Stat, :WadlerExample, :chr, :end,
|
1476
|
+
:begin, :+, :disable, :abstract,
|
1477
|
+
:begin, :__size__, :"symlink?", :"dst?", :end, :ljust, :end,
|
1478
|
+
:begin, :debug_method_info, :matchary, :"\\", :begin, :ftype,
|
1479
|
+
:thread_list_all, :eof, :begin, :abs, :GroupQueue, :end,
|
1480
|
+
:"slice!", :ordering=, :end,
|
1481
|
+
:Q, :"\\", :Q, :ELIBMAX, :GetoptLong, :nlink, :Q,
|
1482
|
+
:begin, :Fixnum, :waitall, :"enclosed?", :"\\", :begin, :deep_copy,
|
1483
|
+
:getpgid, :strftime, :end,
|
1484
|
+
:Q, :close_obj, :Q,
|
1485
|
+
3, :basic_quote_characters=, :rmdir, :"writable_real?",
|
1486
|
+
:begin, :test_hello_11_12, :utc_offset, :freeze,
|
1487
|
+
:begin, :kcode, :egid=, :ARGF, :end,
|
1488
|
+
:setuid, :lock, :gmtoff, :end,
|
1489
|
+
:begin, :$FILENAME, :test_tree_alt_20_49,
|
1490
|
+
:begin, :LOCK_SH, :EL3HLT, :end, :end,
|
1491
|
+
:Q, :"\\", :Q, :ceil, :remainder, :group_sub, :Q, 0
|
1492
|
+
]
|
1493
|
+
assert_eee Reg[lhqqbe+0], [ :begin, :"\\", :rand, :end ]
|
1494
|
+
#breakpoint
|
1495
|
+
assert_eee( +[be], [:begin, :"\\", :"\\", :end])
|
1496
|
+
assert_eee( +[be], [:begin, :"\\", :begin, :end])
|
1497
|
+
assert_eee( +[be], [:begin, :"\\", :end, :end])
|
1498
|
+
assert_eee( +[be], [:begin, :log, :readline, :"\\", :begin, :lh_or_qq, :test_pretty_print_inspect, :@newline, :end])
|
1499
|
+
assert_eee( +[be], [:begin, :lock, :rindex, :begin, :sysopen, :rename, :end, :re_exchange, :on, :end])
|
1500
|
+
assert_eee( +[be], [:begin, :lock, :"\\", :"\\", :begin, :rename, :end, :on, :end])
|
1501
|
+
assert_eee( +[be], [:begin, :begin, :foo, :end, :end])
|
1502
|
+
assert_eee( +[be], makelendata(1,0b11110000000).flatten)
|
1503
|
+
assert_eee( +[be], [:begin, :end])
|
1504
|
+
assert_eee( +[be], [:begin, :foo, :end])
|
1505
|
+
assert_eee( +[be], makelendata(1,0b10000000).flatten)
|
1506
|
+
assert_eee Reg[lhqqbe+0], makelendata(1,0b11111110011).flatten
|
1507
|
+
assert_eee Reg[lhqqbe+0], makelendata(4,0b11111110011).flatten
|
1508
|
+
assert_eee Reg[lhqqbe+0], makelendata(10,0b11111110011).flatten
|
1509
|
+
assert_eee Reg[lhqqbe+0], makelendata(20,0b11111110011).flatten
|
1510
|
+
|
1511
|
+
assert_eee Reg[lenheadlist], [1, :__id__]
|
1512
|
+
assert_eee Reg[lenheadlist], [2, :p, :stat]
|
1513
|
+
assert_eee Reg[lenheadlist], [2, :p, :stat, 1, :__id__]
|
1514
|
+
assert_eee Reg[lenheadlist], [2, :p, :stat, 0, 1, :__id__, 0, 0]
|
1515
|
+
assert_eee Reg[lenheadlist], lenheaddata
|
1516
|
+
assert_ene Reg[lenheadlist], lenheaddataj
|
1517
|
+
assert_eee( +[lh_or_qq+0], lenheaddata )
|
1518
|
+
assert_eee( +[lh_or_qq+0], lenheaddata+[:q, :foo, :bar, :baz, :q] )
|
1519
|
+
|
1520
|
+
assert_eee Reg[lenheadlist], [0]
|
1521
|
+
assert_eee Reg[lenheadlist], makelendata(1,0b11).flatten
|
1522
|
+
assert_eee Reg[lenheadlist], makelendata(5,0b11).flatten
|
1523
|
+
assert_eee Reg[lenheadlist], makelendata(10,0b11).flatten
|
1524
|
+
assert_eee Reg[lenheadlist], makelendata(20,0b11).flatten
|
1525
|
+
assert_ene Reg[lenheadlist], makelendata(20,0b11).flatten+[:j]
|
1526
|
+
assert_ene Reg[lenheadlist], [:j]+makelendata(20,0b11).flatten+[:j]
|
1527
|
+
assert_ene Reg[lenheadlist], [:j]+makelendata(20,0b11).flatten
|
1528
|
+
|
1529
|
+
assert_ene Reg[lenheadlist], makelendata(20,0b11,:j).flatten
|
1530
|
+
assert_eee( +[lh_or_qq+0], makelendata(20,0b11).flatten )
|
1531
|
+
assert_eee( +[lh_or_qq+0], makelendata(20,0b1000011).flatten )
|
1532
|
+
assert_ene( +[lh_or_qq+0], makelendata(20,0b1000011).flatten+[:j] )
|
1533
|
+
assert_ene( +[lh_or_qq+0], [:j]+makelendata(20,0b1000011).flatten+[:j] )
|
1534
|
+
assert_ene( +[lh_or_qq+0], [:j]+makelendata(20,0b1000011).flatten )
|
1535
|
+
end
|
1536
|
+
if ENV['SLOW']
|
1537
|
+
def test_slow; disabled_test_slow; end
|
1538
|
+
else
|
1539
|
+
warning "slow tests disabled... run with env var SLOW=1 to enable"
|
1540
|
+
end
|
1541
|
+
def _; print '_'; $stdout.flush end
|
1542
|
+
def disabled_test_slow
|
1543
|
+
#btracing monsters
|
1544
|
+
_;assert_ene Reg[OB+1+3+2], (1..5).to_a
|
1545
|
+
0.upto(5) {|i| _;assert_ene Reg[OB+1+3+2], [:f]*i }
|
1546
|
+
6.upto(16){|i| _;assert_eee Reg[OB+1+3+2], [:f]*i }
|
1547
|
+
|
1548
|
+
_;assert_ene Reg[OB+2+3+2], [:f]*11
|
1549
|
+
_;assert_eee Reg[OB+2+3+2], [:f]*12
|
1550
|
+
_;assert_ene Reg[OB+2+3+3], [:f]*17
|
1551
|
+
_;assert_eee Reg[OB+2+3+3], [:f]*18
|
1552
|
+
_;assert_ene Reg[OB+3+3+3], [:f]*26
|
1553
|
+
_;assert_eee Reg[OB+3+3+3], [:f]*27
|
1554
|
+
# assert_ene Reg[OB+4+4+4], [:f]*63 #insane
|
1555
|
+
# assert_eee Reg[OB+4+4+4], [:f]*64 #insane
|
1556
|
+
_;assert_ene Reg[OB+2+2+2+2], [:f]*15
|
1557
|
+
_;assert_eee Reg[OB+2+2+2+2], [:f]*16
|
1558
|
+
# assert_ene Reg[OB+2+2+2+2+2+2+2+2], [:foo]*255 #insane
|
1559
|
+
# assert_eee Reg[OB+2+2+2+2+2+2+2+2], [:foo]*256 #insane
|
1560
|
+
|
1561
|
+
|
1562
|
+
#assert_eee Reg[OB+10+10], [:f]*100 #waaaay too slow
|
1563
|
+
_;assert_eee Reg[OB+5+5], [:f]*25
|
1564
|
+
_;assert_ene Reg[OB+5+5], [:f]*24
|
1565
|
+
_;assert_eee Reg[OB+6+6], [:f]*36
|
1566
|
+
_;assert_ene Reg[OB+6+6], [:f]*35
|
1567
|
+
_;assert_eee Reg[OB+7+7], [:f]*49 #prolly excessive
|
1568
|
+
_;assert_ene Reg[OB+7+7], [:f]*48 #prolly excessive
|
1569
|
+
|
1570
|
+
_;assert_ene Reg[OB+1+2+2+2], [:f]*7
|
1571
|
+
_;assert_eee Reg[OB+1+2+2+2], [:f]*8
|
1572
|
+
_;assert_ene Reg[OB+1+1+2+2+2], [:f]*7
|
1573
|
+
_;assert_eee Reg[OB+1+1+2+2+2], [:f]*8
|
1574
|
+
_;assert_ene Reg[OB+1+1+1+2+2+2], [:f]*7
|
1575
|
+
_;assert_eee Reg[OB+1+1+1+2+2+2], [:f]*8
|
1576
|
+
|
1577
|
+
_;assert_ene Reg[OB+1+1+1+1+2+2+2], [:f]*7
|
1578
|
+
_;assert_eee Reg[OB+1+1+1+1+2+2+2], [:f]*8
|
1579
|
+
|
1580
|
+
r=2..3
|
1581
|
+
_;assert_ene Reg[OB*(1..2)*r*r*r], [:f]*7
|
1582
|
+
_;assert_eee Reg[OB*(1..2)*r*r*r], [:f]*8
|
1583
|
+
end
|
1584
|
+
|
1585
|
+
def test_reg2
|
1586
|
+
assert_ene Reg[:foo,OB+1], [:foo]
|
1587
|
+
assert_ene Reg[OB+1,:foo], [:foo]
|
1588
|
+
assert_eee Reg[OB+1], [:foo]
|
1589
|
+
|
1590
|
+
|
1591
|
+
assert_eee Reg[OB+1+1+1+1+1+1+1+1+1+1+1+1+1+1], [:foo]
|
1592
|
+
|
1593
|
+
assert_ene Reg[OB+1+1+1+1], []
|
1594
|
+
assert_eee Reg[OB+1+1+1+1], [:foo,:foo]
|
1595
|
+
assert_ene Reg[OB+2], [:foo]
|
1596
|
+
assert_ene Reg[OB+2+2], [:foo]*3
|
1597
|
+
assert_ene Reg[OB+2+2+1], [:foo]*3
|
1598
|
+
assert_ene Reg[OB+2+1+2], [:foo]*3
|
1599
|
+
|
1600
|
+
|
1601
|
+
assert_eee Reg[-[1,2]|3], [1,2]
|
1602
|
+
assert_eee Reg[-[1,2]|3], [3]
|
1603
|
+
assert_ene Reg[-[1,2]|3], [4]
|
1604
|
+
assert_ene Reg[-[1,2]|3], [2]
|
1605
|
+
assert_ene Reg[-[1,2]|3], [1,3]
|
1606
|
+
|
1607
|
+
assert_eee Reg[(-[0]|-[1,OB]|-[2,OB*2])*1], [2, :p, :stat]
|
1608
|
+
assert_eee Reg[(-[2,OB*2])-1], [2, :p, :stat]
|
1609
|
+
assert_eee Reg[(-[OB])*(1..2)], [1, :p]
|
1610
|
+
|
1611
|
+
assert_eee Reg[(-[-[:p]*(1..2)])], [:p]
|
1612
|
+
assert_eee Reg[(-[-[:p]])*(1..2)], [:p]
|
1613
|
+
assert_eee Reg[(-[-[OB]])*(1..2)], [:p]
|
1614
|
+
assert_eee Reg[(-[OB*1])*(1..2)], [:p]
|
1615
|
+
assert_eee Reg[(-[1,OB*1])*(1..2)], [1, :p]
|
1616
|
+
assert_eee Reg[(-[2,OB*2])*(1..2)], [2, :p, :stat]
|
1617
|
+
assert_eee Reg[(-[0]|-[1,OB]|-[2,OB*2])*(1..2)], [2, :p, :stat]
|
1618
|
+
assert_eee Reg[(-[0]|-[1,OB]|-[2,OB*2])+1], [2, :p, :stat]
|
1619
|
+
end
|
1620
|
+
|
1621
|
+
def test_btracing_monsters
|
1622
|
+
#btracing monsters:
|
1623
|
+
assert_eee Reg[OB*2], [:foo]*2
|
1624
|
+
assert_eee Reg[OB*2*2], [:foo]*4
|
1625
|
+
assert_eee Reg[OB*2*2*2*2], [:foo]*16
|
1626
|
+
assert_eee Reg[OB*2*2*2*2*2*2*2*2], [:foo]*256
|
1627
|
+
assert_eee Reg[OB*2*2*2*2*2*2*2*2*2], [:foo]*512
|
1628
|
+
assert_eee Reg[OB-2-2-2-2-2], [:foo]*32
|
1629
|
+
assert_eee Reg[OB-2-2-2-2-2-2], [:foo]*64
|
1630
|
+
assert_eee Reg[OB-2-2-2-2-2-2-2], [:foo]*128
|
1631
|
+
assert_eee Reg[OB-2-2-2-2-2-2-2-2], [:foo]*256
|
1632
|
+
end
|
1633
|
+
|
1634
|
+
def test_reg3
|
1635
|
+
t=(1..2)
|
1636
|
+
assert_eee Reg[OB*t*t*t*t], [:foo]*16
|
1637
|
+
assert_ene Reg[OB*t*t*t*t], [:foo]*17
|
1638
|
+
assert_eee Reg[5.reg*t], [5]
|
1639
|
+
assert_eee Reg[5.reg*t*1], [5]
|
1640
|
+
assert_eee Reg[5.reg*1*t], [5]
|
1641
|
+
assert_eee Reg[5.reg*t*t], [5]
|
1642
|
+
assert_eee Reg[5.reg*t*t*t], [5]
|
1643
|
+
assert_eee Reg[5.reg*t*t*t*t], [5]
|
1644
|
+
assert_eee Reg[5.reg+1+1+1], [5]
|
1645
|
+
assert_eee Reg[5.reg+1+1+1+1], [5]
|
1646
|
+
assert_eee Reg[OB+1+1+1], [:foo]
|
1647
|
+
assert_eee Reg[OB+1+1+1+1], [:foo]
|
1648
|
+
assert_eee Reg[OB+2], [:foo]*2
|
1649
|
+
assert_eee Reg[OB+2+2], [:foo]*4
|
1650
|
+
|
1651
|
+
|
1652
|
+
|
1653
|
+
|
1654
|
+
|
1655
|
+
assert_ene Reg[OB-0], [1]
|
1656
|
+
assert_eee Reg[OB+0], [1]
|
1657
|
+
assert_eee Reg[OB-1], [1]
|
1658
|
+
assert_eee Reg[OB+1], [1]
|
1659
|
+
assert_eee Reg[OB-2], [1,2]
|
1660
|
+
assert_eee Reg[OB+2], [1,2]
|
1661
|
+
|
1662
|
+
assert_eee Reg[OB], [1]
|
1663
|
+
assert_eee Reg[OB*1], [1]
|
1664
|
+
assert_eee Reg[OB*2], [1,2]
|
1665
|
+
assert_eee Reg[OB*4], [1,2,3,4]
|
1666
|
+
|
1667
|
+
abcreg=Reg[OBS,:a,:b,:c,OBS]
|
1668
|
+
assert_eee abcreg, [:a,:b,:c,7,8,9]
|
1669
|
+
assert_eee abcreg, [1,2,3,:a,:b,:c,7,8,9]
|
1670
|
+
|
1671
|
+
assert_eee abcreg, [1,2,3,:a,:b,:c]
|
1672
|
+
assert_eee abcreg, [:a,:b,:c]
|
1673
|
+
|
1674
|
+
assert_ene abcreg, [1,2,3,:a,:b,:d]
|
1675
|
+
assert_ene abcreg, [1,2,3,:a,:d,:c]
|
1676
|
+
assert_ene abcreg, [1,2,3,:d,:b,:c]
|
1677
|
+
|
1678
|
+
assert_ene abcreg, [1,2,3]
|
1679
|
+
assert_ene abcreg, [1,2,3,:a]
|
1680
|
+
assert_ene abcreg, [1,2,3,:a,:b]
|
1681
|
+
|
1682
|
+
assert_eee Reg[:a, OB+0, :b, :b, :b, :b, :b], [:a, 1,1,1,1,1,1, :b, :b, :b, :b, :b]
|
1683
|
+
assert_eee Reg[:a, OB+0, :b, :b, :b, :b, :b], [:a, 1, :b, :b, :b, :b, :b]
|
1684
|
+
assert_eee Reg[:a, OB+0, :b, :b, :b, :b, :b], [:a, :b, :b, :b, :b, :b]
|
1685
|
+
|
1686
|
+
assert_eee Reg[:a, OB+1, :b, :b, :b, :b, :b], [:a, 1,1,1,1,1,1, :b, :b, :b, :b, :b]
|
1687
|
+
assert_eee Reg[:a, OB+1, :b, :b, :b, :b, :b], [:a, 1, :b, :b, :b, :b, :b]
|
1688
|
+
assert_ene Reg[:a, OB+1, :b, :b, :b, :b, :b], [:a, :b, :b, :b, :b, :b]
|
1689
|
+
|
1690
|
+
assert_ene Reg[:a, OB-0, :b, :b, :b, :b, :b], [:a, 1,1,1,1,1,1, :b, :b, :b, :b, :b]
|
1691
|
+
assert_ene Reg[:a, OB-0, :b, :b, :b, :b, :b], [:a, 1, :b, :b, :b, :b, :b]
|
1692
|
+
assert_eee Reg[:a, OB-0, :b, :b, :b, :b, :b], [:a, :b, :b, :b, :b, :b]
|
1693
|
+
|
1694
|
+
assert_eee Reg[-[OB*2]], [99, 99] #di not right in top level
|
1695
|
+
assert_eee Reg[-[-[-[-[-[OB*2]]]]]], [99, 99] #di not right in top level?
|
1696
|
+
assert_eee Reg[-[-[-[-[-[OB*1]]]]]], [99] #di not right in top level?
|
1697
|
+
#RR[RR[[RR[RR[RR[RR[99,99]]]]]]]
|
1698
|
+
assert_eee Reg[OB*1], [:foo]
|
1699
|
+
assert_eee Reg[-[OB]], [88]
|
1700
|
+
assert_ene Reg[-[0]], [88]
|
1701
|
+
assert_eee Reg[-[0]], [0]
|
1702
|
+
assert_eee Reg[-[OB*1]], [:foo]
|
1703
|
+
assert_eee Reg[OB*1*1], [:foo]
|
1704
|
+
assert_eee Reg[OB*1*1*1*1*1*1*1*1*1*1*1*1*1*1], [:foo]
|
1705
|
+
assert_eee Reg[OB-1-1-1-1-1-1-1-1-1-1-1-1-1-1], [:foo]
|
1706
|
+
assert_eee Reg[-[2,OB*2]], [2, 99, 99]
|
1707
|
+
|
1708
|
+
# assert_eee Reg::Multiple, -[0]|-[1,2]
|
1709
|
+
# assert( (-[0]|-[1,2]).respond_to?( :mmatch))
|
1710
|
+
|
1711
|
+
lenheaddata=[0,0,0,1,:foo,4,:foo,:bar,:baz,:zork,3,:k,77,88]
|
1712
|
+
lenheaddataj=lenheaddata+[:j]
|
1713
|
+
|
1714
|
+
assert_eee Reg[-[0],OBS], lenheaddataj
|
1715
|
+
assert_eee Reg[-[0]|-[1,OB],OBS], lenheaddataj
|
1716
|
+
assert_eee Reg[-[0]|-[1,OB]|-[2,OB*2],OBS], lenheaddataj
|
1717
|
+
assert_eee Reg[-[0]|-[1,OB]|-[2,OB*2]|-[3,OB*3],OBS], lenheaddataj
|
1718
|
+
assert_eee Reg[-[0]|-[1,OB]|-[2,OB*2]|-[3,OB*3]|-[4,OB*4],OBS], lenheaddataj
|
1719
|
+
|
1720
|
+
|
1721
|
+
|
1722
|
+
|
1723
|
+
|
1724
|
+
|
1725
|
+
|
1726
|
+
|
1727
|
+
#Matches array containing exactly 2 elements; 1st is another array, 2nd is
|
1728
|
+
#integer:
|
1729
|
+
assert_eee( +[Array,Integer], [["ee"],555])
|
1730
|
+
|
1731
|
+
#Like above, but 1st is array of arrays of symbol
|
1732
|
+
assert_eee( +[+[+[Symbol+0]+0],Integer], [[[:foo,:bar],[:baz,:bof]], 0])
|
1733
|
+
|
1734
|
+
#Matches array of at least 3 consecutive symbols and nothing else:
|
1735
|
+
assert_ene( +[Symbol+3], [:hop]*2)
|
1736
|
+
assert_eee( +[Symbol+3], [:hop]*3)
|
1737
|
+
assert_eee( +[Symbol+3], [:hop]*4)
|
1738
|
+
|
1739
|
+
#Matches array with at least 3 (consecutive) symbols in it somewhere:
|
1740
|
+
assert_eee( +[OBS, Symbol+3, OBS], [Module, nil, 1, "o", :g, [66,77], {888=>999}, :a, :b, :c])
|
1741
|
+
assert_eee( +[OBS, Symbol+3, OBS], [Module, nil, 1, :a, :b, :c, "o", :g, [66,77], {888=>999}])
|
1742
|
+
assert_ene( +[OBS, Symbol+3, OBS], [Module, nil, 1, :a, :b, "o", :g, [66,77], {888=>999}])
|
1743
|
+
assert_eee( +[OBS, Symbol+3, OBS], [:a, :b, :c, Module, nil, 1, "o", :g, [66,77], {888=>999}])
|
1744
|
+
|
1745
|
+
#Matches array of at most 6 strings starting with 'g'
|
1746
|
+
assert_eee( +[/^g/-6], [])
|
1747
|
+
assert_eee( +[/^g/-6], ["gh"])
|
1748
|
+
assert_eee( +[/^g/-6], ["gh","gg"])
|
1749
|
+
assert_eee( +[/^g/-6], ["gh","gg", "gf"])
|
1750
|
+
assert_eee( +[/^g/-6], ["gh","gg", "gf", "ge"])
|
1751
|
+
assert_eee( +[/^g/-6], ["gh","gg", "gf", "ge","gd"])
|
1752
|
+
assert_eee( +[/^g/-6], ["gh","gg", "gf", "ge","gd","gc"])
|
1753
|
+
assert_ene( +[/^g/-6], ["gh","gg", "gf", "ge","gd","gc","gd"])
|
1754
|
+
|
1755
|
+
#Matches array of between 5 and 9 hashes containing a key :k pointing to
|
1756
|
+
#something non-nil:
|
1757
|
+
h={:k=>true}
|
1758
|
+
assert_eee( +h, h)
|
1759
|
+
assert_eee( +{:k=>OB}, h)
|
1760
|
+
assert_eee( +{:k=>~nil.reg}, h)
|
1761
|
+
assert_ene( +[ +{:k=>~nil.reg}*(5..9) ], [h,h,h,h])
|
1762
|
+
assert_eee( +[ +{:k=>~nil.reg}*(5..9) ], [h,h,h,h,h])
|
1763
|
+
assert_eee( +[ +{:k=>~nil.reg}*(5..9) ], [h,h,h,h,h,h])
|
1764
|
+
assert_eee( +[ +{:k=>~nil.reg}*(5..9) ], [h,h,h,h,h,h,h])
|
1765
|
+
assert_eee( +[ +{:k=>~nil.reg}*(5..9) ], [h,h,h,h,h,h,h,h])
|
1766
|
+
assert_eee( +[ +{:k=>~nil.reg}*(5..9) ], [h,h,h,h,h,h,h,h,h])
|
1767
|
+
assert_ene( +[ +{:k=>~nil.reg}*(5..9) ], [h,h,h,h,h,h,h,h,h,h])
|
1768
|
+
|
1769
|
+
#Matches an object with Integer instance variable @k and property (ie method)
|
1770
|
+
#foobar that returns a string with 'baz' somewhere in it:
|
1771
|
+
assert_eee( -{:@k=>Integer}, [].instance_eval{@k=5;self})
|
1772
|
+
end
|
1773
|
+
|
1774
|
+
def test_anystruct
|
1775
|
+
assert AnyStruct[:k=>5]
|
1776
|
+
assert_eee( -{:@k=>Integer}, AnyStruct[:k=>5])
|
1777
|
+
assert_eee( -{:@k=>Integer}, AnyStruct[:k=>5, :foobar=>"kla-baz"])
|
1778
|
+
assert_eee( -{:@k=>Integer, :foobar=>/baz/}, AnyStruct[:k=>5, :foobar=>"kla-baz"])
|
1779
|
+
end
|
1780
|
+
|
1781
|
+
|
1782
|
+
def test_matcher_more
|
1783
|
+
#Matches array of 6 hashes with 6 as a value of every key, followed by
|
1784
|
+
#18 objects with an attribute @s which is a String:
|
1785
|
+
check_matcher( +[ +{OB=>6}*6 ], :matches=>[[ {:a=>6},{:a=>6,:b=>6},{:a=>6,:b=>6,:c=>6},{:hodd=>6},
|
1786
|
+
{:tuber=>6.0}, {:xxx=>6, :e=>6} ]])
|
1787
|
+
check_matcher( +[ +{OB=>6}*6, -{:@s=>String}*18 ],
|
1788
|
+
:matches=>[ [ {:a=>6},{:a=>6,:b=>6},{:a=>6,:b=>6,:c=>6},{:hodd=>6},
|
1789
|
+
{:tuber=>6.0}, {:xxx=>6, :e=>6}, *[AnyStruct[:s=>"66"]]*18 ]
|
1790
|
+
],
|
1791
|
+
:unmatches=>[
|
1792
|
+
[ {:a=>6},{:a=>6,:b=>6},{:a=>6,:b=>6,:c=>6},{:hodd=>6},
|
1793
|
+
{:tuber=>6.0}, {:xxx=>6, :e=>6}, *[AnyStruct[:s=>"66"]]*17 ],
|
1794
|
+
[ {:a=>6},{:a=>6,:b=>6},{:a=>6,:b=>6,:c=>6},{:hodd=>6},
|
1795
|
+
{:tuber=>6.0}, {:xxx=>6, :e=>6}, *[AnyStruct[:s=>"66"]]*19 ],
|
1796
|
+
[ {:a=>6},{:a=>5,:b=>6},{:a=>4,:b=>5,:c=>6},{:hodd=>6},
|
1797
|
+
{:tuber=>6.0}, {:xxx=>"t", :e=>6}, *[AnyStruct[:s=>"66"]]*18 ]
|
1798
|
+
]
|
1799
|
+
)
|
1800
|
+
|
1801
|
+
check_matcher( +[/fo+/**8, /ba+r/**9],
|
1802
|
+
:matches=> [{"foobar"=>8, "bar"=>9},{"foo"=>8,"bar"=>9}],
|
1803
|
+
:unmatches=> {"foobar"=>9, "bar"=>9})
|
1804
|
+
|
1805
|
+
|
1806
|
+
|
1807
|
+
print "\n"
|
1808
|
+
end
|
1809
|
+
|
1810
|
+
def check_variables(data,*rest)
|
1811
|
+
vals_list=rest.pop
|
1812
|
+
vars=("a"...(?a+rest.size).chr).to_a
|
1813
|
+
pat=[]
|
1814
|
+
rest.each_index{|i| pat<< ((rest[i]+1)%vars[i].to_sym) }
|
1815
|
+
regpat=+pat
|
1816
|
+
assert x=regpat.match( data )
|
1817
|
+
assert regpat.match([]).nil? unless rest.empty?
|
1818
|
+
vals_list.each_index{|i|
|
1819
|
+
assert_equal [vals_list[i]] , x[vars[i]]
|
1820
|
+
assert_equal [vals_list[i]] , x.send(vars[i])
|
1821
|
+
}
|
1822
|
+
regpat=+[-[*pat[0..1]],*pat[2..-1]]
|
1823
|
+
assert x=regpat.match( data)
|
1824
|
+
assert regpat.match([]).nil? unless rest.empty?
|
1825
|
+
vals_list.each_index{|i|
|
1826
|
+
assert_equal [vals_list[i]] , x[vars[i]]
|
1827
|
+
assert_equal [vals_list[i]] , x.send(vars[i])
|
1828
|
+
}
|
1829
|
+
|
1830
|
+
#this way might make warnings...
|
1831
|
+
pat=[]
|
1832
|
+
rest.each_index{|i| pat<< (rest[i]%vars[i].to_sym)+1 }
|
1833
|
+
regpat=+pat
|
1834
|
+
assert x=regpat.match( data)
|
1835
|
+
assert regpat.match([]).nil? unless rest.empty?
|
1836
|
+
vals_list.each_index{|i|
|
1837
|
+
assert_equal vals_list[i] , x[vars[i]]
|
1838
|
+
assert_equal vals_list[i] , x.send( vars[i])
|
1839
|
+
}
|
1840
|
+
regpat=+[-[*pat[0..1]],*pat[2..-1]]
|
1841
|
+
assert x=regpat.match( data)
|
1842
|
+
assert regpat.match([]).nil? unless rest.empty?
|
1843
|
+
vals_list.each_index{|i|
|
1844
|
+
assert_equal vals_list[i] , x[vars[i]]
|
1845
|
+
assert_equal vals_list[i] , x.send( vars[i])
|
1846
|
+
}
|
1847
|
+
end
|
1848
|
+
|
1849
|
+
def test_var_bindings
|
1850
|
+
check_variables([1,2,3],OB,OB,OB,[1,2,3])
|
1851
|
+
check_variables([1,2,3],OB,OB,OB-1,[1,2,3])
|
1852
|
+
check_variables([1,2],OB,OB,OB-1,[1,2,nil])
|
1853
|
+
check_variables([1,2,3],OB,OB+1,OB,[1,2,3])
|
1854
|
+
end
|
1855
|
+
|
1856
|
+
def test_logic
|
1857
|
+
assert_eee( /s/^/t/,'siren')
|
1858
|
+
assert_eee( /s/^/t/,'tire')
|
1859
|
+
assert_ene( /s/^/t/,'street')
|
1860
|
+
assert_ene( /s/^/t/,'and')
|
1861
|
+
|
1862
|
+
assert_ene( /s/^/t/^/r/,'siren')
|
1863
|
+
assert_eee( /s/^/t/^/r/,'sigh')
|
1864
|
+
assert_ene( /s/^/t/^/r/,'tire')
|
1865
|
+
assert_eee( /s/^/t/^/r/,'tie')
|
1866
|
+
assert_eee( /s/^/t/^/r/,'rye')
|
1867
|
+
assert_ene( /s/^/t/^/r/,'stoop')
|
1868
|
+
assert_ene( /s/^/t/^/r/,'street')
|
1869
|
+
assert_ene( /s/^/t/^/r/,'and')
|
1870
|
+
|
1871
|
+
assert_ene( +[OBS, -[/s/]^-[/t/,/r/]^-[/i/,/n/,/g/], OBS],
|
1872
|
+
[1,2,3, "a","b","c", 4,5,6] )
|
1873
|
+
assert_eee( +[OBS, -[/s/]^-[/t/,/r/]^-[/i/,/n/,/g/], OBS],
|
1874
|
+
[1,2,3, "soup", 4,5,6] )
|
1875
|
+
assert_eee( +[OBS, -[/s/]^-[/t/,/r/]^-[/i/,/n/,/g/], OBS],
|
1876
|
+
[1,2,3, "stoop", 4,5,6] )
|
1877
|
+
assert_eee( +[OBS, -[/s/]^-[/t/,/r/]^-[/i/,/n/,/g/], OBS],
|
1878
|
+
[1,2,3, "stoop", "rickshaw", 4,5,6] )#backtracking fools ya
|
1879
|
+
assert_eee( +[OBS.l, -[/s/]^-[/t/,/r/]^-[/i/,/n/,/g/], OBS.l],
|
1880
|
+
[1,2,3, "stoop", "rickshaw", 4,5,6] )#lazy ought to work
|
1881
|
+
assert_ene( +[-[/s/]^-[/t/,/r/]^-[/i/,/n/,/g/]], ["stoop", "rickshaw"])
|
1882
|
+
assert_ene( +[OBS, -[/s/]^-[/t/,/r/]^-[/i/,/n/,/g/], OBS],
|
1883
|
+
[1,2,3, "sit", "ran", "gee-gaw",4,5,6])
|
1884
|
+
assert_eee( +[OBS, -[/s/]^-[/t/,/r/]^-[/i/,/n/,/g/], OBS],
|
1885
|
+
[1,2,3, "turtle", "rickshaw", 4,5,6] )#works, but backtracking fools ya
|
1886
|
+
assert_eee( +[OBS, -[/s/]^-[/t/,/r/]^-[/i/,/n/,/g/], OBS],
|
1887
|
+
[1,2,3, "turtle", "rival", 4,5,6] )
|
1888
|
+
assert_eee( +[OBS, -[/s/]^-[/t/,/r/]^-[/i/,/n/,/g/], OBS],
|
1889
|
+
[1,2,3, "ink", "nap", "great, super", 4,5,6] )#works, but backtracking fools ya; it was /s/ that matched
|
1890
|
+
assert_eee( +[OBS, -[/s/]^-[/t/,/r/]^-[/i/,/n/,/g/], OBS],
|
1891
|
+
[1,2,3, "ink", "nap", "great", 4,5,6] )
|
1892
|
+
|
1893
|
+
assert_eee( /s/|/t/,'siren')
|
1894
|
+
assert_eee( /s/|/t/,'tire')
|
1895
|
+
assert_eee( /s/|/t/,'street')
|
1896
|
+
assert_ene( /s/|/t/,'and')
|
1897
|
+
|
1898
|
+
assert_eee( /s/|/t/|/r/,'siren')
|
1899
|
+
assert_eee( /s/|/t/|/r/,'sigh')
|
1900
|
+
assert_eee( /s/|/t/|/r/,'tire')
|
1901
|
+
assert_eee( /s/|/t/|/r/,'tie')
|
1902
|
+
assert_eee( /s/|/t/|/r/,'rye')
|
1903
|
+
assert_eee( /s/|/t/|/r/,'stoop')
|
1904
|
+
assert_eee( /s/|/t/|/r/,'street')
|
1905
|
+
assert_ene( /s/|/t/|/r/,'and')
|
1906
|
+
|
1907
|
+
assert_ene( +[OBS, -[/s/]|-[/t/,/r/]|-[/i/,/n/,/g/], OBS],
|
1908
|
+
[1,2,3, "a","b","c", 4,5,6] )
|
1909
|
+
assert_eee( +[OBS, -[/s/]|-[/t/,/r/]|-[/i/,/n/,/g/], OBS],
|
1910
|
+
[1,2,3, "soup", 4,5,6] )
|
1911
|
+
assert_eee( +[OBS, -[/s/]|-[/t/,/r/]|-[/i/,/n/,/g/], OBS],
|
1912
|
+
[1,2,3, "stoop", 4,5,6] )
|
1913
|
+
assert_eee( +[OBS, -[/s/]|-[/t/,/r/]|-[/i/,/n/,/g/], OBS],
|
1914
|
+
[1,2,3, "stoop", "rickshaw", 4,5,6] )
|
1915
|
+
assert_eee( +[OBS.l, -[/s/]|-[/t/,/r/]|-[/i/,/n/,/g/], OBS.l],
|
1916
|
+
[1,2,3, "stoop", "rickshaw", 4,5,6] )
|
1917
|
+
assert_eee( +[-[/s/]|-[/t/,/r/]|-[/i/,/n/,/g/]], ["stoop", "rickshaw"])
|
1918
|
+
assert_eee( +[OBS, -[/s/]|-[/t/,/r/]|-[/i/,/n/,/g/], OBS],
|
1919
|
+
[1,2,3, "sit", "ran", "gee-gaw",4,5,6])
|
1920
|
+
assert_eee( +[OBS, -[/s/]|-[/t/,/r/]|-[/i/,/n/,/g/], OBS],
|
1921
|
+
[1,2,3, "turtle", "rickshaw", 4,5,6] )
|
1922
|
+
assert_eee( +[OBS, -[/s/]|-[/t/,/r/]|-[/i/,/n/,/g/], OBS],
|
1923
|
+
[1,2,3, "turtle", "rival", 4,5,6] )
|
1924
|
+
assert_eee( +[OBS, -[/s/]|-[/t/,/r/]|-[/i/,/n/,/g/], OBS],
|
1925
|
+
[1,2,3, "ink", "nap", "great, super", 4,5,6] )#works, but backtracking fools ya; it was /s/ that matched
|
1926
|
+
assert_eee( +[OBS, -[/s/]|-[/t/,/r/]|-[/i/,/n/,/g/], OBS],
|
1927
|
+
[1,2,3, "ink", "nap", "great", 4,5,6] )
|
1928
|
+
|
1929
|
+
assert_ene( /s/&/t/,'siren')
|
1930
|
+
assert_ene( /s/&/t/,'tire')
|
1931
|
+
assert_eee( /s/&/t/,'street')
|
1932
|
+
assert_ene( /s/&/t/,'and')
|
1933
|
+
|
1934
|
+
assert_ene( /s/&/t/&/r/,'siren')
|
1935
|
+
assert_ene( /s/&/t/&/r/,'sigh')
|
1936
|
+
assert_ene( /s/&/t/&/r/,'tire')
|
1937
|
+
assert_ene( /s/&/t/&/r/,'tie')
|
1938
|
+
assert_ene( /s/&/t/&/r/,'rye')
|
1939
|
+
assert_ene( /s/&/t/&/r/,'stoop')
|
1940
|
+
assert_eee( /s/&/t/&/r/,'street')
|
1941
|
+
assert_ene( /s/&/t/&/r/,'and')
|
1942
|
+
|
1943
|
+
check_matcher( +[-[/s/]&-[/t/,/r/]&-[/i/,/n/,/g/]],
|
1944
|
+
:unmatches=>[["stoop", "rickshaw"],["sit", "ran", "hee-haw"]],
|
1945
|
+
:matches=>[["sit", "ran", "gee-gaw"],["sting", "range", "great"]]
|
1946
|
+
)
|
1947
|
+
|
1948
|
+
check_matcher(
|
1949
|
+
[ +[OBS.l, -[/s/]&-[/t/,/r/]&-[/i/,/n/,/g/], OBS.l],
|
1950
|
+
+[OBS, -[/s/]&-[/t/,/r/]&-[/i/,/n/,/g/], OBS],
|
1951
|
+
],
|
1952
|
+
:matches=>[
|
1953
|
+
["sit", "ran", "gee-gaw"],
|
1954
|
+
[1,2,3, "sit", "ran", "gee-gaw",4,5,6],
|
1955
|
+
[1,2,3, "sting", "range", "great", 4,5,6]
|
1956
|
+
],
|
1957
|
+
|
1958
|
+
:unmatches=>[
|
1959
|
+
[1,2,3, "a","b","c", 4,5,6],
|
1960
|
+
[1,2,3, "soup", 4,5,6] ,
|
1961
|
+
[1,2,3, "stoop", 4,5,6] ,
|
1962
|
+
[1,2,3, "stoop", "rickshaw", 4,5,6] ,
|
1963
|
+
[1,2,3, "turtle", "rickshaw", 4,5,6] ,
|
1964
|
+
[1,2,3, "turtle", "rival", 4,5,6] ,
|
1965
|
+
[1,2,3, "ink", "nap", "great, super", 4,5,6] ,
|
1966
|
+
[1,2,3, "ink", "nap", "great", 4,5,6]
|
1967
|
+
|
1968
|
+
]
|
1969
|
+
)
|
1970
|
+
|
1971
|
+
check_matcher( +[-[/a/,/b/,/c/] & (item_that.size < 4) ],
|
1972
|
+
:matches=>[["al", "robert", "chuck"]],
|
1973
|
+
:unmatches=>[["albert", "robert", "chuck"]]
|
1974
|
+
)
|
1975
|
+
end
|
1976
|
+
|
1977
|
+
|
1978
|
+
BOARD_MEMBERS = ['Jan', 'Julie', 'Archie', 'Stewick']
|
1979
|
+
HISTORIANS = ['Braith', 'Dewey', 'Eduardo']
|
1980
|
+
YAHOOS = ['Mitch','Christian','Dan']
|
1981
|
+
def test_toplevel_replacement
|
1982
|
+
|
1983
|
+
assert_equal "You're on the board! A congratulations is in order.", BOARD_MEMBERS.alter(
|
1984
|
+
BOARD_MEMBERS.reg>> "You're on the board! A congratulations is in order." |
|
1985
|
+
HISTORIANS.reg>> "You are busy chronicling every deft play."
|
1986
|
+
)
|
1987
|
+
|
1988
|
+
|
1989
|
+
assert_equal "You are busy chronicling every deft play.", HISTORIANS.alter(
|
1990
|
+
BOARD_MEMBERS.reg>> "You're on the board! A congratulations is in order." |
|
1991
|
+
HISTORIANS.reg>> "You are busy chronicling every deft play."
|
1992
|
+
)
|
1993
|
+
|
1994
|
+
assert_nil YAHOOS.alter(
|
1995
|
+
BOARD_MEMBERS.reg>>
|
1996
|
+
"You're on the board! A congratulations is in order." |
|
1997
|
+
HISTORIANS.reg>>
|
1998
|
+
"You are busy chronicling every deft play."
|
1999
|
+
)
|
2000
|
+
|
2001
|
+
for name in BOARD_MEMBERS|HISTORIANS
|
2002
|
+
assert_eee "You're on the board! A congratulations is in order.".reg|
|
2003
|
+
"You are busy chronicling every deft play.", name.alter(
|
2004
|
+
Set[*BOARD_MEMBERS]>> "You're on the board! A congratulations is in order." |
|
2005
|
+
Set[*HISTORIANS]>> "You are busy chronicling every deft play."
|
2006
|
+
)
|
2007
|
+
end
|
2008
|
+
|
2009
|
+
for name in YAHOOS
|
2010
|
+
assert_nil name.alter \
|
2011
|
+
Set[*BOARD_MEMBERS]>>
|
2012
|
+
"You're on the board! A congratulations is in order." |
|
2013
|
+
Set[*HISTORIANS]>>
|
2014
|
+
"You are busy chronicling every deft play."
|
2015
|
+
end
|
2016
|
+
|
2017
|
+
for name in BOARD_MEMBERS|["Arthur"]
|
2018
|
+
assert_equal "Either you are a board member... or you are Arthur." ,
|
2019
|
+
Set["Arthur",*BOARD_MEMBERS]>>
|
2020
|
+
"Either you are a board member... or you are Arthur." \
|
2021
|
+
=== name
|
2022
|
+
end
|
2023
|
+
|
2024
|
+
for name in YAHOOS|HISTORIANS
|
2025
|
+
assert_nil \
|
2026
|
+
Set["Arthur",*BOARD_MEMBERS]>>
|
2027
|
+
"Either you are a board member... or you are Arthur." \
|
2028
|
+
=== name
|
2029
|
+
end
|
2030
|
+
|
2031
|
+
for name in BOARD_MEMBERS|HISTORIANS
|
2032
|
+
assert_equal "We welcome you all to the First International
|
2033
|
+
Symposium of Board Members and Historians Alike.",
|
2034
|
+
name.alter( Set[*BOARD_MEMBERS|HISTORIANS]>>
|
2035
|
+
"We welcome you all to the First International
|
2036
|
+
Symposium of Board Members and Historians Alike."
|
2037
|
+
)
|
2038
|
+
end
|
2039
|
+
|
2040
|
+
for name in YAHOOS
|
2041
|
+
assert_nil name.alter(
|
2042
|
+
Set[*BOARD_MEMBERS|HISTORIANS]>>
|
2043
|
+
"We welcome you all to the First International
|
2044
|
+
Symposium of Board Members and Historians Alike."
|
2045
|
+
)
|
2046
|
+
end
|
2047
|
+
end
|
2048
|
+
|
2049
|
+
def test_subst
|
2050
|
+
evenwink=+[-[ OB%:even>>-[BR(:even),';)'], OB]+0, OB.-]
|
2051
|
+
#be nice to abbreviate this to:
|
2052
|
+
#+[-[ OB<<-[BR,';)'], OB ]+0, OB.-]
|
2053
|
+
|
2054
|
+
#ok, now use the pattern to test something...
|
2055
|
+
|
2056
|
+
a=(0...4).to_a
|
2057
|
+
assert_equal [0, ';)', 1, 2, ';)', 3],
|
2058
|
+
a.alter(evenwink)
|
2059
|
+
a=(0..10).to_a
|
2060
|
+
assert_equal [0, ';)', 1, 2, ';)', 3, 4, ';)', 5, 6, ';)', 7, 8, ';)', 9, 10, ';)'],
|
2061
|
+
a.alter(evenwink)
|
2062
|
+
end
|
2063
|
+
|
2064
|
+
|
2065
|
+
def assert_eee(left,right,message='assert_eee failed')
|
2066
|
+
assert(
|
2067
|
+
left===right,
|
2068
|
+
message+" left=#{left.inspect} right=#{right.inspect}"
|
2069
|
+
)
|
2070
|
+
if ENV['NO_TEST_UNIT']; print ".";$stdout.flush end
|
2071
|
+
end
|
2072
|
+
|
2073
|
+
def assert_ene(left,right,message='assert_ene failed')
|
2074
|
+
assert(
|
2075
|
+
!(left===right),
|
2076
|
+
message+" left=#{left.inspect} right=#{right.inspect}"
|
2077
|
+
)
|
2078
|
+
if ENV['NO_TEST_UNIT']; print ",";$stdout.flush end
|
2079
|
+
end
|
2080
|
+
|
2081
|
+
def check_matcher(mtrs, hash)
|
2082
|
+
Array(mtrs).each{|mtr|
|
2083
|
+
Array(hash[:matches]).each_with_index {|data,index|
|
2084
|
+
assert_eee mtr, data, "item ##{index} should match"
|
2085
|
+
}
|
2086
|
+
Array(hash[:unmatches]).each_with_index {|data,index|
|
2087
|
+
assert_ene mtr, data, "item ##{index} should not match"
|
2088
|
+
}
|
2089
|
+
}
|
2090
|
+
end
|
2091
|
+
|
2092
|
+
def check_hash_matcher (hmtr, hash)
|
2093
|
+
check_matcher(hmtr,hash)
|
2094
|
+
check_matcher(hmtr.ordered,hash)
|
2095
|
+
end
|
2096
|
+
|
2097
|
+
#end #TC_Reg metaclass?
|
2098
|
+
|
2099
|
+
class AnyStruct
|
2100
|
+
def self.[] *a; new(*a) end
|
2101
|
+
def initialize(hash=nil)
|
2102
|
+
hash.each_pair{|name,val| set_field(name, val) } if hash
|
2103
|
+
end
|
2104
|
+
|
2105
|
+
def set_field(name,val)
|
2106
|
+
eval %{class<<self; attr_accessor :#{name} end}
|
2107
|
+
self.send name.to_s+'=',val
|
2108
|
+
end
|
2109
|
+
end
|
2110
|
+
|
2111
|
+
end
|
2112
|
+
srand;seed=srand #most seeds work, but some don't, due to bugs in makelendata
|
2113
|
+
|
2114
|
+
|
2115
|
+
$verbose=true if ENV['VERBOSE']
|
2116
|
+
seed=ENV['SEED'] if ENV['SEED']
|
2117
|
+
|
2118
|
+
print "random seed is #{seed}\n"
|
2119
|
+
srand seed.to_i
|
2120
|
+
|
2121
|
+
if ENV['NO_TEST_UNIT']
|
2122
|
+
require "assert"
|
2123
|
+
t=TC_Reg.new
|
2124
|
+
t.methods.grep(/^test_/).each{|m| t.send m}
|
2125
|
+
end
|