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.
Files changed (64) hide show
  1. checksums.yaml +4 -0
  2. data/COPYING +0 -0
  3. data/History.txt +14 -0
  4. data/Makefile +59 -0
  5. data/README +87 -40
  6. data/article.txt +838 -0
  7. data/{assert.rb → lib/assert.rb} +3 -3
  8. data/{reg.rb → lib/reg.rb} +11 -4
  9. data/lib/reg/version.rb +21 -0
  10. data/lib/regarray.rb +455 -0
  11. data/{regarrayold.rb → lib/regarrayold.rb} +33 -7
  12. data/lib/regbackref.rb +73 -0
  13. data/lib/regbind.rb +230 -0
  14. data/{regcase.rb → lib/regcase.rb} +15 -5
  15. data/lib/regcompiler.rb +2341 -0
  16. data/{regcore.rb → lib/regcore.rb} +196 -85
  17. data/{regdeferred.rb → lib/regdeferred.rb} +35 -4
  18. data/{regposition.rb → lib/regevent.rb} +36 -38
  19. data/lib/reggraphpoint.rb +28 -0
  20. data/lib/reghash.rb +631 -0
  21. data/lib/reginstrumentation.rb +36 -0
  22. data/{regitem_that.rb → lib/regitem_that.rb} +32 -11
  23. data/{regknows.rb → lib/regknows.rb} +4 -2
  24. data/{reglogic.rb → lib/reglogic.rb} +76 -59
  25. data/{reglookab.rb → lib/reglookab.rb} +31 -21
  26. data/lib/regmatchset.rb +323 -0
  27. data/{regold.rb → lib/regold.rb} +27 -27
  28. data/{regpath.rb → lib/regpath.rb} +91 -1
  29. data/lib/regposition.rb +79 -0
  30. data/lib/regprogress.rb +1522 -0
  31. data/lib/regrepeat.rb +307 -0
  32. data/lib/regreplace.rb +254 -0
  33. data/lib/regslicing.rb +581 -0
  34. data/lib/regsubseq.rb +72 -0
  35. data/lib/regsugar.rb +361 -0
  36. data/lib/regvar.rb +180 -0
  37. data/lib/regxform.rb +212 -0
  38. data/{trace.rb → lib/trace_during.rb} +6 -4
  39. data/lib/warning.rb +37 -0
  40. data/parser.txt +26 -8
  41. data/philosophy.txt +18 -0
  42. data/reg.gemspec +58 -25
  43. data/regguide.txt +18 -0
  44. data/test/andtest.rb +46 -0
  45. data/test/regcompiler_test.rb +346 -0
  46. data/test/regdemo.rb +20 -0
  47. data/{item_thattest.rb → test/regitem_thattest.rb} +2 -2
  48. data/test/regtest.rb +2125 -0
  49. data/test/test_all.rb +32 -0
  50. data/test/test_reg.rb +19 -0
  51. metadata +108 -73
  52. data/calc.reg +0 -73
  53. data/forward_to.rb +0 -49
  54. data/numberset.rb +0 -200
  55. data/regarray.rb +0 -675
  56. data/regbackref.rb +0 -126
  57. data/regbind.rb +0 -74
  58. data/reggrid.csv +1 -2
  59. data/reghash.rb +0 -318
  60. data/regprogress.rb +0 -1054
  61. data/regreplace.rb +0 -114
  62. data/regsugar.rb +0 -230
  63. data/regtest.rb +0 -1078
  64. data/regvar.rb +0 -76
@@ -1,114 +0,0 @@
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
@@ -1,230 +0,0 @@
1
- =begin copyright
2
- reg - the ruby extended grammar
3
- Copyright (C) 2005,2009 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 DELETED
@@ -1,1078 +0,0 @@
1
- #!/usr/bin/ruby -w
2
- =begin copyright
3
- reg - the ruby extended grammar
4
- Copyright (C) 2005,2009 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].join
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
- h={}
137
- h.default=:b
138
- test_hash_matcher Rah(:a=>:b), :matches=>h
139
-
140
- $RegTraceEnable=1 #debugging zone:
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_ene( +[], [nil] )
188
- assert_eee( +[:q], [:q] )
189
- assert_eee( +[-[]], [] )
190
- assert_ene( +[-[]], [:q] )
191
- assert_ene( +[-[]], [nil] )
192
- assert_eee( +[-[:q]], [:q] )
193
- assert_eee( +[-[:q]*1], [:q] )
194
- assert_eee( +[-[:q, :q]*1], [:q,:q] )
195
- assert_eee( +[-[:q, :q]*(0..1)], [:q,:q] )
196
- assert_eee( +[-[:q, :q]*(0..2)], [:q,:q] )
197
- assert_eee( +[-[:q, :q]*(0..4)], [:q,:q] )
198
- assert_eee( +[-[:q, :q]*(0..10)], [:q,:q] )
199
- assert_eee( +[-[:q, :q]-1], [:q,:q] )
200
- assert_eee( +[:q.reg+1], [:q] )
201
- assert_eee( +[/q/+1], ['q'] )
202
- assert_eee( +[-[:q]+1], [:q] )
203
- assert_eee( +[-[:q, :q]+1], [:q,:q] )
204
- assert_eee( +[-[:q, :q]+0], [:q,:q] )
205
-
206
-
207
- lenheadalts=-[0]|-[1,OB]|-[2,OB*2]|-[3,OB*3]|-[4,OB*4]
208
- lenheadlist=lenheadalts+1
209
-
210
- lenheaddata=[0,0,0,1,:foo,4,:foo,:bar,:baz,:zork,3,:k,77,88]
211
- lenheaddataj=lenheaddata+[:j]
212
-
213
- lentailalts=-[OB,-1]|-[OB*2,-2]|-[OB*3,-3]|-[OB*4,-4]
214
- lentaildata=lenheaddata.reverse.map {|x| Integer===x ? -x : x }
215
- infixalts=-[OB,"infix1",OB]|-[OB*2,'infix2',OB*2]|
216
- -[OB*3,'infix3',OB*3]|-[OB*4,'infix4',OB*4]
217
-
218
-
219
- qq=-[:q, ~(:q.reg)+0, :q]
220
- _QQ=-[:Q, ( ~/^[Q\\]$/.sym | -[:'\\',OB] )+0, :Q]
221
-
222
-
223
- be=-[:begin, (
224
- ~/^(begin|end|\\)$/.sym |
225
- -[:'\\',OB] |
226
- innerbe=Reg.const
227
- )+0, :end]
228
- innerbe.set! be
229
-
230
- lh_or_qq=lenheadalts|qq|_QQ
231
- lhqqbe=lh_or_qq|be
232
-
233
-
234
- #most of the examples use the longer, tla form for the outermost reg....
235
- #dunno why any more. anyway, here are the basic equivalences between the
236
- #operator, tla, and long forms or Reg.
237
- #operator form
238
- assert_eee Reg::Array, +[]
239
- assert_eee Reg::Subseq, -[]
240
- assert_eee Reg::Hash, +{}
241
- assert_eee Reg::Object, -{}
242
-
243
- #tla form (square and round brackets)
244
- assert_eee Reg::Array, Reg[]
245
- assert_eee Reg::Subseq, Res[]
246
- assert_eee Reg::Hash, Rah[]
247
- assert_eee Reg::Object, Rob[]
248
-
249
- assert_eee Reg::Array, Reg()
250
- assert_eee Reg::Subseq, Res()
251
- assert_eee Reg::Hash, Rah()
252
- assert_eee Reg::Object, Rob()
253
-
254
-
255
-
256
-
257
- assert_eee( +[qq*1], [:q,:q] )
258
- assert_eee( +[qq+0], [:q,:q] )
259
-
260
- assert_eee( +_QQ, [:Q,:Q] )
261
- assert_eee( +[_QQ], [:Q,:Q] )
262
- assert_eee( +[_QQ*1], [:Q,:Q] )
263
- assert_eee( +[_QQ+0], [:Q,:Q] )
264
-
265
- assert_eee( +[be*1], [:begin,:end] )
266
- assert_eee( +[be+0], [:begin,:end] )
267
-
268
-
269
- assert_eee( +[], [] )
270
- assert_ene( +[], [1] )
271
- assert_eee( +[-[]], [] )
272
- assert_ene( +[-[]], [1] )
273
-
274
-
275
- assert_ene Reg[-[:foo,:bar]-1], [:bar,:foo]
276
- assert_ene Reg[-[:foo,:bar]-1], [:baz,:foo,:bar]
277
- assert_ene Reg[-[:foo,:bar]-1], [:foo,:bar,:baz]
278
- assert_eee Reg[-[:foo,:bar]-1], [:foo,:bar]
279
- assert_ene Reg[-[:foo,:bar]-1], [:foo]
280
- assert_ene Reg[-[:foo,:bar]-1], [:bar]
281
- assert_ene Reg[-[:foo,:bar]-1], [:baz]
282
- assert_eee Reg[-[:foo,:bar]-1], []
283
-
284
-
285
-
286
- assert_eee Reg[OB.+], [1]
287
- assert_eee Reg[OB.+], [1,2,3]
288
- assert_eee Reg[OB.-], [1]
289
- assert_ene Reg[OB.-], [1,2,3]
290
- assert_ene Reg[:a, OB-1, :b, :b, :b, :b, :b], [:a, 1,1,1,1,1,1, :b, :b, :b, :b, :b]
291
- assert_eee Reg[:a, OB-1, :b, :b, :b, :b, :b], [:a, 1, :b, :b, :b, :b, :b]
292
- assert_eee Reg[:a, OB-1, :b, :b, :b, :b, :b], [:a, :b, :b, :b, :b, :b]
293
- assert_ene Reg[:a, OB-1, :b, :b, :b, :b, :b], [1, :b, :b, :b, :b, :b]
294
- assert_ene Reg[:a, OB-1, :b, :b, :b, :b, :b], [:b, :b, :b, :b, :b]
295
- assert_ene Reg[:a, OB-1, :b, :b, :b, :b, :b], [:a, 1, :b, :b, :b, :b]
296
- assert_ene Reg[:a, OB-1, :b, :b, :b, :b, :b], [:a, :b, :b, :b, :b]
297
-
298
-
299
-
300
- if defined? NextMatchTests
301
- a=[:foo]
302
- x=(:foo.reg-1).mmatch a,0
303
- assert x.next_match(a,0)==[[[:foo]],1]
304
- assert x.next_match(a,0)==[[[]],0]
305
- assert x.next_match(a,0)==nil
306
- x=(:foo.reg-1).mmatch a,1
307
- assert x==[[[]],0]
308
-
309
- a=[:foo]
310
- x=(:foo.reg-1-1).mmatch a,0
311
- assert x.next_match(a,0)==[[[[:foo]]],1]
312
- assert x.next_match(a,0)==[[[]],0]
313
- assert x.next_match(a,0)==nil
314
-
315
-
316
-
317
-
318
-
319
-
320
- a=(1..5).to_a
321
- r=OB+1+3
322
- x=r.mmatch a,0
323
- assert x.next_match(a,0)==[[ [[1, 2, 3]], [[4]], [[5]] ], 5]
324
- assert x.next_match(a,0)==[[ [[1, 2]], [[3, 4]], [[5]] ], 5]
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]] ], 4]
328
- assert x.next_match(a,0)==[[ [[1]], [[2, 3, 4]], [[5]] ], 5]
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]], [[4, 5]] ], 5]
336
- assert x.next_match(a,0)==[[ [[1]], [[2]], [[3]], [[4]], [[5]] ], 5]
337
- assert x.next_match(a,0)==[[ [[1]], [[2]], [[3]], [[4]] ], 4]
338
- assert x.next_match(a,0)==[[ [[1]], [[2]], [[3]]], 3]
339
- assert x.next_match(a,0)==nil
340
-
341
- end
342
-
343
-
344
- assert_ene Reg[OB+1+2+2], [:f]*3
345
- assert_ene Reg[OB+2+1+2], [:f]*3
346
- assert_eee Reg[OB+1+2+2], [:f]*4
347
- assert_eee Reg[OB+2+2+1], [:f]*4
348
- assert_eee Reg[OB+2+1+2], [:f]*4
349
- assert_ene Reg[OB+2+2+2], [:f]*7
350
- assert_eee Reg[OB+2+2+2], [:f]*8
351
-
352
-
353
-
354
-
355
- assert_ene Reg[OB+2+2+3], [:f]*11
356
- assert_eee Reg[OB+2+2+3], [:f]*12
357
- assert_eee Reg[OB+2+2+3], [:f]*16
358
-
359
- assert_ene Reg[5.reg+1+3+2], [6]+[5]*5
360
- assert_ene Reg[5.reg+1+3+2], [5]+[6]+[5]*4
361
- assert_ene Reg[5.reg+1+3+2], [5]*2+[6]+[5]*3
362
- assert_ene Reg[5.reg+1+3+2], [5]*3+[6]+[5]*2
363
- assert_ene Reg[5.reg+1+3+2], [5]*4+[6,5]
364
- assert_ene Reg[5.reg+1+3+2], [5]*5+[6]
365
-
366
- assert_eee Reg[OB+1+3+2], [6]+[5]*5
367
- assert_eee Reg[OB+1+3+2], [5]+[6]+[5]*4
368
- assert_eee Reg[OB+1+3+2], [5]*2+[6]+[5]*3
369
- assert_eee Reg[OB+1+3+2], [5]*3+[6]+[5]*2
370
- assert_eee Reg[OB+1+3+2], [5]*4+[6,5]
371
- assert_eee Reg[OB+1+3+2], [5]*5+[6]
372
-
373
- assert_ene Reg[OB+1+3+2], [6]+[5]*4
374
- assert_ene Reg[OB+1+3+2], [5]+[6]+[5]*3
375
- assert_ene Reg[OB+1+3+2], [5]*2+[6]+[5]*2
376
- assert_ene Reg[OB+1+3+2], [5]*3+[6]+[5]
377
- assert_ene Reg[OB+1+3+2], [5]*4+[6]
378
-
379
-
380
- assert_eee Reg[5.reg+1+3+2], [5]*6
381
- assert_ene Reg[5.reg+2+2+2], [5]*8+[6]
382
- assert_ene Reg[:foo.reg*(1..2)*(2..3)*(2..3)], [:foo]*3
383
-
384
- assert_eee Reg[:foo.reg*(1..2)*(2..3)*(2..3)], [:foo]*4
385
- assert_ene Reg[OB*(1..2)*(2..3)*(2..3)], [:foo]*3
386
- assert_eee Reg[OB*(1..2)*(2..3)*(2..3)], [:foo]*4
387
- assert_ene Reg[OB*(1..2)*(2..3)+2], [:foo]*3
388
- assert_eee Reg[OB*(1..2)*(2..3)+2], [:foo]*4
389
- assert_ene Reg[OB+1+2+2], [:foo]*3
390
- assert_eee Reg[OB+1+2+2], [:foo]*4
391
-
392
- assert_eee Reg[OB*(1..3)*(2..3)*2], [:foo]*4
393
-
394
-
395
- if defined? NextMatchTests
396
-
397
- a=[:foo]*6
398
- x=(OB*2*(1..2)*2).mmatch(a,0)
399
- assert x.next_match(a,0)==
400
- [[ [[[:foo, :foo]], [[:foo, :foo]]], [[[:foo, :foo]]] ], 6]
401
- assert x.next_match(a,0)==
402
- [[ [[[:foo, :foo]]], [[[:foo, :foo]], [[:foo, :foo]]] ], 6]
403
- assert x.next_match(a,0)==
404
- [[ [[[:foo, :foo]]], [[[:foo, :foo]]] ], 4]
405
- assert x.next_match(a,0).nil?
406
- end
407
-
408
- #$RegTraceEnable=true
409
- assert_eee Reg[OB*2*(1..2)*2], [:foo]*6
410
- assert_eee Reg[OB*2*(1..2)*2,OB,OB], [:foo]*6
411
- assert_eee Reg[OB*2*(1..2)*2,OB*2], [:foo]*6
412
- assert_eee Reg[OB*2*(1..2)*2,OB+2], [:foo]*6
413
- assert_eee Reg[OB*2*(1..2)*2, OB-1], [:foo]*6
414
- assert_eee Reg[OB*2*(1..2)*2, OB-1], [:foo]*7
415
- assert_eee Reg[OB*2*(1..2)*2], [:foo]*8
416
- assert_eee Reg[OB*2*(1..2)*2], [:foo]*4
417
- assert_eee Reg[OB*(2..3)*(1..2)*2], [:foo]*4
418
- assert_eee Reg[OB*(2..3)*(2..3)*(1..2)], [:foo]*4
419
- assert_eee Reg[OB*(2..2)*(2..3)*(2..3)], [:foo]*8
420
- assert_eee Reg[OB*(2..3)*(2..2)*(2..3)], [:foo]*8
421
-
422
- assert_eee Reg[OB*(2..3)*(2..3)*2], [:foo]*8
423
- assert_eee Reg[OB*(2..3)*(2..3)*(2..3)], [:foo]*8
424
- assert_ene Reg[:foo.reg*(2..3)*(2..3)*2], [:foo]*7
425
-
426
- if defined? NextMatchTests
427
- assert(!(Reg[OB*1*(1..2)]===[:f]).first.empty?)
428
-
429
-
430
- a=[:foo]*4
431
- x=(OB*(1..2)+2).mmatch(a,0)
432
- assert x.next_match(a,0)==[[ [[:foo, :foo]], [[:foo, :foo]] ], 4]
433
- assert x.next_match(a,0)==[[ [[:foo, :foo]], [[:foo]], [[:foo]] ], 4]
434
- assert x.next_match(a,0)==[[ [[:foo, :foo]], [[:foo]] ], 3]
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]], [[:foo, :foo]] ], 4]
438
- assert x.next_match(a,0)==[[ [[:foo]], [[:foo]], [[:foo]], [[:foo]] ], 4]
439
- assert x.next_match(a,0)==[[ [[:foo]], [[:foo]], [[:foo]] ], 3]
440
- assert x.next_match(a,0)==[[ [[:foo]], [[:foo]] ], 2]
441
- assert x.next_match(a,0)==nil
442
- end
443
- assert_ene Reg[OB*(1..2)+2+2], [:foo]*3
444
- assert_eee Reg[OB*(1..2)+2+2], [:foo]*4
445
-
446
- if defined? NextMatchTests
447
-
448
- a=(1..9).to_a
449
- x=(OB+2+2+2).mmatch a,0
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, 9]]] ], 9]
452
- assert x.next_match(a,0)===[[ [[[1, 2]], [[3, 4]]], [[[5, 6, 7]], [[8, 9]]] ], 9]
453
- assert x.next_match(a,0)===[[ [[[1, 2]], [[3, 4]]], [[[5, 6]], [[7, 8, 9]]] ], 9]
454
- assert x.next_match(a,0)===[[ [[[1, 2]], [[3, 4]]], [[[5, 6]], [[7, 8]]] ], 8]
455
- assert x.next_match(a,0)===nil
456
- end
457
-
458
- assert_eee Reg[OB+2+2+2], [:foo]*8
459
- assert_eee Reg[OB+2+2+2, OB], [:foo]*9
460
- assert_eee Reg[OB+2+2+2, OB+1], [:foo]*9
461
- assert_eee Reg[OB+2+2+2, OB-1], [:foo]*9
462
- assert_eee Reg[OB+2+2+2], [:foo]*9
463
-
464
- if defined? NextMatchTests
465
- a=[:foo]*4
466
- x=(OB*2*(1..2)).mmatch(a,2)
467
- assert x.next_match(a,2)==[[[[:foo, :foo]]], 2]
468
- assert x.next_match(a,2)==nil
469
- end
470
-
471
- assert_eee( +[OB*(1..2)*2],[:foo]*2)
472
-
473
- if defined? NextMatchTests
474
- a=[:foo]*3
475
- x=(OB*(1..2)*2).mmatch(a,0)
476
- assert x.next_match(a,0)==
477
- [[ [[:foo, :foo]], [[:foo]] ], 3]
478
- assert x.next_match(a,0)==
479
- [[ [[:foo]], [[:foo, :foo]] ], 3]
480
- assert x.next_match(a,0)==
481
- [[ [[:foo]], [[:foo]] ], 2]
482
- assert x.next_match(a,0).nil?
483
- end
484
-
485
- assert_ene Reg[OB*(2..2)*(2..3)*(2..3)], [:foo]*7
486
- assert_ene Reg[OB*(2..3)*(2..2)*(2..3)], [:foo]*7
487
- assert_ene Reg[OB*(1..3)*(2..3)*2], [:foo]*3
488
- assert_ene Reg[OB*(2..3)*(1..3)*2], [:foo]*3
489
- assert_ene Reg[OB*(2..3)*(2..3)*(1..2)], [:foo]*3
490
-
491
- assert_ene Reg[OB*(2..3)*(2..3)*2], [:foo]*7
492
- assert_ene Reg[OB*(2..3)*(2..3)*(2..3)], [:foo]*7
493
- assert_ene Reg[OB+2+2+2], [:foo]*7
494
-
495
-
496
- assert_eee Reg[OB*2*1*2], [:foo]*4
497
- assert_eee Reg[OB*1*(1..2)*2], [:foo]*2
498
- assert_eee Reg[OB*2*(1..2)*1], [:foo]*2
499
- assert_eee Reg[OB*1*(1..2)*2], [:foo]*3
500
- assert_ene Reg[OB*2*(1..2)*1], [:foo]*3
501
- assert_eee Reg[OB*1*(1..2)*2], [:foo]*4
502
- assert_eee Reg[OB*2*(1..2)*1], [:foo]*4
503
-
504
-
505
- if defined? NextMatchTests
506
-
507
- a=[:foo]*3
508
- x=(:foo.reg*(1..2)).mmatch a,0
509
- assert x.next_match(a,0)==[[[:foo]*2],2]
510
- assert x.next_match(a,0)==[[[:foo]],1]
511
- assert x.next_match(a,0)==nil
512
-
513
- x=(:foo.reg*(1..2)).mmatch a,1
514
- assert x.next_match(a,0)==[[[:foo]*2],2]
515
- assert x.next_match(a,0)==[[[:foo]],1]
516
- assert x.next_match(a,0)==nil
517
-
518
- x=(:foo.reg*(1..2)).mmatch a,2
519
- assert x==[[[:foo]],1]
520
-
521
- x=(:foo.reg*(1..2)).mmatch a,3
522
- assert x.nil?
523
-
524
- x=(:foo.reg*(1..2)*(2..3)).mmatch a,0
525
- assert x.next_match(a,0)==[[[[:foo]*2],[[:foo]]], 3]
526
- assert x.instance_eval{@ri}==2
527
- assert x.next_match(a,0)==[[[[:foo]],[[:foo]*2]], 3]
528
- assert x.instance_eval{@ri}==2
529
- assert x.next_match(a,0)==[[[[:foo]],[[:foo]],[[:foo]]], 3]
530
- assert x.instance_eval{@ri}==3
531
- assert x.next_match(a,0)==[[[[:foo]],[[:foo]]], 2]
532
- assert x.instance_eval{@ri}==2
533
- assert x.next_match(a,0)==nil
534
-
535
- x=(:foo.reg*(1..2)*(2..3)).mmatch a,1
536
- assert x.next_match(a,0)==[[[[:foo]],[[:foo]]], 2]
537
- assert x.instance_eval{@ri}==2
538
- assert x.next_match(a,0)==nil
539
-
540
- x=(:foo.reg*(1..2)*(2..3)).mmatch a,2
541
- assert x.nil?
542
-
543
- x=(:foo.reg*(1..2)*(2..3)).mmatch a,3
544
- assert x.nil?
545
- end
546
-
547
- assert((not (:foo.reg*(1..2)*(2..3)*(2..3)).mmatch [:foo]*3,0 ))
548
-
549
-
550
-
551
-
552
- assert_eee Reg[5.reg+2+2], [5]*4
553
- assert_eee Reg[5.reg*(1..2)*(1..2)*(1..2)], [5]
554
- assert_eee Reg[5.reg*(1..2)*(1..2)*(2..3)], [5]*2
555
- assert_eee Reg[5.reg*(1..2)*(2..3)*(2..3)], [5]*4
556
- assert_eee Reg[(5.reg+1)*(2..3)*(2..3)], [5]*4
557
- assert_eee Reg[(5.reg+1+2)*(2..3)], [5]*4
558
- assert_eee Reg[5.reg+1+2+2], [5]*4
559
- assert_eee Reg[OB+3+2], [:f]*6
560
-
561
- aaa_patho=-[/^a/]|-[/^.a/, OB]|-[/^..a/, OB*2]
562
- assert_ene( +[aaa_patho], ["aaa"]*200 )
563
- assert_eee( +[aaa_patho+0], ["aaa"]*200 )
564
-
565
-
566
-
567
-
568
- assert_eee Reg[(-[-[:p]*(1..2)])], [:p]
569
- assert_eee Reg[(-[-[:p]*(1..2)])], [:p,:p]
570
- assert_ene Reg[(-[-[:p]*(1..2)])], [:p,:q]
571
- assert_ene Reg[(-[-[:p]*(1..2)])], [:q]
572
- assert_ene Reg[(-[-[:p]*(1..2)])], []
573
- assert_ene Reg[(-[-[:p]*(1..2)])], [:p,:p, :p]
574
-
575
-
576
- assert_eee Reg[OB+1], [:foo,:foo]
577
- assert_eee Reg[OB+1+1], [:foo,:foo]
578
- assert_eee Reg[OB+1+1+1], [:foo,:foo]
579
- assert_eee Reg[OB+1+1+1+1], [:foo,:foo]
580
-
581
- assert_ene Reg[OB+2+3], [:f]*5
582
- assert_ene Reg[OB+2+2+1], [:f]*3
583
-
584
- assert_eee(+[be], [
585
- :begin, :SubseqMatchSet, :IndexError, :termsig, :"\\", :ll,
586
- :end]
587
- )
588
- assert_eee(+[be+0], [
589
- :begin, :SubseqMatchSet, :IndexError, :termsig, :"\\", :begin,
590
- :end]
591
- )
592
- assert_eee(+[be+0], [
593
- :begin, :SubseqMatchSet, :IndexError, :termsig, :"\\", :end,
594
- :end]
595
- )
596
- assert_eee(+[be+0], [
597
- :begin, :SubseqMatchSet, :IndexError, :termsig, :"\\",
598
- :begin, :right, :"\\",
599
- :begin, :f, :call, :safe_level, :"\\",
600
- :begin, :undefine_finalizer, :test_anonymous, :quote,
601
- :end]
602
- )
603
- assert_eee(+[lhqqbe+0], [
604
- :begin, :SubseqMatchSet, :IndexError, :termsig, :"\\",
605
- :begin, :right, :"\\",
606
- :begin, :f, :call, :safe_level, :"\\",
607
- :begin, :undefine_finalizer, :test_anonymous, :quote,
608
- :end]
609
- )
610
-
611
- assert_eee Reg[lhqqbe+0], [
612
- :begin, :popen, :"chomp!", :-@, :end, :q, :q,
613
- :begin, :begin, :end, :end,
614
- :begin, :MINOR_VERSION, :"public_method_defined?", :"\\", :begin, :umask,
615
- :debug_print_help, :geteuid, :end,
616
- :q, :public_methods, :option_name, :MUTEX, :q,
617
- :begin, :verbose=, :binding, :symlink, :lambda,
618
- :emacs_editing_mode, :"dst?", :end, 0,
619
- :begin, :test_to_s_with_iv, :"\\", :begin, :glob, :each_with_index,
620
- :initialize_copy, :begin, :$PROGRAM_NAME, :end,
621
- :ELIBACC, :setruid, :"success?", :end,
622
- :begin, :__size__, :width, :"\\", :begin, :$-a, :"sort!", :waitpid, :end,
623
- :begin, :Stat, :WadlerExample, :chr, :end,
624
- :begin, :+, :disable, :abstract,
625
- :begin, :__size__, :"symlink?", :"dst?", :end, :ljust, :end,
626
- :begin, :debug_method_info, :matchary, :"\\", :begin, :ftype,
627
- :thread_list_all, :eof, :begin, :abs, :GroupQueue, :end,
628
- :"slice!", :ordering=, :end,
629
- :Q, :"\\", :Q, :ELIBMAX, :GetoptLong, :nlink, :Q,
630
- :begin, :Fixnum, :waitall, :"enclosed?", :"\\", :begin, :deep_copy,
631
- :getpgid, :strftime, :end,
632
- :Q, :close_obj, :Q,
633
- 3, :basic_quote_characters=, :rmdir, :"writable_real?",
634
- :begin, :test_hello_11_12, :utc_offset, :freeze,
635
- :begin, :kcode, :egid=, :ARGF, :end,
636
- :setuid, :lock, :gmtoff, :end,
637
- :begin, :$FILENAME, :test_tree_alt_20_49,
638
- :begin, :LOCK_SH, :EL3HLT, :end, :end,
639
- :Q, :"\\", :Q, :ceil, :remainder, :group_sub, :Q, 0
640
- ]
641
-
642
- if $Slow ||=false
643
- #btracing monsters
644
- assert_ene Reg[OB+1+3+2], (1..5).to_a
645
- 0.upto(5) {|i| assert_ene Reg[OB+1+3+2], [:f]*i }
646
- 6.upto(16){|i| assert_eee Reg[OB+1+3+2], [:f]*i }
647
-
648
- assert_ene Reg[OB+2+3+2], [:f]*11
649
- assert_eee Reg[OB+2+3+2], [:f]*12
650
- assert_ene Reg[OB+2+3+3], [:f]*17
651
- assert_eee Reg[OB+2+3+3], [:f]*18
652
- assert_ene Reg[OB+3+3+3], [:f]*26
653
- assert_eee Reg[OB+3+3+3], [:f]*27
654
- # assert_ene Reg[OB+4+4+4], [:f]*63 #insane
655
- # assert_eee Reg[OB+4+4+4], [:f]*64 #insane
656
- assert_ene Reg[OB+2+2+2+2], [:f]*15
657
- assert_eee Reg[OB+2+2+2+2], [:f]*16
658
- # assert_ene Reg[OB+2+2+2+2+2+2+2+2], [:foo]*255 #insane
659
- # assert_eee Reg[OB+2+2+2+2+2+2+2+2], [:foo]*256 #insane
660
-
661
-
662
- #assert_eee Reg[OB+10+10], [:f]*100 #waaaay too slow
663
- assert_eee Reg[OB+5+5], [:f]*25
664
- assert_ene Reg[OB+5+5], [:f]*24
665
- assert_eee Reg[OB+6+6], [:f]*36
666
- assert_ene Reg[OB+6+6], [:f]*35
667
- assert_eee Reg[OB+7+7], [:f]*49 #prolly excessive
668
- assert_ene Reg[OB+7+7], [:f]*48 #prolly excessive
669
-
670
- assert_ene Reg[OB+1+2+2+2], [:f]*7
671
- assert_eee Reg[OB+1+2+2+2], [:f]*8
672
- assert_ene Reg[OB+1+1+2+2+2], [:f]*7
673
- assert_eee Reg[OB+1+1+2+2+2], [:f]*8
674
- assert_ene Reg[OB+1+1+1+2+2+2], [:f]*7
675
- assert_eee Reg[OB+1+1+1+2+2+2], [:f]*8
676
-
677
- assert_ene Reg[OB+1+1+1+1+2+2+2], [:f]*7
678
- assert_eee Reg[OB+1+1+1+1+2+2+2], [:f]*8
679
-
680
- r=2..3
681
- assert_ene Reg[OB*(1..2)*r*r*r], [:f]*7
682
- assert_eee Reg[OB*(1..2)*r*r*r], [:f]*8
683
- end
684
-
685
- assert_eee Reg[lhqqbe+0], [ :begin, :"\\", :rand, :end ]
686
- #breakpoint
687
- assert_eee( +[be], [:begin, :"\\", :"\\", :end])
688
- assert_eee( +[be], [:begin, :"\\", :begin, :end])
689
- assert_eee( +[be], [:begin, :"\\", :end, :end])
690
- assert_eee( +[be], [:begin, :log, :readline, :"\\", :begin, :lh_or_qq, :test_pretty_print_inspect, :@newline, :end])
691
- assert_eee( +[be], [:begin, :lock, :rindex, :begin, :sysopen, :rename, :end, :re_exchange, :on, :end])
692
- assert_eee( +[be], [:begin, :lock, :"\\", :"\\", :begin, :rename, :end, :on, :end])
693
- assert_eee( +[be], [:begin, :begin, :foo, :end, :end])
694
- assert_eee( +[be], makelendata(1,0b11110000000).flatten)
695
- assert_eee( +[be], [:begin, :end])
696
- assert_eee( +[be], [:begin, :foo, :end])
697
- assert_eee( +[be], makelendata(1,0b10000000).flatten)
698
- assert_eee Reg[lhqqbe+0], makelendata(1,0b11111110011).flatten
699
- assert_eee Reg[lhqqbe+0], makelendata(4,0b11111110011).flatten
700
- assert_eee Reg[lhqqbe+0], makelendata(10,0b11111110011).flatten
701
- assert_eee Reg[lhqqbe+0], makelendata(20,0b11111110011).flatten
702
-
703
- assert_ene Reg[:foo,OB+1], [:foo]
704
- assert_ene Reg[OB+1,:foo], [:foo]
705
- assert_eee Reg[OB+1], [:foo]
706
-
707
-
708
- assert_eee Reg[OB+1+1+1+1+1+1+1+1+1+1+1+1+1+1], [:foo]
709
-
710
- assert_ene Reg[OB+1+1+1+1], []
711
- assert_eee Reg[OB+1+1+1+1], [:foo,:foo]
712
- assert_ene Reg[OB+2], [:foo]
713
- assert_ene Reg[OB+2+2], [:foo]*3
714
- assert_ene Reg[OB+2+2+1], [:foo]*3
715
- assert_ene Reg[OB+2+1+2], [:foo]*3
716
-
717
-
718
- assert_eee Reg[-[1,2]|3], [1,2]
719
- assert_eee Reg[-[1,2]|3], [3]
720
- assert_ene Reg[-[1,2]|3], [4]
721
- assert_ene Reg[-[1,2]|3], [2]
722
- assert_ene Reg[-[1,2]|3], [1,3]
723
-
724
- assert_eee Reg[lenheadlist], [1, :__id__]
725
- assert_eee Reg[(-[0]|-[1,OB]|-[2,OB*2])*1], [2, :p, :stat]
726
- assert_eee Reg[(-[2,OB*2])-1], [2, :p, :stat]
727
- assert_eee Reg[(-[OB])*(1..2)], [1, :p]
728
-
729
- assert_eee Reg[(-[-[:p]*(1..2)])], [:p]
730
- assert_eee Reg[(-[-[:p]])*(1..2)], [:p]
731
- assert_eee Reg[(-[-[OB]])*(1..2)], [:p]
732
- assert_eee Reg[(-[OB*1])*(1..2)], [:p]
733
- assert_eee Reg[(-[1,OB*1])*(1..2)], [1, :p]
734
- assert_eee Reg[(-[2,OB*2])*(1..2)], [2, :p, :stat]
735
- assert_eee Reg[(-[0]|-[1,OB]|-[2,OB*2])*(1..2)], [2, :p, :stat]
736
- assert_eee Reg[(-[0]|-[1,OB]|-[2,OB*2])+1], [2, :p, :stat]
737
- assert_eee Reg[lenheadlist], [2, :p, :stat]
738
- assert_eee Reg[lenheadlist], [2, :p, :stat, 1, :__id__]
739
- assert_eee Reg[lenheadlist], [2, :p, :stat, 0, 1, :__id__, 0, 0]
740
- assert_eee Reg[lenheadlist], lenheaddata
741
- assert_ene Reg[lenheadlist], lenheaddataj
742
- assert_eee( +[lh_or_qq+0], lenheaddata )
743
- assert_eee( +[lh_or_qq+0], lenheaddata+[:q, :foo, :bar, :baz, :q] )
744
-
745
- assert_eee Reg[lenheadlist], [0]
746
- assert_eee Reg[lenheadlist], makelendata(1,0b11).flatten
747
- assert_eee Reg[lenheadlist], makelendata(5,0b11).flatten
748
- assert_eee Reg[lenheadlist], makelendata(10,0b11).flatten
749
- assert_eee Reg[lenheadlist], makelendata(20,0b11).flatten
750
- assert_ene Reg[lenheadlist], makelendata(20,0b11).flatten+[:j]
751
- assert_ene Reg[lenheadlist], [:j]+makelendata(20,0b11).flatten+[:j]
752
- assert_ene Reg[lenheadlist], [:j]+makelendata(20,0b11).flatten
753
-
754
- assert_ene Reg[lenheadlist], makelendata(20,0b11,:j).flatten
755
- assert_eee( +[lh_or_qq+0], makelendata(20,0b11).flatten )
756
- assert_eee( +[lh_or_qq+0], makelendata(20,0b1000011).flatten )
757
- assert_ene( +[lh_or_qq+0], makelendata(20,0b1000011).flatten+[:j] )
758
- assert_ene( +[lh_or_qq+0], [:j]+makelendata(20,0b1000011).flatten+[:j] )
759
- assert_ene( +[lh_or_qq+0], [:j]+makelendata(20,0b1000011).flatten )
760
-
761
-
762
-
763
- t=(1..2)
764
- assert_eee Reg[OB*t*t*t*t], [:foo]*16
765
- assert_ene Reg[OB*t*t*t*t], [:foo]*17
766
- assert_eee Reg[5.reg*t], [5]
767
- assert_eee Reg[5.reg*t*1], [5]
768
- assert_eee Reg[5.reg*1*t], [5]
769
- assert_eee Reg[5.reg*t*t], [5]
770
- assert_eee Reg[5.reg*t*t*t], [5]
771
- assert_eee Reg[5.reg*t*t*t*t], [5]
772
- assert_eee Reg[5.reg+1+1+1], [5]
773
- assert_eee Reg[5.reg+1+1+1+1], [5]
774
- assert_eee Reg[OB+1+1+1], [:foo]
775
- assert_eee Reg[OB+1+1+1+1], [:foo]
776
- assert_eee Reg[OB+2], [:foo]*2
777
- assert_eee Reg[OB+2+2], [:foo]*4
778
-
779
-
780
-
781
- #btracing monsters:
782
- assert_eee Reg[OB*2], [:foo]*2
783
- assert_eee Reg[OB*2*2], [:foo]*4
784
- assert_eee Reg[OB*2*2*2*2], [:foo]*16
785
- assert_eee Reg[OB*2*2*2*2*2*2*2*2], [:foo]*256
786
- assert_eee Reg[OB-2-2-2-2-2-2-2-2], [:foo]*256
787
-
788
-
789
-
790
- assert_ene Reg[OB-0], [1]
791
- assert_eee Reg[OB+0], [1]
792
- assert_eee Reg[OB-1], [1]
793
- assert_eee Reg[OB+1], [1]
794
- assert_eee Reg[OB-2], [1,2]
795
- assert_eee Reg[OB+2], [1,2]
796
-
797
- assert_eee Reg[OB], [1]
798
- assert_eee Reg[OB*1], [1]
799
- assert_eee Reg[OB*2], [1,2]
800
- assert_eee Reg[OB*4], [1,2,3,4]
801
-
802
- abcreg=Reg[OBS,:a,:b,:c,OBS]
803
- assert_eee abcreg, [:a,:b,:c,7,8,9]
804
- assert_eee abcreg, [1,2,3,:a,:b,:c,7,8,9]
805
-
806
- assert_eee abcreg, [1,2,3,:a,:b,:c]
807
- assert_eee abcreg, [:a,:b,:c]
808
-
809
- assert_ene abcreg, [1,2,3,:a,:b,:d]
810
- assert_ene abcreg, [1,2,3,:a,:d,:c]
811
- assert_ene abcreg, [1,2,3,:d,:b,:c]
812
-
813
- assert_ene abcreg, [1,2,3]
814
- assert_ene abcreg, [1,2,3,:a]
815
- assert_ene abcreg, [1,2,3,:a,:b]
816
-
817
- assert_eee Reg[:a, OB+0, :b, :b, :b, :b, :b], [:a, 1,1,1,1,1,1, :b, :b, :b, :b, :b]
818
- assert_eee Reg[:a, OB+0, :b, :b, :b, :b, :b], [:a, 1, :b, :b, :b, :b, :b]
819
- assert_eee Reg[:a, OB+0, :b, :b, :b, :b, :b], [:a, :b, :b, :b, :b, :b]
820
-
821
- assert_eee Reg[:a, OB+1, :b, :b, :b, :b, :b], [:a, 1,1,1,1,1,1, :b, :b, :b, :b, :b]
822
- assert_eee Reg[:a, OB+1, :b, :b, :b, :b, :b], [:a, 1, :b, :b, :b, :b, :b]
823
- assert_ene Reg[:a, OB+1, :b, :b, :b, :b, :b], [:a, :b, :b, :b, :b, :b]
824
-
825
- assert_ene Reg[:a, OB-0, :b, :b, :b, :b, :b], [:a, 1,1,1,1,1,1, :b, :b, :b, :b, :b]
826
- assert_ene Reg[:a, OB-0, :b, :b, :b, :b, :b], [:a, 1, :b, :b, :b, :b, :b]
827
- assert_eee Reg[:a, OB-0, :b, :b, :b, :b, :b], [:a, :b, :b, :b, :b, :b]
828
-
829
- assert_eee Reg[-[OB*2]], [99, 99] #di not right in top level
830
- assert_eee Reg[-[-[-[-[-[OB*2]]]]]], [99, 99] #di not right in top level?
831
- assert_eee Reg[-[-[-[-[-[OB*1]]]]]], [99] #di not right in top level?
832
- #RR[RR[[RR[RR[RR[RR[99,99]]]]]]]
833
- assert_eee Reg[OB*1], [:foo]
834
- assert_eee Reg[-[OB]], [88]
835
- assert_ene Reg[-[0]], [88]
836
- assert_eee Reg[-[0]], [0]
837
- assert_eee Reg[-[OB*1]], [:foo]
838
- assert_eee Reg[OB*1*1], [:foo]
839
- assert_eee Reg[OB*1*1*1*1*1*1*1*1*1*1*1*1*1*1], [:foo]
840
- assert_eee Reg[OB-1-1-1-1-1-1-1-1-1-1-1-1-1-1], [:foo]
841
- assert_eee Reg[-[2,OB*2]], [2, 99, 99]
842
-
843
- assert_eee Reg::Multiple, -[0]|-[1,2]
844
- assert( (-[0]|-[1,2]).respond_to?( :mmatch))
845
-
846
- assert_eee Reg[-[0],OBS], lenheaddataj
847
- assert_eee Reg[-[0]|-[1,OB],OBS], lenheaddataj
848
- assert_eee Reg[-[0]|-[1,OB]|-[2,OB*2],OBS], lenheaddataj
849
- assert_eee Reg[-[0]|-[1,OB]|-[2,OB*2]|-[3,OB*3],OBS], lenheaddataj
850
- assert_eee Reg[-[0]|-[1,OB]|-[2,OB*2]|-[3,OB*3]|-[4,OB*4],OBS], lenheaddataj
851
-
852
-
853
-
854
- test_hash_matcher Rah(:a=>:b), :matches=>[{:a=>:b}],
855
- :unmatches=>[ {:a=>:c}, {} ] #=> false
856
-
857
- h={}
858
- h.default=:b
859
- test_hash_matcher Rah(:a=>:b), :matches=>h, :unmatches=>{}
860
-
861
- test_hash_matcher Rah(/^(a|b)$/=>33),
862
- :matches=>[{"a"=>33}, {"b"=>33}, {"a"=>33,"b"=>33} ],
863
- :unmatches=>[
864
- {"a"=>33,"c"=>33},
865
- {"b"=>33,"c"=>33}, {"a"=>33,"c"=>133}, {"b"=>33,"c"=>133}, {"a"=>133}, {"b"=>133} ,
866
- {"c"=>33}, {"c"=>133} , {"a"=>33,"b"=>133}, {"a"=>133,"b"=>33}, {"a"=>133,"b"=>133}
867
- ]
868
-
869
- =begin disabled.... Reg::Hash#|(Hash) not special anymore
870
- assert_eee Rah("a"=>33)|{"b"=>33}, {"a"=>33,"b"=>33} #=> true
871
- assert_eee Rah("a"=>33)|{"b"=>33}, {"a"=>33,"b"=>133} #=> true
872
- assert_ene Rah("a"=>33)|{"b"=>33}, {"a"=>133,"b"=>33} #=> false
873
- assert_ene Rah("a"=>33)|{"b"=>33}, {"a"=>133,"b"=>133} #=> false
874
-
875
- assert_eee Rah("a"=>33)|{"b"=>33}, {"b"=>33} #=> true
876
- =end
877
- test_hash_matcher Rah(:a.reg|:b => 44), :matches=>[{:a => 44},{:b => 44}],
878
- :unmatches=> [{:a => 144}, {:b => 144}]
879
-
880
- #object matcher tests
881
- ob=AnyStruct[:aa=>1,:b=>"foob",:c=>[1,2,3]]
882
- assert_eee Rob(:aa=>1), ob
883
- assert_eee Rob(:@aa=>1), ob
884
- assert_eee Rob(:aa=>1,:b=>/foo/), ob
885
- assert_eee Rob(:@aa=>1,:@b=>/foo/), ob
886
-
887
- assert_ene Rob(:aa=>Float), ob
888
- assert_ene Rob(:@aa=>Float), ob
889
- assert_ene Rob(:aa=>1,:b=>/fu/), ob
890
- assert_ene Rob(:@aa=>1,:@b=>/fu/), ob
891
-
892
- assert_eee Rob(), ob
893
- assert_ene Rob(:d=>item_that.size>33), ob
894
-
895
-
896
- assert_eee Rob(/aa$/=>1), ob
897
- #assert_eee Rob(/@aa/=>1), ob
898
- assert_eee Rob(/aa$/=>1,:b=>/foo/), ob
899
- #assert_eee Rob(/@aa/=>1,:@b=>/foo/), ob
900
-
901
- assert_ene Rob(/aab$/=>1), ob
902
- assert_ene Rob(/aab$/=>1,:b=>/foo/), ob
903
-
904
- assert_ene Rob(/aa$/=>Float), ob
905
- #assert_ene Rob(/@aa/=>Float), ob
906
- assert_ene Rob(/aa$/=>1,:b=>/fu/), ob
907
- #assert_ene Rob(/@aa/=>1,:@b=>/fu/), ob
908
-
909
- assert_ene Rob(/ddd/=>item_that.size>33), ob
910
-
911
- assert_eee Rob(/aa$/=>1,:b=>/foo/,:@c=>OB), ob
912
- #assert_eee Rob(/@aa/=>1,:@b=>/foo/,OB=>item_that.size<33), ob
913
- #assert_eee Rob(/@aa/=>1,:@b=>/foo/,:@c=>Array,OB=>nil), ob
914
-
915
- assert_ene Rob(/a$/=>1,:bb=>/foo/,:@c=>OB), ob
916
- #assert_ene Rob(/@a/=>1,:@b=>/foo/,OB=>item_that.size>33), ob
917
- #assert_ene Rob(/@a/=>1,:@b=>/foo/,:@c=>Array,OB=>Symbol), ob
918
-
919
- #Matches array containing exactly 2 elements; 1st is another array, 2nd is
920
- #integer:
921
- assert_eee( +[Array,Integer], [["ee"],555])
922
-
923
- #Like above, but 1st is array of arrays of symbol
924
- assert_eee( +[+[+[Symbol+0]+0],Integer], [[[:foo,:bar],[:baz,:bof]], 0])
925
-
926
- #Matches array of at least 3 consecutive symbols and nothing else:
927
- assert_ene( +[Symbol+3], [:hop]*2)
928
- assert_eee( +[Symbol+3], [:hop]*3)
929
- assert_eee( +[Symbol+3], [:hop]*4)
930
-
931
- #Matches array with at least 3 (consecutive) symbols in it somewhere:
932
- assert_eee( +[OBS, Symbol+3, OBS], [Module, nil, 1, "o", :g, [66,77], {888=>999}, :a, :b, :c])
933
- assert_eee( +[OBS, Symbol+3, OBS], [Module, nil, 1, :a, :b, :c, "o", :g, [66,77], {888=>999}])
934
- assert_ene( +[OBS, Symbol+3, OBS], [Module, nil, 1, :a, :b, "o", :g, [66,77], {888=>999}])
935
- assert_eee( +[OBS, Symbol+3, OBS], [:a, :b, :c, Module, nil, 1, "o", :g, [66,77], {888=>999}])
936
-
937
- #Matches array of at most 6 strings starting with 'g'
938
- assert_eee( +[/^g/-6], [])
939
- assert_eee( +[/^g/-6], ["gh"])
940
- assert_eee( +[/^g/-6], ["gh","gg"])
941
- assert_eee( +[/^g/-6], ["gh","gg", "gf"])
942
- assert_eee( +[/^g/-6], ["gh","gg", "gf", "ge"])
943
- assert_eee( +[/^g/-6], ["gh","gg", "gf", "ge","gd"])
944
- assert_eee( +[/^g/-6], ["gh","gg", "gf", "ge","gd","gc"])
945
- assert_ene( +[/^g/-6], ["gh","gg", "gf", "ge","gd","gc","gd"])
946
-
947
- #Matches array of between 5 and 9 hashes containing a key :k pointing to
948
- #something non-nil:
949
- h={:k=>true}
950
- assert_eee( +h, h)
951
- assert_eee( +{:k=>OB}, h)
952
- assert_eee( +{:k=>~nil.reg}, h)
953
- assert_ene( +[ +{:k=>~nil.reg}*(5..9) ], [h,h,h,h])
954
- assert_eee( +[ +{:k=>~nil.reg}*(5..9) ], [h,h,h,h,h])
955
- assert_eee( +[ +{:k=>~nil.reg}*(5..9) ], [h,h,h,h,h,h])
956
- assert_eee( +[ +{:k=>~nil.reg}*(5..9) ], [h,h,h,h,h,h,h])
957
- assert_eee( +[ +{:k=>~nil.reg}*(5..9) ], [h,h,h,h,h,h,h,h])
958
- assert_eee( +[ +{:k=>~nil.reg}*(5..9) ], [h,h,h,h,h,h,h,h,h])
959
- assert_ene( +[ +{:k=>~nil.reg}*(5..9) ], [h,h,h,h,h,h,h,h,h,h])
960
-
961
- #Matches an object with Integer instance variable @k and property (ie method)
962
- #foobar that returns a string with 'baz' somewhere in it:
963
- assert_eee( -{:@k=>Integer, :foobar=>/baz/}, AnyStruct[:k=>5, :foobar=>"kla-baz"])
964
-
965
- #Matches array of 6 hashes with 6 as a value of every key, followed by
966
- #18 objects with an attribute @s which is a String:
967
- test_matcher( +[ +{OB=>6}*6 ], :matches=>[[ {:a=>6},{:a=>6,:b=>6},{:a=>6,:b=>6,:c=>6},{:hodd=>6},
968
- {:tuber=>6.0}, {:xxx=>6, :e=>6} ]])
969
- test_matcher( +[ +{OB=>6}*6, -{:@s=>String}*18 ],
970
- :matches=>[ [ {:a=>6},{:a=>6,:b=>6},{:a=>6,:b=>6,:c=>6},{:hodd=>6},
971
- {:tuber=>6.0}, {:xxx=>6, :e=>6}, *[AnyStruct[:s=>"66"]]*18 ]
972
- ],
973
- :unmatches=>[
974
- [ {:a=>6},{:a=>6,:b=>6},{:a=>6,:b=>6,:c=>6},{:hodd=>6},
975
- {:tuber=>6.0}, {:xxx=>6, :e=>6}, *[AnyStruct[:s=>"66"]]*17 ],
976
- [ {:a=>6},{:a=>6,:b=>6},{:a=>6,:b=>6,:c=>6},{:hodd=>6},
977
- {:tuber=>6.0}, {:xxx=>6, :e=>6}, *[AnyStruct[:s=>"66"]]*19 ],
978
- [ {:a=>6},{:a=>5,:b=>6},{:a=>4,:b=>5,:c=>6},{:hodd=>6},
979
- {:tuber=>6.0}, {:xxx=>"t", :e=>6}, *[AnyStruct[:s=>"66"]]*18 ]
980
- ]
981
- )
982
-
983
- test_hash_matcher( +{OB=>6}, :unmatches=>{} )
984
-
985
- test_hash_matcher +{/fo+/=>8, /ba+r/=>9}, :matches=> {"foo"=>8,"bar"=>9}
986
-
987
- test_matcher +[/fo+/**8, /ba+r/**9],
988
- :matches=> [{"foobar"=>8, "bar"=>9},{"foo"=>8,"bar"=>9}],
989
- :unmatches=> {"foobar"=>9, "bar"=>9}
990
-
991
-
992
-
993
- print "\n"
994
- end
995
-
996
- def disabled_test_subst
997
- #insert ';)' after even elements of an array
998
- +[-[ OB>>:even << -[BR[:even],';)'], OB]+0, OB.-]
999
- #be nice to abbreviate this to:
1000
- #+[-[ OB<<-[BR[],';)'], OB ]+0, OB.-]
1001
- end
1002
-
1003
-
1004
- def assert_eee(left,right,message='assert_eee failed')
1005
- assert(
1006
- left===right,
1007
- message+" left=#{left.inspect} right=#{right.inspect}"
1008
- )
1009
- print ".";$stdout.flush
1010
- end
1011
-
1012
- def assert_ene(left,right,message='assert_ene failed')
1013
- assert(
1014
- !(left===right),
1015
- message+" left=#{left.inspect} right=#{right.inspect}"
1016
- )
1017
- print ",";$stdout.flush
1018
- end
1019
-
1020
- def test_matcher(mtr, hash)
1021
- if list=hash[:matches]
1022
- Array===list or list=[list]
1023
- list.each_with_index {|data,index| assert_eee mtr, data, "item ##{index} should match" }
1024
- end
1025
-
1026
- if list=hash[:unmatches]
1027
- Array===list or list=[list]
1028
- list.each_with_index {|data,index| assert_ene mtr, data, "item ##{index} should not match" }
1029
- end
1030
- end
1031
-
1032
- def test_hash_matcher (hmtr, hash)
1033
- test_matcher(hmtr,hash)
1034
- test_matcher(hmtr.ordered,hash)
1035
- end
1036
-
1037
- end
1038
-
1039
- class AnyStruct
1040
- def self.[] *a; new(*a) end
1041
- def initialize(hash=nil)
1042
- hash.each_pair{|name,val| set_field(name, val) } if hash
1043
- end
1044
-
1045
- def set_field(name,val)
1046
- class<<self; self; end.instance_eval %{
1047
- attr_accessor :#{name}
1048
- }
1049
- instance_variable_set "@#{name}", val
1050
- end
1051
-
1052
- def method_missing sym, *val
1053
- sym=sym.to_s
1054
- if /^(.*)=$/===sym
1055
- set_field($1, val)
1056
- end
1057
- end
1058
- end
1059
-
1060
- end
1061
- srand;seed=srand #most seeds work, but some don't, due to bugs in makelendata
1062
-
1063
-
1064
-
1065
- opts=GetoptLong.new(["--seed", "-s", GetoptLong::REQUIRED_ARGUMENT],
1066
- ["--verbose","-v",GetoptLong::NO_ARGUMENT])
1067
- verbose=false
1068
- opts.each{|opt,arg|
1069
- opt=='--seed' and seed=arg
1070
- opt=='--verbose' and $verbose=true
1071
- }
1072
-
1073
- print "random seed is #{seed}\n"
1074
- srand seed.to_i
1075
-
1076
-
1077
- TC_Reg.test_reg
1078
- #TC_Reg.test_rand_reg #causes 0*inf too often