reg 0.4.6
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.
- data/COPYING +510 -0
- data/README +404 -0
- data/assert.rb +31 -0
- data/calc.reg +73 -0
- data/forward_to.rb +49 -0
- data/item_thattest.rb +47 -0
- data/numberset.rb +200 -0
- data/parser.txt +188 -0
- data/philosophy.txt +72 -0
- data/reg.gemspec +27 -0
- data/reg.rb +33 -0
- data/regarray.rb +675 -0
- data/regarrayold.rb +477 -0
- data/regbackref.rb +126 -0
- data/regbind.rb +74 -0
- data/regcase.rb +78 -0
- data/regcore.rb +379 -0
- data/regdeferred.rb +134 -0
- data/reggrid.csv +2 -1
- data/regguide.txt +416 -0
- data/reghash.rb +318 -0
- data/regitem_that.rb +146 -0
- data/regknows.rb +63 -0
- data/reglogic.rb +195 -0
- data/reglookab.rb +94 -0
- data/regold.rb +75 -0
- data/regpath.rb +74 -0
- data/regposition.rb +68 -0
- data/regprogress.rb +1067 -0
- data/regreplace.rb +114 -0
- data/regsugar.rb +230 -0
- data/regtest.rb +1075 -0
- data/regvar.rb +76 -0
- data/trace.rb +45 -0
- metadata +83 -0
data/regreplace.rb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
=begin copyright
|
2
|
+
reg - the ruby extended grammar
|
3
|
+
Copyright (C) 2005 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
|
+
module Reg
|
20
|
+
module Reg
|
21
|
+
|
22
|
+
#turns a Reg that matches into a Reg that matches and
|
23
|
+
#replaces. (creates a Reg::Transform)
|
24
|
+
def >>(rep)
|
25
|
+
Transform.new(self,rep)
|
26
|
+
end
|
27
|
+
|
28
|
+
def later(&block)
|
29
|
+
Later.new(self,block)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Later
|
34
|
+
include Reg
|
35
|
+
|
36
|
+
def initialize(reg,block)
|
37
|
+
@reg,@block=reg,block
|
38
|
+
end
|
39
|
+
|
40
|
+
def mmatch(progress)
|
41
|
+
progress.later progress,@reg &@block
|
42
|
+
|
43
|
+
@reg.mmatch progress
|
44
|
+
end
|
45
|
+
|
46
|
+
#forward most other things to @reg (but what??)
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
=begin contexts for a Reg::Transform
|
52
|
+
an element of a Reg::Array, Reg::Subseq or Reg::Repeat
|
53
|
+
a key matcher in a Reg::Hash
|
54
|
+
a value matcher in Reg::Hash
|
55
|
+
a value matcher in Reg::Object
|
56
|
+
|
57
|
+
but a Reg::logical (Or, for instance) could be in any of above, and a Transform could be within.
|
58
|
+
=end
|
59
|
+
|
60
|
+
class Transform
|
61
|
+
include Reg
|
62
|
+
|
63
|
+
def initialize(reg,rep)
|
64
|
+
Replace===rep or Replace.make_replace rep
|
65
|
+
@reg,@rep=reg,rep
|
66
|
+
end
|
67
|
+
|
68
|
+
#this works for transforms in arrays, but what about transforms in
|
69
|
+
#Reg::Hash or Reg::Object keys? and values? what about tranforms used directly
|
70
|
+
#as matchers (ie, how does a transform respond to ===?)
|
71
|
+
def mmatch(progress)
|
72
|
+
origpos=progress.cursor.pos
|
73
|
+
result=@reg.mmatch(progress) and
|
74
|
+
progress.later {
|
75
|
+
Integer===result or fail 'need just int returned from mmatch'
|
76
|
+
progress.cursor[origpos,result]=@rep.replace_with(progress,@reg,origpos,result)
|
77
|
+
}
|
78
|
+
return result
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
=begin
|
83
|
+
varieties of Reg::Replace:
|
84
|
+
Reg::Backref and Reg::Bound
|
85
|
+
Reg::RepProc
|
86
|
+
Reg::ItemThat... maybe not, but some sort of Deferred
|
87
|
+
Reg::Fixed
|
88
|
+
Object (as if wrapped in Reg::Fixed)
|
89
|
+
Reg::Array and Reg::Subseq?
|
90
|
+
(Reg::Array inserts an array at that point. Reg::Subseq
|
91
|
+
inlines its items at that point. when used this way,
|
92
|
+
they are not matching anything, nor are the contents necessarily matchers.
|
93
|
+
they just serve as convenient container classes.)
|
94
|
+
(to actually insert a Reg::Array or anything that's special at this point,
|
95
|
+
wrap it in a Reg::Fixed.)
|
96
|
+
Array (as if Reg::Array? or Reg::Subseq?)
|
97
|
+
Reg::Transform?
|
98
|
+
=end
|
99
|
+
module Replace
|
100
|
+
huh
|
101
|
+
def self.make_replace(item)
|
102
|
+
case item
|
103
|
+
when ::Array: huh Reg::Array|Reg::Subseq
|
104
|
+
when Reg::Fixed
|
105
|
+
else huh #like Reg::Fixed
|
106
|
+
end
|
107
|
+
|
108
|
+
def replace_with
|
109
|
+
huh
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
data/regsugar.rb
ADDED
@@ -0,0 +1,230 @@
|
|
1
|
+
=begin copyright
|
2
|
+
reg - the ruby extended grammar
|
3
|
+
Copyright (C) 2005 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
|
+
|
20
|
+
=begin
|
21
|
+
this file contains the various 'convenience constructors' which might pollute the
|
22
|
+
global namespace. it's optional, but highly recommended.
|
23
|
+
|
24
|
+
if you want the tla's only, then don't call Sugar.include! (note that reg.rb calls this,
|
25
|
+
so requiring 'reg' gives you global sugar by default). To add the tla's only into
|
26
|
+
the current namespace, then load (not require) 'regsugar' in that namespace. example:
|
27
|
+
|
28
|
+
module SomeNamespace
|
29
|
+
require 'reglogic', 'regcore' #.... whatever other parts you need (see reg.rb)
|
30
|
+
load 'regsugar'
|
31
|
+
|
32
|
+
def m(...)
|
33
|
+
....
|
34
|
+
Reg[Array,Symbol,/fo+/,3..10]===somevar or raise MyError.new
|
35
|
+
....
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
=end
|
43
|
+
|
44
|
+
require 'forward_to'
|
45
|
+
require 'set'
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
#tla sugar moved into the related files plus central stuff in regcore.rb
|
50
|
+
#(maybe the regcore stuff can move here?,,, but sugar is supposed to be optional...\
|
51
|
+
|
52
|
+
|
53
|
+
#need tlas for Reg::Knows, Reg::Symbol
|
54
|
+
|
55
|
+
module ::Reg
|
56
|
+
class <<self
|
57
|
+
#Reg::Array convenience constructor. see Array#+@ for details.
|
58
|
+
def [](*args)
|
59
|
+
::Reg::Array.new(*args)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
module Sugar
|
64
|
+
module Array
|
65
|
+
def +@
|
66
|
+
::Reg::Array.new(*self)
|
67
|
+
end
|
68
|
+
def -@
|
69
|
+
::Reg::Subseq.new(*self)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
module Hash
|
74
|
+
def +@
|
75
|
+
::Reg::Hash.new(self)
|
76
|
+
end
|
77
|
+
def -@
|
78
|
+
::Reg::Object.new(self)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
module Symbol
|
83
|
+
def [](*args)
|
84
|
+
::Reg::Knows.new(self)[*args]
|
85
|
+
end
|
86
|
+
|
87
|
+
def **(other)
|
88
|
+
reg ** other
|
89
|
+
end
|
90
|
+
|
91
|
+
def -@
|
92
|
+
#item_that.respond_to?(self).reg
|
93
|
+
::Reg::Knows.new(self)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
#i'd like to take String#-@ and #** too...
|
97
|
+
|
98
|
+
|
99
|
+
module Regexp
|
100
|
+
#just like the original version of ::Regexp#~
|
101
|
+
#(except this takes an optional argument to
|
102
|
+
#compare against something else.)
|
103
|
+
def cmp(other=$_);
|
104
|
+
self =~ other
|
105
|
+
end
|
106
|
+
|
107
|
+
#~ itself has to be handled in Sugar::include!
|
108
|
+
|
109
|
+
include ::Reg::Reg
|
110
|
+
|
111
|
+
def matches_class; ::String end
|
112
|
+
|
113
|
+
#creates a Regexp that works with symbols instead of strings
|
114
|
+
def sym; ::Reg::Symbol.new(self) end
|
115
|
+
end
|
116
|
+
|
117
|
+
module Module
|
118
|
+
include ::Reg::Reg
|
119
|
+
end
|
120
|
+
|
121
|
+
module Range
|
122
|
+
include ::Reg::Reg
|
123
|
+
end
|
124
|
+
|
125
|
+
module Set
|
126
|
+
#&|^+- are already defined in Set... resolved by piracy below
|
127
|
+
include ::Reg::Reg
|
128
|
+
|
129
|
+
def ===(other)
|
130
|
+
include? other
|
131
|
+
end
|
132
|
+
|
133
|
+
#need an optimized ~ that returns a Set-like...
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
module Kernel
|
138
|
+
forward_to ::Reg, :item_that, :item_is, :regproc #last need a better name
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
class << self
|
143
|
+
|
144
|
+
@@RegexpPirate=proc{
|
145
|
+
class ::Regexp #doesn't work in Sugar::Regexp cause ~ is already defined in ::Regexp
|
146
|
+
#negates the sense of receiver regexp. returns something that matches everything
|
147
|
+
#that the original didn't, (including all non-Strings!).
|
148
|
+
undef ~
|
149
|
+
alias ~ not
|
150
|
+
end
|
151
|
+
}
|
152
|
+
|
153
|
+
@@oplookup = {
|
154
|
+
:"+" => :"op_plus",
|
155
|
+
:"-" => :"op_minus",
|
156
|
+
:"+@" => :"op_plus_self",
|
157
|
+
:"-@" => :"op_minus_self",
|
158
|
+
:"*" => :"op_mul",
|
159
|
+
:"**" => :"op_pow",
|
160
|
+
:"/" => :"op_div",
|
161
|
+
:"%" => :"op_mod",
|
162
|
+
:"<<" => :"op_lshift",
|
163
|
+
:">>" => :"op_rshift",
|
164
|
+
:"~" => :"op_tilde",
|
165
|
+
:"<=>" => :"op_cmp",
|
166
|
+
:"<" => :"op_lt",
|
167
|
+
:">" => :"op_gt",
|
168
|
+
:"==" => :"op_equal",
|
169
|
+
:"<=" => :"op_lt_eq",
|
170
|
+
:">=" => :"op_gt_eq",
|
171
|
+
:"===" => :"op_case_eq",
|
172
|
+
:"=~" => :"op_apply",
|
173
|
+
:"|" => :"op_or",
|
174
|
+
:"&" => :"op_and",
|
175
|
+
:"^" => :"op_xor",
|
176
|
+
:"[]" => :"op_fetch",
|
177
|
+
:"[]=" => :"op_store"
|
178
|
+
}
|
179
|
+
|
180
|
+
|
181
|
+
def alphabetic_name(meth)
|
182
|
+
@@oplookup[meth] or case meth
|
183
|
+
when /\?$/: :"op_#{meth[0...-1]}_p"
|
184
|
+
when /!$/: :"op_#{meth[0...-1]}_bang"
|
185
|
+
when /=$/: :"op_#{meth[0...-1]}_setter"
|
186
|
+
when /^op_/: :"op_#{meth}"
|
187
|
+
else meth
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def pirate_school(klass,meth,exception)
|
192
|
+
|
193
|
+
klass=klass.to_s; exception=exception.to_s
|
194
|
+
/^::/===klass or klass="::#{klass}"
|
195
|
+
/^::/===exception or exception="::#{exception}"
|
196
|
+
eval %{
|
197
|
+
class #{klass}
|
198
|
+
setmeth=instance_method :#{meth}
|
199
|
+
undef #{meth}
|
200
|
+
regmeth= ::Reg::Reg.instance_method :#{meth}
|
201
|
+
define_method :#{meth} do |other|
|
202
|
+
#{exception}===other and return setmeth.bind(self).call(other)
|
203
|
+
regmeth.bind(self).call(other)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
}
|
207
|
+
end
|
208
|
+
|
209
|
+
def include!
|
210
|
+
constants.each{|con| (::Object.const_get con).instance_eval "include Sugar::#{con}" }
|
211
|
+
|
212
|
+
#take over Regexp#~ to mean 'not' rather than 'compare to $_'
|
213
|
+
#eval needed to avoid "class inside of def" syntax error
|
214
|
+
instance_eval( &@@RegexpPirate) #boy, that's trick
|
215
|
+
|
216
|
+
#extend Set's version of certain operators to respect the
|
217
|
+
#reg versions as well. (The type of the rhs determines which
|
218
|
+
#version is used.)
|
219
|
+
[:+, :-, :&, :|, :^ ].each {|opname|
|
220
|
+
pirate_school ::Set,opname,::Enumerable
|
221
|
+
} if ::Reg::Reg>::Set
|
222
|
+
|
223
|
+
::Object.const_set :None,::Reg::None if defined? ::Reg::None
|
224
|
+
::Object.const_set :OB,::Reg::OB if defined? ::Reg::OB
|
225
|
+
::Object.const_set :OBS,::Reg::OBS if defined? ::Reg::OBS
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
end
|
230
|
+
end
|
data/regtest.rb
ADDED
@@ -0,0 +1,1075 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
=begin copyright
|
3
|
+
reg - the ruby extended grammar
|
4
|
+
Copyright (C) 2005 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
|
+
|
21
|
+
$Debug=true #turn on assertions
|
22
|
+
|
23
|
+
require "reg"
|
24
|
+
require "regarray"
|
25
|
+
require "reglogic"
|
26
|
+
require "reghash"
|
27
|
+
require "regvar"
|
28
|
+
require "assert"
|
29
|
+
require 'getoptlong'
|
30
|
+
|
31
|
+
#require 'test/unit' #gets in the way of my debug output
|
32
|
+
class TC_Reg #< Test::Unit::TestCase
|
33
|
+
class <<self
|
34
|
+
|
35
|
+
|
36
|
+
def randsym
|
37
|
+
as=Symbol.all_symbols
|
38
|
+
as[rand(as.size)]
|
39
|
+
end
|
40
|
+
|
41
|
+
def makelendata(num=20,mask=0b11111111111,mischief=false)
|
42
|
+
result=[]
|
43
|
+
(1..num).each do
|
44
|
+
begin type=rand(11) end until 0 != mask&(1<<type)
|
45
|
+
len=type==0 ? 0 : rand(4)
|
46
|
+
|
47
|
+
result<<case type
|
48
|
+
when 0 then [0]
|
49
|
+
when 1 then [len]+(1..len).map{randsym}
|
50
|
+
when 2 then (1..len).map{randsym}+[-len]
|
51
|
+
when 3 then (1..len).map{randsym}+["infix#{len}"]+(1..len).map{randsym}
|
52
|
+
when 4
|
53
|
+
[:Q] +
|
54
|
+
(1..len).map{randsym}.delete_if {|x|:Q==x} +
|
55
|
+
(1..rand(4)).map{randsym}.delete_if {|x|:Q==x} +
|
56
|
+
[:Q]
|
57
|
+
when 5
|
58
|
+
[:Q] +
|
59
|
+
(1..len).map{randsym}.delete_if {|x|:Q==x} +
|
60
|
+
[:'\\', :Q] +
|
61
|
+
(1..rand(4)).map{randsym}.delete_if {|x|:Q==x} +
|
62
|
+
[:Q]
|
63
|
+
|
64
|
+
when 6
|
65
|
+
[:q]+(1..len).map{randsym}.delete_if {|x|:q==x}+[:q]
|
66
|
+
|
67
|
+
when 7
|
68
|
+
[:begin]+
|
69
|
+
(1..len).map{randsym}.delete_if {|x| :begin==x or :end==x} +
|
70
|
+
(1..rand(4)).map{randsym}.delete_if {|x| :begin==x or :end==x} +
|
71
|
+
[:end]
|
72
|
+
|
73
|
+
when 8
|
74
|
+
[:begin]+
|
75
|
+
(1..len).map{randsym}.delete_if {|x| :begin==x or :end==x} +
|
76
|
+
[:'\\', 0==rand(1) ? :begin : :end] +
|
77
|
+
(1..rand(4)).map{randsym}.delete_if {|x| :begin==x or :end==x} +
|
78
|
+
[:end]
|
79
|
+
|
80
|
+
when 9
|
81
|
+
[:begin]+
|
82
|
+
(1..len).map{randsym}.delete_if {|x| :begin==x or :end==x} +
|
83
|
+
[:begin]+(1..len).map{randsym}.delete_if {|x| :begin==x or :end==x} +[:end]+
|
84
|
+
(1..rand(4)).map{randsym}.delete_if {|x| :begin==x or :end==x} +
|
85
|
+
[:end]
|
86
|
+
|
87
|
+
when 10
|
88
|
+
[:begin]+
|
89
|
+
(1..len).map{randsym}.delete_if {|x| :begin==x or :end==x} +
|
90
|
+
[:'\\', 0==rand(1)? :begin : :end] +
|
91
|
+
(1..rand(4)).map{randsym}.delete_if {|x| :begin==x or :end==x} +
|
92
|
+
[:begin]+(1..len).map{randsym}.delete_if {|x| :begin==x or :end==x} +[:end]+
|
93
|
+
(1..rand(4)).map{randsym}.delete_if {|x| :begin==x or :end==x} +
|
94
|
+
[:end]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
mischief and result.insert(rand(result.size),mischief)
|
98
|
+
return result
|
99
|
+
end
|
100
|
+
|
101
|
+
def rand_ambig
|
102
|
+
nestlevel=rand(5)+1
|
103
|
+
corepat=rand(1)==0 ? 'OB' : 'Numeric.reg'
|
104
|
+
pat=corepat
|
105
|
+
product=1
|
106
|
+
nestlevel.times {
|
107
|
+
op=case rand(3)
|
108
|
+
when 0: :*
|
109
|
+
when 1: :+
|
110
|
+
when 2: :-
|
111
|
+
end
|
112
|
+
num=rand(6)+1
|
113
|
+
product*=num
|
114
|
+
pat=["(",pat,")",op,num].to_s
|
115
|
+
product>50 and break
|
116
|
+
}
|
117
|
+
|
118
|
+
pat=eval "+[#{pat}]"
|
119
|
+
$verbose and print "testing #{pat.inspect} with #{product} items\n"
|
120
|
+
assert_eee pat,(1..product).to_a
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_rand_reg
|
124
|
+
20.times { rand_ambig }
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
def test_reg
|
129
|
+
eat_unworking=<<'#end unworking'
|
130
|
+
assert_eee +[OB-1+1]===[1] #the 0*infinity problem
|
131
|
+
assert_eee +[OB-1-2+1]===[1,2] #the 0*infinity problem
|
132
|
+
#end unworking
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
$RegTraceEnable=1 #debugging zone:
|
137
|
+
h={}
|
138
|
+
h.default=:b
|
139
|
+
test_hash_matcher Rah(:a=>:b), :matches=>h
|
140
|
+
|
141
|
+
$RegTraceEnable=false#end debug zone
|
142
|
+
|
143
|
+
assert_eee Reg[OB*2*(1..2)*2, OB*2], [:foo]*6
|
144
|
+
assert_eee Reg[(OB+2)*(1..2)+2, OB+2], [:foo]*6
|
145
|
+
|
146
|
+
assert_eee Reg[OB+6,OB+1], [:foo]*7
|
147
|
+
assert_eee Reg[OB+1,OB+1,OB+1], [:foo]*3
|
148
|
+
|
149
|
+
assert_eee( /s/^/t/,'siren')
|
150
|
+
assert_eee( /s/^/t/,'tire')
|
151
|
+
assert_ene( /s/^/t/,'street')
|
152
|
+
assert_ene( /s/^/t/,'and')
|
153
|
+
|
154
|
+
assert_ene( /s/^/t/^/r/,'siren')
|
155
|
+
assert_eee( /s/^/t/^/r/,'sigh')
|
156
|
+
assert_ene( /s/^/t/^/r/,'tire')
|
157
|
+
assert_eee( /s/^/t/^/r/,'tie')
|
158
|
+
assert_eee( /s/^/t/^/r/,'rye')
|
159
|
+
assert_ene( /s/^/t/^/r/,'stoop')
|
160
|
+
assert_ene( /s/^/t/^/r/,'street')
|
161
|
+
assert_ene( /s/^/t/^/r/,'and')
|
162
|
+
|
163
|
+
assert_ene( +[OBS, -[/s/]^-[/t/,/r/]^-[/i/,/n/,/g/], OBS],
|
164
|
+
[1,2,3, "a","b","c", 4,5,6] )
|
165
|
+
assert_eee( +[OBS, -[/s/]^-[/t/,/r/]^-[/i/,/n/,/g/], OBS],
|
166
|
+
[1,2,3, "soup", 4,5,6] )
|
167
|
+
assert_eee( +[OBS, -[/s/]^-[/t/,/r/]^-[/i/,/n/,/g/], OBS],
|
168
|
+
[1,2,3, "stoop", 4,5,6] )
|
169
|
+
assert_eee( +[OBS, -[/s/]^-[/t/,/r/]^-[/i/,/n/,/g/], OBS],
|
170
|
+
[1,2,3, "stoop", "rickshaw", 4,5,6] )#backtracking fools ya
|
171
|
+
#assert_eee( +[OBS.l, -[/s/]^-[/t/,/r/]^-[/i/,/n/,/g/], OBS.l],
|
172
|
+
# [1,2,3, "stoop", "rickshaw", 4,5,6] )#lazy ought to work
|
173
|
+
assert_ene( +[-[/s/]^-[/t/,/r/]^-[/i/,/n/,/g/]], ["stoop", "rickshaw"])
|
174
|
+
assert_ene( +[OBS, -[/s/]^-[/t/,/r/]^-[/i/,/n/,/g/], OBS],
|
175
|
+
[1,2,3, "sit", "ran", "gee-gaw",4,5,6])
|
176
|
+
assert_eee( +[OBS, -[/s/]^-[/t/,/r/]^-[/i/,/n/,/g/], OBS],
|
177
|
+
[1,2,3, "turtle", "rickshaw", 4,5,6] )#works, but backtracking fools ya
|
178
|
+
assert_eee( +[OBS, -[/s/]^-[/t/,/r/]^-[/i/,/n/,/g/], OBS],
|
179
|
+
[1,2,3, "turtle", "rival", 4,5,6] )
|
180
|
+
assert_eee( +[OBS, -[/s/]^-[/t/,/r/]^-[/i/,/n/,/g/], OBS],
|
181
|
+
[1,2,3, "ink", "nap", "great, super", 4,5,6] )#works, but backtracking fools ya; it was /s/ that matched
|
182
|
+
assert_eee( +[OBS, -[/s/]^-[/t/,/r/]^-[/i/,/n/,/g/], OBS],
|
183
|
+
[1,2,3, "ink", "nap", "great", 4,5,6] )
|
184
|
+
|
185
|
+
assert_eee( +[], [] )
|
186
|
+
assert_ene( +[], [:q] )
|
187
|
+
assert_eee( +[:q], [:q] )
|
188
|
+
assert_eee( +[-[]], [] )
|
189
|
+
assert_eee( +[-[:q]], [:q] )
|
190
|
+
assert_eee( +[-[:q]*1], [:q] )
|
191
|
+
assert_eee( +[-[:q, :q]*1], [:q,:q] )
|
192
|
+
assert_eee( +[-[:q, :q]*(0..1)], [:q,:q] )
|
193
|
+
assert_eee( +[-[:q, :q]*(0..2)], [:q,:q] )
|
194
|
+
assert_eee( +[-[:q, :q]*(0..4)], [:q,:q] )
|
195
|
+
assert_eee( +[-[:q, :q]*(0..10)], [:q,:q] )
|
196
|
+
assert_eee( +[-[:q, :q]-1], [:q,:q] )
|
197
|
+
assert_eee( +[:q.reg+1], [:q] )
|
198
|
+
assert_eee( +[/q/+1], ['q'] )
|
199
|
+
assert_eee( +[-[:q]+1], [:q] )
|
200
|
+
assert_eee( +[-[:q, :q]+1], [:q,:q] )
|
201
|
+
assert_eee( +[-[:q, :q]+0], [:q,:q] )
|
202
|
+
|
203
|
+
|
204
|
+
lenheadalts=-[0]|-[1,OB]|-[2,OB*2]|-[3,OB*3]|-[4,OB*4]
|
205
|
+
lenheadlist=lenheadalts+1
|
206
|
+
|
207
|
+
lenheaddata=[0,0,0,1,:foo,4,:foo,:bar,:baz,:zork,3,:k,77,88]
|
208
|
+
lenheaddataj=lenheaddata+[:j]
|
209
|
+
|
210
|
+
lentailalts=-[OB,-1]|-[OB*2,-2]|-[OB*3,-3]|-[OB*4,-4]
|
211
|
+
lentaildata=lenheaddata.reverse.map {|x| Integer===x ? -x : x }
|
212
|
+
infixalts=-[OB,"infix1",OB]|-[OB*2,'infix2',OB*2]|
|
213
|
+
-[OB*3,'infix3',OB*3]|-[OB*4,'infix4',OB*4]
|
214
|
+
|
215
|
+
|
216
|
+
qq=-[:q, ~(:q.reg)+0, :q]
|
217
|
+
_QQ=-[:Q, ( ~/^[Q\\]$/.sym | -[:'\\',OB] )+0, :Q]
|
218
|
+
|
219
|
+
|
220
|
+
be=-[:begin, (
|
221
|
+
~/^(begin|end|\\)$/.sym |
|
222
|
+
-[:'\\',OB] |
|
223
|
+
innerbe=Reg.const
|
224
|
+
)+0, :end]
|
225
|
+
innerbe.set! be
|
226
|
+
|
227
|
+
lh_or_qq=lenheadalts|qq|_QQ
|
228
|
+
lhqqbe=lh_or_qq|be
|
229
|
+
|
230
|
+
|
231
|
+
#most of the examples use the longer, tla form for the outermost reg....
|
232
|
+
#dunno why any more. anyway, here are the basic equivalences between the
|
233
|
+
#operator, tla, and long forms or Reg.
|
234
|
+
#operator form
|
235
|
+
assert_eee Reg::Array, +[]
|
236
|
+
assert_eee Reg::Subseq, -[]
|
237
|
+
assert_eee Reg::Hash, +{}
|
238
|
+
assert_eee Reg::Object, -{}
|
239
|
+
|
240
|
+
#tla form (square and round brackets)
|
241
|
+
assert_eee Reg::Array, Reg[]
|
242
|
+
assert_eee Reg::Subseq, Res[]
|
243
|
+
assert_eee Reg::Hash, Rah[]
|
244
|
+
assert_eee Reg::Object, Rob[]
|
245
|
+
|
246
|
+
assert_eee Reg::Array, Reg()
|
247
|
+
assert_eee Reg::Subseq, Res()
|
248
|
+
assert_eee Reg::Hash, Rah()
|
249
|
+
assert_eee Reg::Object, Rob()
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
assert_eee( +[qq*1], [:q,:q] )
|
255
|
+
assert_eee( +[qq+0], [:q,:q] )
|
256
|
+
|
257
|
+
assert_eee( +_QQ, [:Q,:Q] )
|
258
|
+
assert_eee( +[_QQ], [:Q,:Q] )
|
259
|
+
assert_eee( +[_QQ*1], [:Q,:Q] )
|
260
|
+
assert_eee( +[_QQ+0], [:Q,:Q] )
|
261
|
+
|
262
|
+
assert_eee( +[be*1], [:begin,:end] )
|
263
|
+
assert_eee( +[be+0], [:begin,:end] )
|
264
|
+
|
265
|
+
|
266
|
+
assert_eee( +[], [] )
|
267
|
+
assert_ene( +[], [1] )
|
268
|
+
assert_eee( +[-[]], [] )
|
269
|
+
assert_ene( +[-[]], [1] )
|
270
|
+
|
271
|
+
|
272
|
+
assert_ene Reg[-[:foo,:bar]-1], [:bar,:foo]
|
273
|
+
assert_ene Reg[-[:foo,:bar]-1], [:baz,:foo,:bar]
|
274
|
+
assert_ene Reg[-[:foo,:bar]-1], [:foo,:bar,:baz]
|
275
|
+
assert_eee Reg[-[:foo,:bar]-1], [:foo,:bar]
|
276
|
+
assert_ene Reg[-[:foo,:bar]-1], [:foo]
|
277
|
+
assert_ene Reg[-[:foo,:bar]-1], [:bar]
|
278
|
+
assert_ene Reg[-[:foo,:bar]-1], [:baz]
|
279
|
+
assert_eee Reg[-[:foo,:bar]-1], []
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
assert_eee Reg[OB.+], [1]
|
284
|
+
assert_eee Reg[OB.+], [1,2,3]
|
285
|
+
assert_eee Reg[OB.-], [1]
|
286
|
+
assert_ene Reg[OB.-], [1,2,3]
|
287
|
+
assert_ene Reg[:a, OB-1, :b, :b, :b, :b, :b], [:a, 1,1,1,1,1,1, :b, :b, :b, :b, :b]
|
288
|
+
assert_eee Reg[:a, OB-1, :b, :b, :b, :b, :b], [:a, 1, :b, :b, :b, :b, :b]
|
289
|
+
assert_eee Reg[:a, OB-1, :b, :b, :b, :b, :b], [:a, :b, :b, :b, :b, :b]
|
290
|
+
assert_ene Reg[:a, OB-1, :b, :b, :b, :b, :b], [1, :b, :b, :b, :b, :b]
|
291
|
+
assert_ene Reg[:a, OB-1, :b, :b, :b, :b, :b], [:b, :b, :b, :b, :b]
|
292
|
+
assert_ene Reg[:a, OB-1, :b, :b, :b, :b, :b], [:a, 1, :b, :b, :b, :b]
|
293
|
+
assert_ene Reg[:a, OB-1, :b, :b, :b, :b, :b], [:a, :b, :b, :b, :b]
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
if defined? NextMatchTests
|
298
|
+
a=[:foo]
|
299
|
+
x=(:foo.reg-1).mmatch a,0
|
300
|
+
assert x.next_match(a,0)==[[[:foo]],1]
|
301
|
+
assert x.next_match(a,0)==[[[]],0]
|
302
|
+
assert x.next_match(a,0)==nil
|
303
|
+
x=(:foo.reg-1).mmatch a,1
|
304
|
+
assert x==[[[]],0]
|
305
|
+
|
306
|
+
a=[:foo]
|
307
|
+
x=(:foo.reg-1-1).mmatch a,0
|
308
|
+
assert x.next_match(a,0)==[[[[:foo]]],1]
|
309
|
+
assert x.next_match(a,0)==[[[]],0]
|
310
|
+
assert x.next_match(a,0)==nil
|
311
|
+
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
a=(1..5).to_a
|
318
|
+
r=OB+1+3
|
319
|
+
x=r.mmatch a,0
|
320
|
+
assert x.next_match(a,0)==[[ [[1, 2, 3]], [[4]], [[5]] ], 5]
|
321
|
+
assert x.next_match(a,0)==[[ [[1, 2]], [[3, 4]], [[5]] ], 5]
|
322
|
+
assert x.next_match(a,0)==[[ [[1, 2]], [[3]], [[4, 5]] ], 5]
|
323
|
+
assert x.next_match(a,0)==[[ [[1, 2]], [[3]], [[4]], [[5]] ], 5]
|
324
|
+
assert x.next_match(a,0)==[[ [[1, 2]], [[3]], [[4]] ], 4]
|
325
|
+
assert x.next_match(a,0)==[[ [[1]], [[2, 3, 4]], [[5]] ], 5]
|
326
|
+
assert x.next_match(a,0)==[[ [[1]], [[2, 3]], [[4, 5]] ], 5]
|
327
|
+
assert x.next_match(a,0)==[[ [[1]], [[2, 3]], [[4]], [[5]] ], 5]
|
328
|
+
assert x.next_match(a,0)==[[ [[1]], [[2, 3]], [[4]] ], 4]
|
329
|
+
assert x.next_match(a,0)==[[ [[1]], [[2]], [[3, 4, 5]] ], 5]
|
330
|
+
assert x.next_match(a,0)==[[ [[1]], [[2]], [[3, 4]], [[5]] ], 5]
|
331
|
+
assert x.next_match(a,0)==[[ [[1]], [[2]], [[3, 4]] ], 4]
|
332
|
+
assert x.next_match(a,0)==[[ [[1]], [[2]], [[3]], [[4, 5]] ], 5]
|
333
|
+
assert x.next_match(a,0)==[[ [[1]], [[2]], [[3]], [[4]], [[5]] ], 5]
|
334
|
+
assert x.next_match(a,0)==[[ [[1]], [[2]], [[3]], [[4]] ], 4]
|
335
|
+
assert x.next_match(a,0)==[[ [[1]], [[2]], [[3]]], 3]
|
336
|
+
assert x.next_match(a,0)==nil
|
337
|
+
|
338
|
+
end
|
339
|
+
|
340
|
+
|
341
|
+
assert_ene Reg[OB+1+2+2], [:f]*3
|
342
|
+
assert_ene Reg[OB+2+1+2], [:f]*3
|
343
|
+
assert_eee Reg[OB+1+2+2], [:f]*4
|
344
|
+
assert_eee Reg[OB+2+2+1], [:f]*4
|
345
|
+
assert_eee Reg[OB+2+1+2], [:f]*4
|
346
|
+
assert_ene Reg[OB+2+2+2], [:f]*7
|
347
|
+
assert_eee Reg[OB+2+2+2], [:f]*8
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
|
352
|
+
assert_ene Reg[OB+2+2+3], [:f]*11
|
353
|
+
assert_eee Reg[OB+2+2+3], [:f]*12
|
354
|
+
assert_eee Reg[OB+2+2+3], [:f]*16
|
355
|
+
|
356
|
+
assert_ene Reg[5.reg+1+3+2], [6]+[5]*5
|
357
|
+
assert_ene Reg[5.reg+1+3+2], [5]+[6]+[5]*4
|
358
|
+
assert_ene Reg[5.reg+1+3+2], [5]*2+[6]+[5]*3
|
359
|
+
assert_ene Reg[5.reg+1+3+2], [5]*3+[6]+[5]*2
|
360
|
+
assert_ene Reg[5.reg+1+3+2], [5]*4+[6,5]
|
361
|
+
assert_ene Reg[5.reg+1+3+2], [5]*5+[6]
|
362
|
+
|
363
|
+
assert_eee Reg[OB+1+3+2], [6]+[5]*5
|
364
|
+
assert_eee Reg[OB+1+3+2], [5]+[6]+[5]*4
|
365
|
+
assert_eee Reg[OB+1+3+2], [5]*2+[6]+[5]*3
|
366
|
+
assert_eee Reg[OB+1+3+2], [5]*3+[6]+[5]*2
|
367
|
+
assert_eee Reg[OB+1+3+2], [5]*4+[6,5]
|
368
|
+
assert_eee Reg[OB+1+3+2], [5]*5+[6]
|
369
|
+
|
370
|
+
assert_ene Reg[OB+1+3+2], [6]+[5]*4
|
371
|
+
assert_ene Reg[OB+1+3+2], [5]+[6]+[5]*3
|
372
|
+
assert_ene Reg[OB+1+3+2], [5]*2+[6]+[5]*2
|
373
|
+
assert_ene Reg[OB+1+3+2], [5]*3+[6]+[5]
|
374
|
+
assert_ene Reg[OB+1+3+2], [5]*4+[6]
|
375
|
+
|
376
|
+
|
377
|
+
assert_eee Reg[5.reg+1+3+2], [5]*6
|
378
|
+
assert_ene Reg[5.reg+2+2+2], [5]*8+[6]
|
379
|
+
assert_ene Reg[:foo.reg*(1..2)*(2..3)*(2..3)], [:foo]*3
|
380
|
+
|
381
|
+
assert_eee Reg[:foo.reg*(1..2)*(2..3)*(2..3)], [:foo]*4
|
382
|
+
assert_ene Reg[OB*(1..2)*(2..3)*(2..3)], [:foo]*3
|
383
|
+
assert_eee Reg[OB*(1..2)*(2..3)*(2..3)], [:foo]*4
|
384
|
+
assert_ene Reg[OB*(1..2)*(2..3)+2], [:foo]*3
|
385
|
+
assert_eee Reg[OB*(1..2)*(2..3)+2], [:foo]*4
|
386
|
+
assert_ene Reg[OB+1+2+2], [:foo]*3
|
387
|
+
assert_eee Reg[OB+1+2+2], [:foo]*4
|
388
|
+
|
389
|
+
assert_eee Reg[OB*(1..3)*(2..3)*2], [:foo]*4
|
390
|
+
|
391
|
+
|
392
|
+
if defined? NextMatchTests
|
393
|
+
|
394
|
+
a=[:foo]*6
|
395
|
+
x=(OB*2*(1..2)*2).mmatch(a,0)
|
396
|
+
assert x.next_match(a,0)==
|
397
|
+
[[ [[[:foo, :foo]], [[:foo, :foo]]], [[[:foo, :foo]]] ], 6]
|
398
|
+
assert x.next_match(a,0)==
|
399
|
+
[[ [[[:foo, :foo]]], [[[:foo, :foo]], [[:foo, :foo]]] ], 6]
|
400
|
+
assert x.next_match(a,0)==
|
401
|
+
[[ [[[:foo, :foo]]], [[[:foo, :foo]]] ], 4]
|
402
|
+
assert x.next_match(a,0).nil?
|
403
|
+
end
|
404
|
+
|
405
|
+
#$RegTraceEnable=true
|
406
|
+
assert_eee Reg[OB*2*(1..2)*2], [:foo]*6
|
407
|
+
assert_eee Reg[OB*2*(1..2)*2,OB,OB], [:foo]*6
|
408
|
+
assert_eee Reg[OB*2*(1..2)*2,OB*2], [:foo]*6
|
409
|
+
assert_eee Reg[OB*2*(1..2)*2,OB+2], [:foo]*6
|
410
|
+
assert_eee Reg[OB*2*(1..2)*2, OB-1], [:foo]*6
|
411
|
+
assert_eee Reg[OB*2*(1..2)*2, OB-1], [:foo]*7
|
412
|
+
assert_eee Reg[OB*2*(1..2)*2], [:foo]*8
|
413
|
+
assert_eee Reg[OB*2*(1..2)*2], [:foo]*4
|
414
|
+
assert_eee Reg[OB*(2..3)*(1..2)*2], [:foo]*4
|
415
|
+
assert_eee Reg[OB*(2..3)*(2..3)*(1..2)], [:foo]*4
|
416
|
+
assert_eee Reg[OB*(2..2)*(2..3)*(2..3)], [:foo]*8
|
417
|
+
assert_eee Reg[OB*(2..3)*(2..2)*(2..3)], [:foo]*8
|
418
|
+
|
419
|
+
assert_eee Reg[OB*(2..3)*(2..3)*2], [:foo]*8
|
420
|
+
assert_eee Reg[OB*(2..3)*(2..3)*(2..3)], [:foo]*8
|
421
|
+
assert_ene Reg[:foo.reg*(2..3)*(2..3)*2], [:foo]*7
|
422
|
+
|
423
|
+
if defined? NextMatchTests
|
424
|
+
assert(!(Reg[OB*1*(1..2)]===[:f]).first.empty?)
|
425
|
+
|
426
|
+
|
427
|
+
a=[:foo]*4
|
428
|
+
x=(OB*(1..2)+2).mmatch(a,0)
|
429
|
+
assert x.next_match(a,0)==[[ [[:foo, :foo]], [[:foo, :foo]] ], 4]
|
430
|
+
assert x.next_match(a,0)==[[ [[:foo, :foo]], [[:foo]], [[:foo]] ], 4]
|
431
|
+
assert x.next_match(a,0)==[[ [[:foo, :foo]], [[:foo]] ], 3]
|
432
|
+
assert x.next_match(a,0)==[[ [[:foo]], [[:foo, :foo]], [[:foo]] ], 4]
|
433
|
+
assert x.next_match(a,0)==[[ [[:foo]], [[:foo, :foo]] ], 3]
|
434
|
+
assert x.next_match(a,0)==[[ [[:foo]], [[:foo]], [[:foo, :foo]] ], 4]
|
435
|
+
assert x.next_match(a,0)==[[ [[:foo]], [[:foo]], [[:foo]], [[:foo]] ], 4]
|
436
|
+
assert x.next_match(a,0)==[[ [[:foo]], [[:foo]], [[:foo]] ], 3]
|
437
|
+
assert x.next_match(a,0)==[[ [[:foo]], [[:foo]] ], 2]
|
438
|
+
assert x.next_match(a,0)==nil
|
439
|
+
end
|
440
|
+
assert_ene Reg[OB*(1..2)+2+2], [:foo]*3
|
441
|
+
assert_eee Reg[OB*(1..2)+2+2], [:foo]*4
|
442
|
+
|
443
|
+
if defined? NextMatchTests
|
444
|
+
|
445
|
+
a=(1..9).to_a
|
446
|
+
x=(OB+2+2+2).mmatch a,0
|
447
|
+
assert x.next_match(a,0)===[[ [[[1, 2, 3]], [[4, 5]]], [[[6, 7]], [[8, 9]]] ], 9]
|
448
|
+
assert x.next_match(a,0)===[[ [[[1, 2]], [[3, 4, 5]]], [[[6, 7]], [[8, 9]]] ], 9]
|
449
|
+
assert x.next_match(a,0)===[[ [[[1, 2]], [[3, 4]]], [[[5, 6, 7]], [[8, 9]]] ], 9]
|
450
|
+
assert x.next_match(a,0)===[[ [[[1, 2]], [[3, 4]]], [[[5, 6]], [[7, 8, 9]]] ], 9]
|
451
|
+
assert x.next_match(a,0)===[[ [[[1, 2]], [[3, 4]]], [[[5, 6]], [[7, 8]]] ], 8]
|
452
|
+
assert x.next_match(a,0)===nil
|
453
|
+
end
|
454
|
+
|
455
|
+
assert_eee Reg[OB+2+2+2], [:foo]*8
|
456
|
+
assert_eee Reg[OB+2+2+2, OB], [:foo]*9
|
457
|
+
assert_eee Reg[OB+2+2+2, OB+1], [:foo]*9
|
458
|
+
assert_eee Reg[OB+2+2+2, OB-1], [:foo]*9
|
459
|
+
assert_eee Reg[OB+2+2+2], [:foo]*9
|
460
|
+
|
461
|
+
if defined? NextMatchTests
|
462
|
+
a=[:foo]*4
|
463
|
+
x=(OB*2*(1..2)).mmatch(a,2)
|
464
|
+
assert x.next_match(a,2)==[[[[:foo, :foo]]], 2]
|
465
|
+
assert x.next_match(a,2)==nil
|
466
|
+
end
|
467
|
+
|
468
|
+
assert_eee( +[OB*(1..2)*2],[:foo]*2)
|
469
|
+
|
470
|
+
if defined? NextMatchTests
|
471
|
+
a=[:foo]*3
|
472
|
+
x=(OB*(1..2)*2).mmatch(a,0)
|
473
|
+
assert x.next_match(a,0)==
|
474
|
+
[[ [[:foo, :foo]], [[:foo]] ], 3]
|
475
|
+
assert x.next_match(a,0)==
|
476
|
+
[[ [[:foo]], [[:foo, :foo]] ], 3]
|
477
|
+
assert x.next_match(a,0)==
|
478
|
+
[[ [[:foo]], [[:foo]] ], 2]
|
479
|
+
assert x.next_match(a,0).nil?
|
480
|
+
end
|
481
|
+
|
482
|
+
assert_ene Reg[OB*(2..2)*(2..3)*(2..3)], [:foo]*7
|
483
|
+
assert_ene Reg[OB*(2..3)*(2..2)*(2..3)], [:foo]*7
|
484
|
+
assert_ene Reg[OB*(1..3)*(2..3)*2], [:foo]*3
|
485
|
+
assert_ene Reg[OB*(2..3)*(1..3)*2], [:foo]*3
|
486
|
+
assert_ene Reg[OB*(2..3)*(2..3)*(1..2)], [:foo]*3
|
487
|
+
|
488
|
+
assert_ene Reg[OB*(2..3)*(2..3)*2], [:foo]*7
|
489
|
+
assert_ene Reg[OB*(2..3)*(2..3)*(2..3)], [:foo]*7
|
490
|
+
assert_ene Reg[OB+2+2+2], [:foo]*7
|
491
|
+
|
492
|
+
|
493
|
+
assert_eee Reg[OB*2*1*2], [:foo]*4
|
494
|
+
assert_eee Reg[OB*1*(1..2)*2], [:foo]*2
|
495
|
+
assert_eee Reg[OB*2*(1..2)*1], [:foo]*2
|
496
|
+
assert_eee Reg[OB*1*(1..2)*2], [:foo]*3
|
497
|
+
assert_ene Reg[OB*2*(1..2)*1], [:foo]*3
|
498
|
+
assert_eee Reg[OB*1*(1..2)*2], [:foo]*4
|
499
|
+
assert_eee Reg[OB*2*(1..2)*1], [:foo]*4
|
500
|
+
|
501
|
+
|
502
|
+
if defined? NextMatchTests
|
503
|
+
|
504
|
+
a=[:foo]*3
|
505
|
+
x=(:foo.reg*(1..2)).mmatch a,0
|
506
|
+
assert x.next_match(a,0)==[[[:foo]*2],2]
|
507
|
+
assert x.next_match(a,0)==[[[:foo]],1]
|
508
|
+
assert x.next_match(a,0)==nil
|
509
|
+
|
510
|
+
x=(:foo.reg*(1..2)).mmatch a,1
|
511
|
+
assert x.next_match(a,0)==[[[:foo]*2],2]
|
512
|
+
assert x.next_match(a,0)==[[[:foo]],1]
|
513
|
+
assert x.next_match(a,0)==nil
|
514
|
+
|
515
|
+
x=(:foo.reg*(1..2)).mmatch a,2
|
516
|
+
assert x==[[[:foo]],1]
|
517
|
+
|
518
|
+
x=(:foo.reg*(1..2)).mmatch a,3
|
519
|
+
assert x.nil?
|
520
|
+
|
521
|
+
x=(:foo.reg*(1..2)*(2..3)).mmatch a,0
|
522
|
+
assert x.next_match(a,0)==[[[[:foo]*2],[[:foo]]], 3]
|
523
|
+
assert x.instance_eval{@ri}==2
|
524
|
+
assert x.next_match(a,0)==[[[[:foo]],[[:foo]*2]], 3]
|
525
|
+
assert x.instance_eval{@ri}==2
|
526
|
+
assert x.next_match(a,0)==[[[[:foo]],[[:foo]],[[:foo]]], 3]
|
527
|
+
assert x.instance_eval{@ri}==3
|
528
|
+
assert x.next_match(a,0)==[[[[:foo]],[[:foo]]], 2]
|
529
|
+
assert x.instance_eval{@ri}==2
|
530
|
+
assert x.next_match(a,0)==nil
|
531
|
+
|
532
|
+
x=(:foo.reg*(1..2)*(2..3)).mmatch a,1
|
533
|
+
assert x.next_match(a,0)==[[[[:foo]],[[:foo]]], 2]
|
534
|
+
assert x.instance_eval{@ri}==2
|
535
|
+
assert x.next_match(a,0)==nil
|
536
|
+
|
537
|
+
x=(:foo.reg*(1..2)*(2..3)).mmatch a,2
|
538
|
+
assert x.nil?
|
539
|
+
|
540
|
+
x=(:foo.reg*(1..2)*(2..3)).mmatch a,3
|
541
|
+
assert x.nil?
|
542
|
+
end
|
543
|
+
|
544
|
+
assert((not (:foo.reg*(1..2)*(2..3)*(2..3)).mmatch [:foo]*3,0 ))
|
545
|
+
|
546
|
+
|
547
|
+
|
548
|
+
|
549
|
+
assert_eee Reg[5.reg+2+2], [5]*4
|
550
|
+
assert_eee Reg[5.reg*(1..2)*(1..2)*(1..2)], [5]
|
551
|
+
assert_eee Reg[5.reg*(1..2)*(1..2)*(2..3)], [5]*2
|
552
|
+
assert_eee Reg[5.reg*(1..2)*(2..3)*(2..3)], [5]*4
|
553
|
+
assert_eee Reg[(5.reg+1)*(2..3)*(2..3)], [5]*4
|
554
|
+
assert_eee Reg[(5.reg+1+2)*(2..3)], [5]*4
|
555
|
+
assert_eee Reg[5.reg+1+2+2], [5]*4
|
556
|
+
assert_eee Reg[OB+3+2], [:f]*6
|
557
|
+
|
558
|
+
aaa_patho=-[/^a/]|-[/^.a/, OB]|-[/^..a/, OB*2]
|
559
|
+
assert_ene( +[aaa_patho], ["aaa"]*200 )
|
560
|
+
assert_eee( +[aaa_patho+0], ["aaa"]*200 )
|
561
|
+
|
562
|
+
|
563
|
+
|
564
|
+
|
565
|
+
assert_eee Reg[(-[-[:p]*(1..2)])], [:p]
|
566
|
+
assert_eee Reg[(-[-[:p]*(1..2)])], [:p,:p]
|
567
|
+
assert_ene Reg[(-[-[:p]*(1..2)])], [:p,:q]
|
568
|
+
assert_ene Reg[(-[-[:p]*(1..2)])], [:q]
|
569
|
+
assert_ene Reg[(-[-[:p]*(1..2)])], []
|
570
|
+
assert_ene Reg[(-[-[:p]*(1..2)])], [:p,:p, :p]
|
571
|
+
|
572
|
+
|
573
|
+
assert_eee Reg[OB+1], [:foo,:foo]
|
574
|
+
assert_eee Reg[OB+1+1], [:foo,:foo]
|
575
|
+
assert_eee Reg[OB+1+1+1], [:foo,:foo]
|
576
|
+
assert_eee Reg[OB+1+1+1+1], [:foo,:foo]
|
577
|
+
|
578
|
+
assert_ene Reg[OB+2+3], [:f]*5
|
579
|
+
assert_ene Reg[OB+2+2+1], [:f]*3
|
580
|
+
|
581
|
+
assert_eee(+[be], [
|
582
|
+
:begin, :SubseqMatchSet, :IndexError, :termsig, :"\\", :ll,
|
583
|
+
:end]
|
584
|
+
)
|
585
|
+
assert_eee(+[be+0], [
|
586
|
+
:begin, :SubseqMatchSet, :IndexError, :termsig, :"\\", :begin,
|
587
|
+
:end]
|
588
|
+
)
|
589
|
+
assert_eee(+[be+0], [
|
590
|
+
:begin, :SubseqMatchSet, :IndexError, :termsig, :"\\", :end,
|
591
|
+
:end]
|
592
|
+
)
|
593
|
+
assert_eee(+[be+0], [
|
594
|
+
:begin, :SubseqMatchSet, :IndexError, :termsig, :"\\",
|
595
|
+
:begin, :right, :"\\",
|
596
|
+
:begin, :f, :call, :safe_level, :"\\",
|
597
|
+
:begin, :undefine_finalizer, :test_anonymous, :quote,
|
598
|
+
:end]
|
599
|
+
)
|
600
|
+
assert_eee(+[lhqqbe+0], [
|
601
|
+
:begin, :SubseqMatchSet, :IndexError, :termsig, :"\\",
|
602
|
+
:begin, :right, :"\\",
|
603
|
+
:begin, :f, :call, :safe_level, :"\\",
|
604
|
+
:begin, :undefine_finalizer, :test_anonymous, :quote,
|
605
|
+
:end]
|
606
|
+
)
|
607
|
+
|
608
|
+
assert_eee Reg[lhqqbe+0], [
|
609
|
+
:begin, :popen, :"chomp!", :-@, :end, :q, :q,
|
610
|
+
:begin, :begin, :end, :end,
|
611
|
+
:begin, :MINOR_VERSION, :"public_method_defined?", :"\\", :begin, :umask,
|
612
|
+
:debug_print_help, :geteuid, :end,
|
613
|
+
:q, :public_methods, :option_name, :MUTEX, :q,
|
614
|
+
:begin, :verbose=, :binding, :symlink, :lambda,
|
615
|
+
:emacs_editing_mode, :"dst?", :end, 0,
|
616
|
+
:begin, :test_to_s_with_iv, :"\\", :begin, :glob, :each_with_index,
|
617
|
+
:initialize_copy, :begin, :$PROGRAM_NAME, :end,
|
618
|
+
:ELIBACC, :setruid, :"success?", :end,
|
619
|
+
:begin, :__size__, :width, :"\\", :begin, :$-a, :"sort!", :waitpid, :end,
|
620
|
+
:begin, :Stat, :WadlerExample, :chr, :end,
|
621
|
+
:begin, :+, :disable, :abstract,
|
622
|
+
:begin, :__size__, :"symlink?", :"dst?", :end, :ljust, :end,
|
623
|
+
:begin, :debug_method_info, :matchary, :"\\", :begin, :ftype,
|
624
|
+
:thread_list_all, :eof, :begin, :abs, :GroupQueue, :end,
|
625
|
+
:"slice!", :ordering=, :end,
|
626
|
+
:Q, :"\\", :Q, :ELIBMAX, :GetoptLong, :nlink, :Q,
|
627
|
+
:begin, :Fixnum, :waitall, :"enclosed?", :"\\", :begin, :deep_copy,
|
628
|
+
:getpgid, :strftime, :end,
|
629
|
+
:Q, :close_obj, :Q,
|
630
|
+
3, :basic_quote_characters=, :rmdir, :"writable_real?",
|
631
|
+
:begin, :test_hello_11_12, :utc_offset, :freeze,
|
632
|
+
:begin, :kcode, :egid=, :ARGF, :end,
|
633
|
+
:setuid, :lock, :gmtoff, :end,
|
634
|
+
:begin, :$FILENAME, :test_tree_alt_20_49,
|
635
|
+
:begin, :LOCK_SH, :EL3HLT, :end, :end,
|
636
|
+
:Q, :"\\", :Q, :ceil, :remainder, :group_sub, :Q, 0
|
637
|
+
]
|
638
|
+
|
639
|
+
if $Slow ||=false
|
640
|
+
#btracing monsters
|
641
|
+
assert_ene Reg[OB+1+3+2], (1..5).to_a
|
642
|
+
0.upto(5) {|i| assert_ene Reg[OB+1+3+2], [:f]*i }
|
643
|
+
6.upto(16){|i| assert_eee Reg[OB+1+3+2], [:f]*i }
|
644
|
+
|
645
|
+
assert_ene Reg[OB+2+3+2], [:f]*11
|
646
|
+
assert_eee Reg[OB+2+3+2], [:f]*12
|
647
|
+
assert_ene Reg[OB+2+3+3], [:f]*17
|
648
|
+
assert_eee Reg[OB+2+3+3], [:f]*18
|
649
|
+
assert_ene Reg[OB+3+3+3], [:f]*26
|
650
|
+
assert_eee Reg[OB+3+3+3], [:f]*27
|
651
|
+
# assert_ene Reg[OB+4+4+4], [:f]*63 #insane
|
652
|
+
# assert_eee Reg[OB+4+4+4], [:f]*64 #insane
|
653
|
+
assert_ene Reg[OB+2+2+2+2], [:f]*15
|
654
|
+
assert_eee Reg[OB+2+2+2+2], [:f]*16
|
655
|
+
# assert_ene Reg[OB+2+2+2+2+2+2+2+2], [:foo]*255 #insane
|
656
|
+
# assert_eee Reg[OB+2+2+2+2+2+2+2+2], [:foo]*256 #insane
|
657
|
+
|
658
|
+
|
659
|
+
#assert_eee Reg[OB+10+10], [:f]*100 #waaaay too slow
|
660
|
+
assert_eee Reg[OB+5+5], [:f]*25
|
661
|
+
assert_ene Reg[OB+5+5], [:f]*24
|
662
|
+
assert_eee Reg[OB+6+6], [:f]*36
|
663
|
+
assert_ene Reg[OB+6+6], [:f]*35
|
664
|
+
assert_eee Reg[OB+7+7], [:f]*49 #prolly excessive
|
665
|
+
assert_ene Reg[OB+7+7], [:f]*48 #prolly excessive
|
666
|
+
|
667
|
+
assert_ene Reg[OB+1+2+2+2], [:f]*7
|
668
|
+
assert_eee Reg[OB+1+2+2+2], [:f]*8
|
669
|
+
assert_ene Reg[OB+1+1+2+2+2], [:f]*7
|
670
|
+
assert_eee Reg[OB+1+1+2+2+2], [:f]*8
|
671
|
+
assert_ene Reg[OB+1+1+1+2+2+2], [:f]*7
|
672
|
+
assert_eee Reg[OB+1+1+1+2+2+2], [:f]*8
|
673
|
+
|
674
|
+
assert_ene Reg[OB+1+1+1+1+2+2+2], [:f]*7
|
675
|
+
assert_eee Reg[OB+1+1+1+1+2+2+2], [:f]*8
|
676
|
+
|
677
|
+
r=2..3
|
678
|
+
assert_ene Reg[OB*(1..2)*r*r*r], [:f]*7
|
679
|
+
assert_eee Reg[OB*(1..2)*r*r*r], [:f]*8
|
680
|
+
end
|
681
|
+
|
682
|
+
assert_eee Reg[lhqqbe+0], [ :begin, :"\\", :rand, :end ]
|
683
|
+
#breakpoint
|
684
|
+
assert_eee( +[be], [:begin, :"\\", :"\\", :end])
|
685
|
+
assert_eee( +[be], [:begin, :"\\", :begin, :end])
|
686
|
+
assert_eee( +[be], [:begin, :"\\", :end, :end])
|
687
|
+
assert_eee( +[be], [:begin, :log, :readline, :"\\", :begin, :lh_or_qq, :test_pretty_print_inspect, :@newline, :end])
|
688
|
+
assert_eee( +[be], [:begin, :lock, :rindex, :begin, :sysopen, :rename, :end, :re_exchange, :on, :end])
|
689
|
+
assert_eee( +[be], [:begin, :lock, :"\\", :"\\", :begin, :rename, :end, :on, :end])
|
690
|
+
assert_eee( +[be], [:begin, :begin, :foo, :end, :end])
|
691
|
+
assert_eee( +[be], makelendata(1,0b11110000000).flatten)
|
692
|
+
assert_eee( +[be], [:begin, :end])
|
693
|
+
assert_eee( +[be], [:begin, :foo, :end])
|
694
|
+
assert_eee( +[be], makelendata(1,0b10000000).flatten)
|
695
|
+
assert_eee Reg[lhqqbe+0], makelendata(1,0b11111110011).flatten
|
696
|
+
assert_eee Reg[lhqqbe+0], makelendata(4,0b11111110011).flatten
|
697
|
+
assert_eee Reg[lhqqbe+0], makelendata(10,0b11111110011).flatten
|
698
|
+
assert_eee Reg[lhqqbe+0], makelendata(20,0b11111110011).flatten
|
699
|
+
|
700
|
+
assert_ene Reg[:foo,OB+1], [:foo]
|
701
|
+
assert_ene Reg[OB+1,:foo], [:foo]
|
702
|
+
assert_eee Reg[OB+1], [:foo]
|
703
|
+
|
704
|
+
|
705
|
+
assert_eee Reg[OB+1+1+1+1+1+1+1+1+1+1+1+1+1+1], [:foo]
|
706
|
+
|
707
|
+
assert_ene Reg[OB+1+1+1+1], []
|
708
|
+
assert_eee Reg[OB+1+1+1+1], [:foo,:foo]
|
709
|
+
assert_ene Reg[OB+2], [:foo]
|
710
|
+
assert_ene Reg[OB+2+2], [:foo]*3
|
711
|
+
assert_ene Reg[OB+2+2+1], [:foo]*3
|
712
|
+
assert_ene Reg[OB+2+1+2], [:foo]*3
|
713
|
+
|
714
|
+
|
715
|
+
assert_eee Reg[-[1,2]|3], [1,2]
|
716
|
+
assert_eee Reg[-[1,2]|3], [3]
|
717
|
+
assert_ene Reg[-[1,2]|3], [4]
|
718
|
+
assert_ene Reg[-[1,2]|3], [2]
|
719
|
+
assert_ene Reg[-[1,2]|3], [1,3]
|
720
|
+
|
721
|
+
assert_eee Reg[lenheadlist], [1, :__id__]
|
722
|
+
assert_eee Reg[(-[0]|-[1,OB]|-[2,OB*2])*1], [2, :p, :stat]
|
723
|
+
assert_eee Reg[(-[2,OB*2])-1], [2, :p, :stat]
|
724
|
+
assert_eee Reg[(-[OB])*(1..2)], [1, :p]
|
725
|
+
|
726
|
+
assert_eee Reg[(-[-[:p]*(1..2)])], [:p]
|
727
|
+
assert_eee Reg[(-[-[:p]])*(1..2)], [:p]
|
728
|
+
assert_eee Reg[(-[-[OB]])*(1..2)], [:p]
|
729
|
+
assert_eee Reg[(-[OB*1])*(1..2)], [:p]
|
730
|
+
assert_eee Reg[(-[1,OB*1])*(1..2)], [1, :p]
|
731
|
+
assert_eee Reg[(-[2,OB*2])*(1..2)], [2, :p, :stat]
|
732
|
+
assert_eee Reg[(-[0]|-[1,OB]|-[2,OB*2])*(1..2)], [2, :p, :stat]
|
733
|
+
assert_eee Reg[(-[0]|-[1,OB]|-[2,OB*2])+1], [2, :p, :stat]
|
734
|
+
assert_eee Reg[lenheadlist], [2, :p, :stat]
|
735
|
+
assert_eee Reg[lenheadlist], [2, :p, :stat, 1, :__id__]
|
736
|
+
assert_eee Reg[lenheadlist], [2, :p, :stat, 0, 1, :__id__, 0, 0]
|
737
|
+
assert_eee Reg[lenheadlist], lenheaddata
|
738
|
+
assert_ene Reg[lenheadlist], lenheaddataj
|
739
|
+
assert_eee( +[lh_or_qq+0], lenheaddata )
|
740
|
+
assert_eee( +[lh_or_qq+0], lenheaddata+[:q, :foo, :bar, :baz, :q] )
|
741
|
+
|
742
|
+
assert_eee Reg[lenheadlist], [0]
|
743
|
+
assert_eee Reg[lenheadlist], makelendata(1,0b11).flatten
|
744
|
+
assert_eee Reg[lenheadlist], makelendata(5,0b11).flatten
|
745
|
+
assert_eee Reg[lenheadlist], makelendata(10,0b11).flatten
|
746
|
+
assert_eee Reg[lenheadlist], makelendata(20,0b11).flatten
|
747
|
+
assert_ene Reg[lenheadlist], makelendata(20,0b11).flatten+[:j]
|
748
|
+
assert_ene Reg[lenheadlist], [:j]+makelendata(20,0b11).flatten+[:j]
|
749
|
+
assert_ene Reg[lenheadlist], [:j]+makelendata(20,0b11).flatten
|
750
|
+
|
751
|
+
assert_ene Reg[lenheadlist], makelendata(20,0b11,:j).flatten
|
752
|
+
assert_eee( +[lh_or_qq+0], makelendata(20,0b11).flatten )
|
753
|
+
assert_eee( +[lh_or_qq+0], makelendata(20,0b1000011).flatten )
|
754
|
+
assert_ene( +[lh_or_qq+0], makelendata(20,0b1000011).flatten+[:j] )
|
755
|
+
assert_ene( +[lh_or_qq+0], [:j]+makelendata(20,0b1000011).flatten+[:j] )
|
756
|
+
assert_ene( +[lh_or_qq+0], [:j]+makelendata(20,0b1000011).flatten )
|
757
|
+
|
758
|
+
|
759
|
+
|
760
|
+
t=(1..2)
|
761
|
+
assert_eee Reg[OB*t*t*t*t], [:foo]*16
|
762
|
+
assert_ene Reg[OB*t*t*t*t], [:foo]*17
|
763
|
+
assert_eee Reg[5.reg*t], [5]
|
764
|
+
assert_eee Reg[5.reg*t*1], [5]
|
765
|
+
assert_eee Reg[5.reg*1*t], [5]
|
766
|
+
assert_eee Reg[5.reg*t*t], [5]
|
767
|
+
assert_eee Reg[5.reg*t*t*t], [5]
|
768
|
+
assert_eee Reg[5.reg*t*t*t*t], [5]
|
769
|
+
assert_eee Reg[5.reg+1+1+1], [5]
|
770
|
+
assert_eee Reg[5.reg+1+1+1+1], [5]
|
771
|
+
assert_eee Reg[OB+1+1+1], [:foo]
|
772
|
+
assert_eee Reg[OB+1+1+1+1], [:foo]
|
773
|
+
assert_eee Reg[OB+2], [:foo]*2
|
774
|
+
assert_eee Reg[OB+2+2], [:foo]*4
|
775
|
+
|
776
|
+
|
777
|
+
|
778
|
+
#btracing monsters:
|
779
|
+
assert_eee Reg[OB*2], [:foo]*2
|
780
|
+
assert_eee Reg[OB*2*2], [:foo]*4
|
781
|
+
assert_eee Reg[OB*2*2*2*2], [:foo]*16
|
782
|
+
assert_eee Reg[OB*2*2*2*2*2*2*2*2], [:foo]*256
|
783
|
+
assert_eee Reg[OB-2-2-2-2-2-2-2-2], [:foo]*256
|
784
|
+
|
785
|
+
|
786
|
+
|
787
|
+
assert_ene Reg[OB-0], [1]
|
788
|
+
assert_eee Reg[OB+0], [1]
|
789
|
+
assert_eee Reg[OB-1], [1]
|
790
|
+
assert_eee Reg[OB+1], [1]
|
791
|
+
assert_eee Reg[OB-2], [1,2]
|
792
|
+
assert_eee Reg[OB+2], [1,2]
|
793
|
+
|
794
|
+
assert_eee Reg[OB], [1]
|
795
|
+
assert_eee Reg[OB*1], [1]
|
796
|
+
assert_eee Reg[OB*2], [1,2]
|
797
|
+
assert_eee Reg[OB*4], [1,2,3,4]
|
798
|
+
|
799
|
+
abcreg=Reg[OBS,:a,:b,:c,OBS]
|
800
|
+
assert_eee abcreg, [:a,:b,:c,7,8,9]
|
801
|
+
assert_eee abcreg, [1,2,3,:a,:b,:c,7,8,9]
|
802
|
+
|
803
|
+
assert_eee abcreg, [1,2,3,:a,:b,:c]
|
804
|
+
assert_eee abcreg, [:a,:b,:c]
|
805
|
+
|
806
|
+
assert_ene abcreg, [1,2,3,:a,:b,:d]
|
807
|
+
assert_ene abcreg, [1,2,3,:a,:d,:c]
|
808
|
+
assert_ene abcreg, [1,2,3,:d,:b,:c]
|
809
|
+
|
810
|
+
assert_ene abcreg, [1,2,3]
|
811
|
+
assert_ene abcreg, [1,2,3,:a]
|
812
|
+
assert_ene abcreg, [1,2,3,:a,:b]
|
813
|
+
|
814
|
+
assert_eee Reg[:a, OB+0, :b, :b, :b, :b, :b], [:a, 1,1,1,1,1,1, :b, :b, :b, :b, :b]
|
815
|
+
assert_eee Reg[:a, OB+0, :b, :b, :b, :b, :b], [:a, 1, :b, :b, :b, :b, :b]
|
816
|
+
assert_eee Reg[:a, OB+0, :b, :b, :b, :b, :b], [:a, :b, :b, :b, :b, :b]
|
817
|
+
|
818
|
+
assert_eee Reg[:a, OB+1, :b, :b, :b, :b, :b], [:a, 1,1,1,1,1,1, :b, :b, :b, :b, :b]
|
819
|
+
assert_eee Reg[:a, OB+1, :b, :b, :b, :b, :b], [:a, 1, :b, :b, :b, :b, :b]
|
820
|
+
assert_ene Reg[:a, OB+1, :b, :b, :b, :b, :b], [:a, :b, :b, :b, :b, :b]
|
821
|
+
|
822
|
+
assert_ene Reg[:a, OB-0, :b, :b, :b, :b, :b], [:a, 1,1,1,1,1,1, :b, :b, :b, :b, :b]
|
823
|
+
assert_ene Reg[:a, OB-0, :b, :b, :b, :b, :b], [:a, 1, :b, :b, :b, :b, :b]
|
824
|
+
assert_eee Reg[:a, OB-0, :b, :b, :b, :b, :b], [:a, :b, :b, :b, :b, :b]
|
825
|
+
|
826
|
+
assert_eee Reg[-[OB*2]], [99, 99] #di not right in top level
|
827
|
+
assert_eee Reg[-[-[-[-[-[OB*2]]]]]], [99, 99] #di not right in top level?
|
828
|
+
assert_eee Reg[-[-[-[-[-[OB*1]]]]]], [99] #di not right in top level?
|
829
|
+
#RR[RR[[RR[RR[RR[RR[99,99]]]]]]]
|
830
|
+
assert_eee Reg[OB*1], [:foo]
|
831
|
+
assert_eee Reg[-[OB]], [88]
|
832
|
+
assert_ene Reg[-[0]], [88]
|
833
|
+
assert_eee Reg[-[0]], [0]
|
834
|
+
assert_eee Reg[-[OB*1]], [:foo]
|
835
|
+
assert_eee Reg[OB*1*1], [:foo]
|
836
|
+
assert_eee Reg[OB*1*1*1*1*1*1*1*1*1*1*1*1*1*1], [:foo]
|
837
|
+
assert_eee Reg[OB-1-1-1-1-1-1-1-1-1-1-1-1-1-1], [:foo]
|
838
|
+
assert_eee Reg[-[2,OB*2]], [2, 99, 99]
|
839
|
+
|
840
|
+
assert_eee Reg::Multiple, -[0]|-[1,2]
|
841
|
+
assert( (-[0]|-[1,2]).respond_to?( :mmatch))
|
842
|
+
|
843
|
+
assert_eee Reg[-[0],OBS], lenheaddataj
|
844
|
+
assert_eee Reg[-[0]|-[1,OB],OBS], lenheaddataj
|
845
|
+
assert_eee Reg[-[0]|-[1,OB]|-[2,OB*2],OBS], lenheaddataj
|
846
|
+
assert_eee Reg[-[0]|-[1,OB]|-[2,OB*2]|-[3,OB*3],OBS], lenheaddataj
|
847
|
+
assert_eee Reg[-[0]|-[1,OB]|-[2,OB*2]|-[3,OB*3]|-[4,OB*4],OBS], lenheaddataj
|
848
|
+
|
849
|
+
|
850
|
+
|
851
|
+
test_hash_matcher Rah(:a=>:b), :matches=>[{:a=>:b}],
|
852
|
+
:unmatches=>[ {:a=>:c}, {} ] #=> false
|
853
|
+
|
854
|
+
h={}
|
855
|
+
h.default=:b
|
856
|
+
test_hash_matcher Rah(:a=>:b), :matches=>h, :unmatches=>{}
|
857
|
+
|
858
|
+
test_hash_matcher Rah(/^(a|b)$/=>33),
|
859
|
+
:matches=>[{"a"=>33}, {"b"=>33}, {"a"=>33,"b"=>33} ],
|
860
|
+
:unmatches=>[
|
861
|
+
{"a"=>33,"c"=>33},
|
862
|
+
{"b"=>33,"c"=>33}, {"a"=>33,"c"=>133}, {"b"=>33,"c"=>133}, {"a"=>133}, {"b"=>133} ,
|
863
|
+
{"c"=>33}, {"c"=>133} , {"a"=>33,"b"=>133}, {"a"=>133,"b"=>33}, {"a"=>133,"b"=>133}
|
864
|
+
]
|
865
|
+
|
866
|
+
=begin disabled.... Reg::Hash#|(Hash) not special anymore
|
867
|
+
assert_eee Rah("a"=>33)|{"b"=>33}, {"a"=>33,"b"=>33} #=> true
|
868
|
+
assert_eee Rah("a"=>33)|{"b"=>33}, {"a"=>33,"b"=>133} #=> true
|
869
|
+
assert_ene Rah("a"=>33)|{"b"=>33}, {"a"=>133,"b"=>33} #=> false
|
870
|
+
assert_ene Rah("a"=>33)|{"b"=>33}, {"a"=>133,"b"=>133} #=> false
|
871
|
+
|
872
|
+
assert_eee Rah("a"=>33)|{"b"=>33}, {"b"=>33} #=> true
|
873
|
+
=end
|
874
|
+
test_hash_matcher Rah(:a.reg|:b => 44), :matches=>[{:a => 44},{:b => 44}],
|
875
|
+
:unmatches=> [{:a => 144}, {:b => 144}]
|
876
|
+
|
877
|
+
#object matcher tests
|
878
|
+
ob=AnyStruct[:aa=>1,:b=>"foob",:c=>[1,2,3]]
|
879
|
+
assert_eee Rob(:aa=>1), ob
|
880
|
+
assert_eee Rob(:@aa=>1), ob
|
881
|
+
assert_eee Rob(:aa=>1,:b=>/foo/), ob
|
882
|
+
assert_eee Rob(:@aa=>1,:@b=>/foo/), ob
|
883
|
+
|
884
|
+
assert_ene Rob(:aa=>Float), ob
|
885
|
+
assert_ene Rob(:@aa=>Float), ob
|
886
|
+
assert_ene Rob(:aa=>1,:b=>/fu/), ob
|
887
|
+
assert_ene Rob(:@aa=>1,:@b=>/fu/), ob
|
888
|
+
|
889
|
+
assert_eee Rob(), ob
|
890
|
+
assert_ene Rob(:d=>item_that.size>33), ob
|
891
|
+
|
892
|
+
|
893
|
+
assert_eee Rob(/aa$/=>1), ob
|
894
|
+
#assert_eee Rob(/@aa/=>1), ob
|
895
|
+
assert_eee Rob(/aa$/=>1,:b=>/foo/), ob
|
896
|
+
#assert_eee Rob(/@aa/=>1,:@b=>/foo/), ob
|
897
|
+
|
898
|
+
assert_ene Rob(/aab$/=>1), ob
|
899
|
+
assert_ene Rob(/aab$/=>1,:b=>/foo/), ob
|
900
|
+
|
901
|
+
assert_ene Rob(/aa$/=>Float), ob
|
902
|
+
#assert_ene Rob(/@aa/=>Float), ob
|
903
|
+
assert_ene Rob(/aa$/=>1,:b=>/fu/), ob
|
904
|
+
#assert_ene Rob(/@aa/=>1,:@b=>/fu/), ob
|
905
|
+
|
906
|
+
assert_ene Rob(/ddd/=>item_that.size>33), ob
|
907
|
+
|
908
|
+
assert_eee Rob(/aa$/=>1,:b=>/foo/,:@c=>OB), ob
|
909
|
+
#assert_eee Rob(/@aa/=>1,:@b=>/foo/,OB=>item_that.size<33), ob
|
910
|
+
#assert_eee Rob(/@aa/=>1,:@b=>/foo/,:@c=>Array,OB=>nil), ob
|
911
|
+
|
912
|
+
assert_ene Rob(/a$/=>1,:bb=>/foo/,:@c=>OB), ob
|
913
|
+
#assert_ene Rob(/@a/=>1,:@b=>/foo/,OB=>item_that.size>33), ob
|
914
|
+
#assert_ene Rob(/@a/=>1,:@b=>/foo/,:@c=>Array,OB=>Symbol), ob
|
915
|
+
|
916
|
+
#Matches array containing exactly 2 elements; 1st is another array, 2nd is
|
917
|
+
#integer:
|
918
|
+
assert_eee( +[Array,Integer], [["ee"],555])
|
919
|
+
|
920
|
+
#Like above, but 1st is array of arrays of symbol
|
921
|
+
assert_eee( +[+[+[Symbol+0]+0],Integer], [[[:foo,:bar],[:baz,:bof]], 0])
|
922
|
+
|
923
|
+
#Matches array of at least 3 consecutive symbols and nothing else:
|
924
|
+
assert_ene( +[Symbol+3], [:hop]*2)
|
925
|
+
assert_eee( +[Symbol+3], [:hop]*3)
|
926
|
+
assert_eee( +[Symbol+3], [:hop]*4)
|
927
|
+
|
928
|
+
#Matches array with at least 3 (consecutive) symbols in it somewhere:
|
929
|
+
assert_eee( +[OBS, Symbol+3, OBS], [Module, nil, 1, "o", :g, [66,77], {888=>999}, :a, :b, :c])
|
930
|
+
assert_eee( +[OBS, Symbol+3, OBS], [Module, nil, 1, :a, :b, :c, "o", :g, [66,77], {888=>999}])
|
931
|
+
assert_ene( +[OBS, Symbol+3, OBS], [Module, nil, 1, :a, :b, "o", :g, [66,77], {888=>999}])
|
932
|
+
assert_eee( +[OBS, Symbol+3, OBS], [:a, :b, :c, Module, nil, 1, "o", :g, [66,77], {888=>999}])
|
933
|
+
|
934
|
+
#Matches array of at most 6 strings starting with 'g'
|
935
|
+
assert_eee( +[/^g/-6], [])
|
936
|
+
assert_eee( +[/^g/-6], ["gh"])
|
937
|
+
assert_eee( +[/^g/-6], ["gh","gg"])
|
938
|
+
assert_eee( +[/^g/-6], ["gh","gg", "gf"])
|
939
|
+
assert_eee( +[/^g/-6], ["gh","gg", "gf", "ge"])
|
940
|
+
assert_eee( +[/^g/-6], ["gh","gg", "gf", "ge","gd"])
|
941
|
+
assert_eee( +[/^g/-6], ["gh","gg", "gf", "ge","gd","gc"])
|
942
|
+
assert_ene( +[/^g/-6], ["gh","gg", "gf", "ge","gd","gc","gd"])
|
943
|
+
|
944
|
+
#Matches array of between 5 and 9 hashes containing a key :k pointing to
|
945
|
+
#something non-nil:
|
946
|
+
h={:k=>true}
|
947
|
+
assert_eee( +h, h)
|
948
|
+
assert_eee( +{:k=>OB}, h)
|
949
|
+
assert_eee( +{:k=>~nil.reg}, h)
|
950
|
+
assert_ene( +[ +{:k=>~nil.reg}*(5..9) ], [h,h,h,h])
|
951
|
+
assert_eee( +[ +{:k=>~nil.reg}*(5..9) ], [h,h,h,h,h])
|
952
|
+
assert_eee( +[ +{:k=>~nil.reg}*(5..9) ], [h,h,h,h,h,h])
|
953
|
+
assert_eee( +[ +{:k=>~nil.reg}*(5..9) ], [h,h,h,h,h,h,h])
|
954
|
+
assert_eee( +[ +{:k=>~nil.reg}*(5..9) ], [h,h,h,h,h,h,h,h])
|
955
|
+
assert_eee( +[ +{:k=>~nil.reg}*(5..9) ], [h,h,h,h,h,h,h,h,h])
|
956
|
+
assert_ene( +[ +{:k=>~nil.reg}*(5..9) ], [h,h,h,h,h,h,h,h,h,h])
|
957
|
+
|
958
|
+
#Matches an object with Integer instance variable @k and property (ie method)
|
959
|
+
#foobar that returns a string with 'baz' somewhere in it:
|
960
|
+
assert_eee( -{:@k=>Integer, :foobar=>/baz/}, AnyStruct[:k=>5, :foobar=>"kla-baz"])
|
961
|
+
|
962
|
+
#Matches array of 6 hashes with 6 as a value of every key, followed by
|
963
|
+
#18 objects with an attribute @s which is a String:
|
964
|
+
test_matcher( +[ +{OB=>6}*6 ], :matches=>[[ {:a=>6},{:a=>6,:b=>6},{:a=>6,:b=>6,:c=>6},{:hodd=>6},
|
965
|
+
{:tuber=>6.0}, {:xxx=>6, :e=>6} ]])
|
966
|
+
test_matcher( +[ +{OB=>6}*6, -{:@s=>String}*18 ],
|
967
|
+
:matches=>[ [ {:a=>6},{:a=>6,:b=>6},{:a=>6,:b=>6,:c=>6},{:hodd=>6},
|
968
|
+
{:tuber=>6.0}, {:xxx=>6, :e=>6}, *[AnyStruct[:s=>"66"]]*18 ]
|
969
|
+
],
|
970
|
+
:unmatches=>[
|
971
|
+
[ {:a=>6},{:a=>6,:b=>6},{:a=>6,:b=>6,:c=>6},{:hodd=>6},
|
972
|
+
{:tuber=>6.0}, {:xxx=>6, :e=>6}, *[AnyStruct[:s=>"66"]]*17 ],
|
973
|
+
[ {:a=>6},{:a=>6,:b=>6},{:a=>6,:b=>6,:c=>6},{:hodd=>6},
|
974
|
+
{:tuber=>6.0}, {:xxx=>6, :e=>6}, *[AnyStruct[:s=>"66"]]*19 ],
|
975
|
+
[ {:a=>6},{:a=>5,:b=>6},{:a=>4,:b=>5,:c=>6},{:hodd=>6},
|
976
|
+
{:tuber=>6.0}, {:xxx=>"t", :e=>6}, *[AnyStruct[:s=>"66"]]*18 ]
|
977
|
+
]
|
978
|
+
)
|
979
|
+
|
980
|
+
test_hash_matcher( +{OB=>6}, :unmatches=>{} )
|
981
|
+
|
982
|
+
test_hash_matcher +{/fo+/=>8, /ba+r/=>9}, :matches=> {"foo"=>8,"bar"=>9}
|
983
|
+
|
984
|
+
test_matcher +[/fo+/**8, /ba+r/**9],
|
985
|
+
:matches=> [{"foobar"=>8, "bar"=>9},{"foo"=>8,"bar"=>9}],
|
986
|
+
:unmatches=> {"foobar"=>9, "bar"=>9}
|
987
|
+
|
988
|
+
|
989
|
+
|
990
|
+
print "\n"
|
991
|
+
end
|
992
|
+
|
993
|
+
def disabled_test_subst
|
994
|
+
#insert ';)' after even elements of an array
|
995
|
+
+[-[ OB>>:even << -[BR[:even],';)'], OB]+0, OB.-]
|
996
|
+
#be nice to abbreviate this to:
|
997
|
+
#+[-[ OB<<-[BR[],';)'], OB ]+0, OB.-]
|
998
|
+
end
|
999
|
+
|
1000
|
+
|
1001
|
+
def assert_eee(left,right,message='assert_eee failed')
|
1002
|
+
assert(
|
1003
|
+
left===right,
|
1004
|
+
message+" left=#{left.inspect} right=#{right.inspect}"
|
1005
|
+
)
|
1006
|
+
print ".";$stdout.flush
|
1007
|
+
end
|
1008
|
+
|
1009
|
+
def assert_ene(left,right,message='assert_ene failed')
|
1010
|
+
assert(
|
1011
|
+
!(left===right),
|
1012
|
+
message+" left=#{left.inspect} right=#{right.inspect}"
|
1013
|
+
)
|
1014
|
+
print ",";$stdout.flush
|
1015
|
+
end
|
1016
|
+
|
1017
|
+
def test_matcher(mtr, hash)
|
1018
|
+
if list=hash[:matches]
|
1019
|
+
Array===list or list=[list]
|
1020
|
+
list.each_with_index {|data,index| assert_eee mtr, data, "item ##{index} should match" }
|
1021
|
+
end
|
1022
|
+
|
1023
|
+
if list=hash[:unmatches]
|
1024
|
+
Array===list or list=[list]
|
1025
|
+
list.each_with_index {|data,index| assert_ene mtr, data, "item ##{index} should not match" }
|
1026
|
+
end
|
1027
|
+
end
|
1028
|
+
|
1029
|
+
def test_hash_matcher (hmtr, hash)
|
1030
|
+
test_matcher(hmtr,hash)
|
1031
|
+
test_matcher(hmtr.ordered,hash)
|
1032
|
+
end
|
1033
|
+
|
1034
|
+
end
|
1035
|
+
|
1036
|
+
class AnyStruct
|
1037
|
+
def self.[] *a; new(*a) end
|
1038
|
+
def initialize(hash=nil)
|
1039
|
+
hash.each_pair{|name,val| set_field(name, val) } if hash
|
1040
|
+
end
|
1041
|
+
|
1042
|
+
def set_field(name,val)
|
1043
|
+
class<<self; self; end.instance_eval %{
|
1044
|
+
attr_accessor :#{name}
|
1045
|
+
}
|
1046
|
+
instance_variable_set "@#{name}", val
|
1047
|
+
end
|
1048
|
+
|
1049
|
+
def method_missing sym, *val
|
1050
|
+
sym=sym.to_s
|
1051
|
+
if /^(.*)=$/===sym
|
1052
|
+
set_field($1, val)
|
1053
|
+
end
|
1054
|
+
end
|
1055
|
+
end
|
1056
|
+
|
1057
|
+
end
|
1058
|
+
srand;seed=srand #most seeds work, but some don't, due to bugs in makelendata
|
1059
|
+
|
1060
|
+
|
1061
|
+
|
1062
|
+
opts=GetoptLong.new(["--seed", "-s", GetoptLong::REQUIRED_ARGUMENT],
|
1063
|
+
["--verbose","-v",GetoptLong::NO_ARGUMENT])
|
1064
|
+
verbose=false
|
1065
|
+
opts.each{|opt,arg|
|
1066
|
+
opt=='--seed' and seed=arg
|
1067
|
+
opt=='--verbose' and $verbose=true
|
1068
|
+
}
|
1069
|
+
|
1070
|
+
print "random seed is #{seed}\n"
|
1071
|
+
srand seed.to_i
|
1072
|
+
|
1073
|
+
|
1074
|
+
TC_Reg.test_reg
|
1075
|
+
#TC_Reg.test_rand_reg #causes 0*inf too often
|