rogue_parser 1.0.1
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/.autotest +38 -0
- data/History.txt +5 -0
- data/Manifest.txt +9 -0
- data/README.txt +76 -0
- data/Rakefile +134 -0
- data/lib/ruby_lexer.rb +1329 -0
- data/lib/ruby_parser.rb +5343 -0
- data/lib/ruby_parser.y +1656 -0
- data/lib/ruby_parser_extras.rb +725 -0
- data/test/test_ruby_lexer.rb +1766 -0
- data/test/test_ruby_parser.rb +394 -0
- data/test/test_ruby_parser_extras.rb +177 -0
- metadata +87 -0
@@ -0,0 +1,394 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'ruby_parser'
|
5
|
+
|
6
|
+
$: << File.expand_path('~/Work/p4/zss/src/ParseTree/dev/lib')
|
7
|
+
$: << File.expand_path('~/Work/p4/zss/src/ParseTree/dev/test')
|
8
|
+
|
9
|
+
require 'pt_testcase'
|
10
|
+
|
11
|
+
class TestRubyParser < Test::Unit::TestCase # ParseTreeTestCase
|
12
|
+
|
13
|
+
# Regular ParseTreeTestCase tests
|
14
|
+
eval ParseTreeTestCase.testcases.map { |node, data|
|
15
|
+
next if node.to_s =~ /bmethod|dmethod/
|
16
|
+
next if Array === data['Ruby'] # runtime only crap
|
17
|
+
"def test_#{node}
|
18
|
+
rb = #{data['Ruby'].inspect}
|
19
|
+
pt = #{data['ParseTree'].inspect}
|
20
|
+
|
21
|
+
assert_not_nil rb, \"Ruby for #{node} undefined\"
|
22
|
+
assert_not_nil pt, \"ParseTree for #{node} undefined\"
|
23
|
+
|
24
|
+
assert_equal Sexp.from_array(pt), @processor.parse(rb)
|
25
|
+
end"
|
26
|
+
}.compact.join("\n")
|
27
|
+
|
28
|
+
if false then
|
29
|
+
require 'parse_tree'
|
30
|
+
|
31
|
+
# Regular ParseTreeTestCase tests
|
32
|
+
eval ParseTreeTestCase.testcases.map { |node, data|
|
33
|
+
next if node.to_s =~ /bmethod|dmethod/
|
34
|
+
next if Array === data['Ruby'] # runtime only crap
|
35
|
+
"def test_nl_#{node}
|
36
|
+
rb = #{data['Ruby'].inspect}
|
37
|
+
pt = ParseTree.new(true).parse_tree_for_string(rb).first
|
38
|
+
|
39
|
+
assert_not_nil rb, \"Ruby for #{node} undefined\"
|
40
|
+
assert_not_nil pt, \"ParseTree for #{node} undefined\"
|
41
|
+
|
42
|
+
assert_equal Sexp.from_array(pt), @processor.parse(rb)
|
43
|
+
end"
|
44
|
+
}.compact.join("\n")
|
45
|
+
end
|
46
|
+
|
47
|
+
# Scour the world and compare against ParseTree
|
48
|
+
if ENV['ZOMGPONIES'] or File.exist? 'zomgponies' then
|
49
|
+
require 'parse_tree'
|
50
|
+
|
51
|
+
base = "/usr/lib/ruby"
|
52
|
+
base = "unit"
|
53
|
+
|
54
|
+
files = Dir[File.join(base, "**/*.rb")]
|
55
|
+
|
56
|
+
# these files/patterns cause parse_tree_show to bus error (or just suck):
|
57
|
+
files.reject! { |f| f =~ /environments.environment|rss.maker.base|rails_generator|ferret.browser|rubinius.spec.core.module.(constants|name|remove_const)_spec|tkextlib.tcllib.tablelist/ }
|
58
|
+
|
59
|
+
# these are rejected for dasgn_curr ordering failures... I'll fix them later.
|
60
|
+
# (or mri parse errors--I should have separated them out)
|
61
|
+
files.reject! { |f| f =~ /lib.flog|lib.autotest.notify|lib.analyzer.tools.rails.stat|flog.lib.flog|rakelib.struct.generator|rubinius.kernel.core.array|lib.rbosa.rb|src.rbosa.rb|spec.spec.mocks.mock.spec.rb|dsl.shared.behaviour.spec.rb|spec.spec.dsl.behaviour.spec|lib.hpricot.parse.rb|resolve.rb|parsers.parse.f95|rubinius.shotgun.lib.primitives.ltm|rubinius.lib.bin.compile|rubinius.kernel.core.object|rubinius.kernel.core.file|rubinius.compiler2.garnet.bindingagent|ruby_to_c_test_r2ctestcase|lib.more.like.this|resolv\.rb|test.r2ctestcase/ }
|
62
|
+
|
63
|
+
warn "Generating #{files.size} tests from #{base}"
|
64
|
+
|
65
|
+
eval files.map { |file|
|
66
|
+
name = file[base.size..-1].gsub(/\W+/, '_')
|
67
|
+
|
68
|
+
loc = `wc -l #{file}`.strip.to_i
|
69
|
+
|
70
|
+
"def test#{name}_#{loc}
|
71
|
+
file = #{file.inspect}
|
72
|
+
rb = File.read(file)
|
73
|
+
|
74
|
+
pt = ParseTree.new.parse_tree_for_string rb
|
75
|
+
assert_not_nil pt, \"ParseTree for #{name} undefined\"
|
76
|
+
|
77
|
+
rp = @processor.parse rb
|
78
|
+
assert_equal Sexp.from_array(pt).first, rp, \"RP different from PT\"
|
79
|
+
File.unlink #{file.inspect}
|
80
|
+
end"
|
81
|
+
}.compact.join("\n")
|
82
|
+
end
|
83
|
+
|
84
|
+
def setup
|
85
|
+
super
|
86
|
+
|
87
|
+
# puts self.name
|
88
|
+
|
89
|
+
@processor = RubyParser.new
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_block_append
|
93
|
+
head = s(:args)
|
94
|
+
tail = s(:zsuper)
|
95
|
+
expected = s(:block, s(:args), s(:zsuper))
|
96
|
+
assert_equal expected, @processor.block_append(head, tail)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_block_append_begin_begin
|
100
|
+
head = s(:begin, s(:args))
|
101
|
+
tail = s(:begin, s(:args))
|
102
|
+
expected = s(:block, s(:args), s(:begin, s(:args)))
|
103
|
+
assert_equal expected, @processor.block_append(head, tail)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_block_append_block
|
107
|
+
head = s(:block, s(:args))
|
108
|
+
tail = s(:zsuper)
|
109
|
+
expected = s(:block, s(:args), s(:zsuper))
|
110
|
+
assert_equal expected, @processor.block_append(head, tail)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_block_append_nil_head
|
114
|
+
head = nil
|
115
|
+
tail = s(:zsuper)
|
116
|
+
expected = s(:zsuper)
|
117
|
+
assert_equal expected, @processor.block_append(head, tail)
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_block_append_nil_tail
|
121
|
+
head = s(:args)
|
122
|
+
tail = nil
|
123
|
+
expected = s(:args)
|
124
|
+
assert_equal expected, @processor.block_append(head, tail)
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_block_append_tail_block
|
128
|
+
head = s(:vcall, :f1)
|
129
|
+
tail = s(:block, s(:undef, s(:lit, :x)), s(:undef, s(:lit, :y)))
|
130
|
+
expected = s(:block,
|
131
|
+
s(:vcall, :f1),
|
132
|
+
s(:block, s(:undef, s(:lit, :x)), s(:undef, s(:lit, :y))))
|
133
|
+
assert_equal expected, @processor.block_append(head, tail)
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_call_env
|
137
|
+
@processor.env[:a] = :lvar
|
138
|
+
expected = s(:call, s(:lvar, :a), :happy)
|
139
|
+
|
140
|
+
assert_equal expected, @processor.parse('a.happy')
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_dasgn_icky2
|
144
|
+
rb = "a do\n v = nil\n begin\n yield\n rescue Exception => v\n break\n end\nend"
|
145
|
+
pt = s(:iter,
|
146
|
+
s(:fcall, :a),
|
147
|
+
nil,
|
148
|
+
s(:block,
|
149
|
+
s(:dasgn_curr, :v, s(:nil)),
|
150
|
+
s(:begin,
|
151
|
+
s(:rescue,
|
152
|
+
s(:yield),
|
153
|
+
s(:resbody,
|
154
|
+
s(:array, s(:const, :Exception)),
|
155
|
+
s(:block, s(:dasgn_curr, :v, s(:gvar, :$!)), s(:break)))))))
|
156
|
+
|
157
|
+
assert_equal pt, @processor.parse(rb)
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_class_comments
|
161
|
+
rb = "# blah 1\n# blah 2\n\nclass X\n # blah 3\n def blah\n # blah 4\n end\nend"
|
162
|
+
pt = s(:class, :X, nil,
|
163
|
+
s(:scope,
|
164
|
+
s(:defn, :blah, s(:scope, s(:block, s(:args), s(:nil))))))
|
165
|
+
|
166
|
+
actual = @processor.parse(rb)
|
167
|
+
assert_equal pt, actual
|
168
|
+
|
169
|
+
assert_equal "# blah 1\n# blah 2\n\n", actual.comments
|
170
|
+
assert_equal "# blah 3\n", actual.scope.defn.comments
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_module_comments
|
174
|
+
rb = "# blah 1\n \n # blah 2\n\nmodule X\n # blah 3\n def blah\n # blah 4\n end\nend"
|
175
|
+
pt = s(:module, :X,
|
176
|
+
s(:scope,
|
177
|
+
s(:defn, :blah, s(:scope, s(:block, s(:args), s(:nil))))))
|
178
|
+
|
179
|
+
actual = @processor.parse(rb)
|
180
|
+
assert_equal pt, actual
|
181
|
+
assert_equal "# blah 1\n\n# blah 2\n\n", actual.comments
|
182
|
+
assert_equal "# blah 3\n", actual.scope.defn.comments
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_defn_comments
|
186
|
+
rb = "# blah 1\n# blah 2\n\ndef blah\nend"
|
187
|
+
pt = s(:defn, :blah, s(:scope, s(:block, s(:args), s(:nil))))
|
188
|
+
|
189
|
+
actual = @processor.parse(rb)
|
190
|
+
assert_equal pt, actual
|
191
|
+
assert_equal "# blah 1\n# blah 2\n\n", actual.comments
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_defs_comments
|
195
|
+
rb = "# blah 1\n# blah 2\n\ndef self.blah\nend"
|
196
|
+
pt = s(:defs, s(:self), :blah, s(:scope, s(:args)))
|
197
|
+
|
198
|
+
actual = @processor.parse(rb)
|
199
|
+
assert_equal pt, actual
|
200
|
+
assert_equal "# blah 1\n# blah 2\n\n", actual.comments
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_do_bug # TODO: rename
|
204
|
+
rb = "a 1\na.b do |c|\n # do nothing\nend"
|
205
|
+
pt = s(:block,
|
206
|
+
s(:fcall, :a, s(:array, s(:lit, 1))),
|
207
|
+
s(:iter, s(:call, s(:vcall, :a), :b), s(:dasgn_curr, :c)))
|
208
|
+
|
209
|
+
assert_equal pt, @processor.parse(rb)
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_dstr_evstr
|
213
|
+
rb = "\"#\{'a'}#\{b}\""
|
214
|
+
pt = s(:dstr, "a", s(:evstr, s(:vcall, :b)))
|
215
|
+
|
216
|
+
assert_equal pt, @processor.parse(rb)
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_dstr_str
|
220
|
+
rb = "\"#\{'a'} b\""
|
221
|
+
pt = s(:str, "a b")
|
222
|
+
|
223
|
+
assert_equal pt, @processor.parse(rb)
|
224
|
+
end
|
225
|
+
|
226
|
+
def test_empty
|
227
|
+
rb = ""
|
228
|
+
pt = nil
|
229
|
+
|
230
|
+
assert_equal pt, @processor.parse(rb)
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_evstr_evstr
|
234
|
+
rb = "\"#\{a}#\{b}\""
|
235
|
+
pt = s(:dstr, "", s(:evstr, s(:vcall, :a)), s(:evstr, s(:vcall, :b)))
|
236
|
+
|
237
|
+
assert_equal pt, @processor.parse(rb)
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_evstr_str
|
241
|
+
rb = "\"#\{a} b\""
|
242
|
+
pt = s(:dstr, "", s(:evstr, s(:vcall, :a)), s(:str, " b"))
|
243
|
+
|
244
|
+
assert_equal pt, @processor.parse(rb)
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_lasgn_env
|
248
|
+
rb = 'a = 42'
|
249
|
+
pt = s(:lasgn, :a, s(:lit, 42))
|
250
|
+
expected_env = { :a => :lvar }
|
251
|
+
|
252
|
+
assert_equal pt, @processor.parse(rb)
|
253
|
+
assert_equal expected_env, @processor.env.all
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_list_append
|
257
|
+
lhs, rhs = s(:array, s(:lit, :iter)), s(:when, s(:const, :BRANCHING), nil)
|
258
|
+
expected = s(:array, s(:lit, :iter), s(:when, s(:const, :BRANCHING), nil))
|
259
|
+
|
260
|
+
assert_equal expected, @processor.list_append(lhs, rhs)
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_literal_concat_dstr_dstr
|
264
|
+
lhs = s(:dstr, "Failed to download spec ",
|
265
|
+
s(:evstr, s(:vcall, :spec_name)),
|
266
|
+
s(:str, " from "),
|
267
|
+
s(:evstr, s(:vcall, :source_uri)),
|
268
|
+
s(:str, ":\n"))
|
269
|
+
rhs = s(:dstr, "\t",
|
270
|
+
s(:evstr, s(:call, s(:ivar, :@fetch_error), :message)))
|
271
|
+
expected = s(:dstr, "Failed to download spec ",
|
272
|
+
s(:evstr, s(:vcall, :spec_name)),
|
273
|
+
s(:str, " from "),
|
274
|
+
s(:evstr, s(:vcall, :source_uri)),
|
275
|
+
s(:str, ":\n"),
|
276
|
+
s(:str, "\t"),
|
277
|
+
s(:evstr, s(:call, s(:ivar, :@fetch_error), :message)))
|
278
|
+
|
279
|
+
assert_equal expected, @processor.literal_concat(lhs, rhs)
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_literal_concat_dstr_evstr
|
283
|
+
lhs, rhs = s(:dstr, "a"), s(:evstr, s(:vcall, :b))
|
284
|
+
expected = s(:dstr, "a", s(:evstr, s(:vcall, :b)))
|
285
|
+
|
286
|
+
assert_equal expected, @processor.literal_concat(lhs, rhs)
|
287
|
+
end
|
288
|
+
|
289
|
+
def test_literal_concat_evstr_evstr
|
290
|
+
lhs, rhs = s(:evstr, s(:lit, 1)), s(:evstr, s(:lit, 2))
|
291
|
+
expected = s(:dstr, "", s(:evstr, s(:lit, 1)), s(:evstr, s(:lit, 2)))
|
292
|
+
|
293
|
+
assert_equal expected, @processor.literal_concat(lhs, rhs)
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_literal_concat_str_evstr
|
297
|
+
lhs, rhs = s(:str, ""), s(:evstr, s(:str, "blah"))
|
298
|
+
|
299
|
+
assert_equal s(:str, "blah"), @processor.literal_concat(lhs, rhs)
|
300
|
+
end
|
301
|
+
|
302
|
+
def test_logop_12
|
303
|
+
lhs = s(:lit, 1)
|
304
|
+
rhs = s(:lit, 2)
|
305
|
+
exp = s(:and, s(:lit, 1), s(:lit, 2))
|
306
|
+
|
307
|
+
assert_equal exp, @processor.logop(:and, lhs, rhs)
|
308
|
+
end
|
309
|
+
|
310
|
+
def test_logop_1234_5
|
311
|
+
lhs = s(:and, s(:lit, 1), s(:and, s(:lit, 2), s(:and, s(:lit, 3), s(:lit, 4))))
|
312
|
+
rhs = s(:lit, 5)
|
313
|
+
exp = s(:and,
|
314
|
+
s(:lit, 1),
|
315
|
+
s(:and,
|
316
|
+
s(:lit, 2),
|
317
|
+
s(:and,
|
318
|
+
s(:lit, 3),
|
319
|
+
s(:and,
|
320
|
+
s(:lit, 4),
|
321
|
+
s(:lit, 5)))))
|
322
|
+
|
323
|
+
assert_equal exp, @processor.logop(:and, lhs, rhs)
|
324
|
+
end
|
325
|
+
|
326
|
+
def test_logop_123_4
|
327
|
+
lhs = s(:and, s(:lit, 1), s(:and, s(:lit, 2), s(:lit, 3)))
|
328
|
+
rhs = s(:lit, 4)
|
329
|
+
exp = s(:and,
|
330
|
+
s(:lit, 1),
|
331
|
+
s(:and,
|
332
|
+
s(:lit, 2),
|
333
|
+
s(:and,
|
334
|
+
s(:lit, 3),
|
335
|
+
s(:lit, 4))))
|
336
|
+
|
337
|
+
assert_equal exp, @processor.logop(:and, lhs, rhs)
|
338
|
+
end
|
339
|
+
|
340
|
+
def test_logop_12_3
|
341
|
+
lhs = s(:and, s(:lit, 1), s(:lit, 2))
|
342
|
+
rhs = s(:lit, 3)
|
343
|
+
exp = s(:and, s(:lit, 1), s(:and, s(:lit, 2), s(:lit, 3)))
|
344
|
+
|
345
|
+
assert_equal exp, @processor.logop(:and, lhs, rhs)
|
346
|
+
end
|
347
|
+
|
348
|
+
def test_logop_nested_mix
|
349
|
+
lhs = s(:or, s(:vcall, :a), s(:vcall, :b))
|
350
|
+
rhs = s(:and, s(:vcall, :c), s(:vcall, :d))
|
351
|
+
exp = s(:or,
|
352
|
+
s(:or, s(:vcall, :a), s(:vcall, :b)),
|
353
|
+
s(:and, s(:vcall, :c), s(:vcall, :d)))
|
354
|
+
|
355
|
+
lhs.paren = true
|
356
|
+
rhs.paren = true
|
357
|
+
|
358
|
+
assert_equal exp, @processor.logop(:or, lhs, rhs)
|
359
|
+
end
|
360
|
+
|
361
|
+
def test_str_evstr
|
362
|
+
rb = "\"a #\{b}\""
|
363
|
+
pt = s(:dstr, "a ", s(:evstr, s(:vcall, :b)))
|
364
|
+
|
365
|
+
assert_equal pt, @processor.parse(rb)
|
366
|
+
end
|
367
|
+
|
368
|
+
def test_str_pct_Q_nested
|
369
|
+
rb = "%Q[before [#\{nest}] after]"
|
370
|
+
pt = s(:dstr, "before [", s(:evstr, s(:vcall, :nest)), s(:str, "] after"))
|
371
|
+
|
372
|
+
assert_equal pt, @processor.parse(rb)
|
373
|
+
end
|
374
|
+
|
375
|
+
def test_str_str
|
376
|
+
rb = "\"a #\{'b'}\""
|
377
|
+
pt = s(:str, "a b")
|
378
|
+
|
379
|
+
assert_equal pt, @processor.parse(rb)
|
380
|
+
end
|
381
|
+
|
382
|
+
def test_str_str_str
|
383
|
+
rb = "\"a #\{'b'} c\""
|
384
|
+
pt = s(:str, "a b c")
|
385
|
+
|
386
|
+
assert_equal pt, @processor.parse(rb)
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
__END__
|
391
|
+
|
392
|
+
# blah18.rb
|
393
|
+
|
394
|
+
assert_equal("sub", $_)
|
@@ -0,0 +1,177 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'ruby_parser_extras'
|
3
|
+
|
4
|
+
class TestStackState < Test::Unit::TestCase
|
5
|
+
def test_stack_state
|
6
|
+
s = StackState.new :test
|
7
|
+
s.push true
|
8
|
+
s.push false
|
9
|
+
s.lexpop
|
10
|
+
assert_equal [false, true], s.stack
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_is_in_state
|
14
|
+
s = StackState.new :test
|
15
|
+
assert_equal false, s.is_in_state
|
16
|
+
s.push false
|
17
|
+
assert_equal false, s.is_in_state
|
18
|
+
s.push true
|
19
|
+
assert_equal true, s.is_in_state
|
20
|
+
s.push false
|
21
|
+
assert_equal false, s.is_in_state
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_lexpop
|
25
|
+
s = StackState.new :test
|
26
|
+
assert_equal [false], s.stack
|
27
|
+
s.push true
|
28
|
+
s.push false
|
29
|
+
assert_equal [false, true, false], s.stack
|
30
|
+
s.lexpop
|
31
|
+
assert_equal [false, true], s.stack
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_pop
|
35
|
+
s = StackState.new :test
|
36
|
+
assert_equal [false], s.stack
|
37
|
+
s.push true
|
38
|
+
assert_equal [false, true], s.stack
|
39
|
+
assert_equal true, s.pop
|
40
|
+
assert_equal [false], s.stack
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_push
|
44
|
+
s = StackState.new :test
|
45
|
+
assert_equal [false], s.stack
|
46
|
+
s.push true
|
47
|
+
s.push false
|
48
|
+
assert_equal [false, true, false], s.stack
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class TestEnvironment < Test::Unit::TestCase
|
53
|
+
def deny t
|
54
|
+
assert ! t
|
55
|
+
end
|
56
|
+
|
57
|
+
def setup
|
58
|
+
@env = Environment.new
|
59
|
+
@env[:blah] = 42
|
60
|
+
assert_equal 42, @env[:blah]
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_use
|
64
|
+
@env.use :blah
|
65
|
+
expected = [{ :blah => true }]
|
66
|
+
assert_equal expected, @env.instance_variable_get(:"@use")
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_use_scoped
|
70
|
+
@env.use :blah
|
71
|
+
@env.extend
|
72
|
+
expected = [{}, { :blah => true }]
|
73
|
+
assert_equal expected, @env.instance_variable_get(:"@use")
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_used_eh
|
77
|
+
@env.extend :dynamic
|
78
|
+
@env[:x] = :dvar
|
79
|
+
@env.use :x
|
80
|
+
assert_equal true, @env.used?(:x)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_used_eh_none
|
84
|
+
assert_equal nil, @env.used?(:x)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_used_eh_scoped
|
88
|
+
self.test_used_eh
|
89
|
+
@env.extend :dynamic
|
90
|
+
assert_equal true, @env.used?(:x)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_var_scope_dynamic
|
94
|
+
@env.extend :dynamic
|
95
|
+
assert_equal 42, @env[:blah]
|
96
|
+
@env.unextend
|
97
|
+
assert_equal 42, @env[:blah]
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_var_scope_static
|
101
|
+
@env.extend
|
102
|
+
assert_equal nil, @env[:blah]
|
103
|
+
@env.unextend
|
104
|
+
assert_equal 42, @env[:blah]
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_dynamic
|
108
|
+
expected1 = {}
|
109
|
+
expected2 = { :x => 42 }
|
110
|
+
|
111
|
+
assert_equal expected1, @env.dynamic
|
112
|
+
begin
|
113
|
+
@env.extend :dynamic
|
114
|
+
assert_equal expected1, @env.dynamic
|
115
|
+
|
116
|
+
@env[:x] = 42
|
117
|
+
assert_equal expected2, @env.dynamic
|
118
|
+
|
119
|
+
begin
|
120
|
+
@env.extend :dynamic
|
121
|
+
assert_equal expected2, @env.dynamic
|
122
|
+
@env.unextend
|
123
|
+
end
|
124
|
+
|
125
|
+
assert_equal expected2, @env.dynamic
|
126
|
+
@env.unextend
|
127
|
+
end
|
128
|
+
assert_equal expected1, @env.dynamic
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_all_dynamic
|
132
|
+
expected = { :blah => 42 }
|
133
|
+
|
134
|
+
@env.extend :dynamic
|
135
|
+
assert_equal expected, @env.all
|
136
|
+
@env.unextend
|
137
|
+
assert_equal expected, @env.all
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_all_static
|
141
|
+
@env.extend
|
142
|
+
expected = { }
|
143
|
+
assert_equal expected, @env.all
|
144
|
+
|
145
|
+
@env.unextend
|
146
|
+
expected = { :blah => 42 }
|
147
|
+
assert_equal expected, @env.all
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_dynamic_eh
|
151
|
+
assert_equal false, @env.dynamic?
|
152
|
+
@env.extend :dynamic
|
153
|
+
assert_equal true, @env.dynamic?
|
154
|
+
@env.extend
|
155
|
+
assert_equal false, @env.dynamic?
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_all_static_deeper
|
159
|
+
expected0 = { :blah => 42 }
|
160
|
+
expected1 = { :blah => 42, :blah2 => 24 }
|
161
|
+
expected2 = { :blah => 27 }
|
162
|
+
|
163
|
+
@env.extend :dynamic
|
164
|
+
@env[:blah2] = 24
|
165
|
+
assert_equal expected1, @env.all
|
166
|
+
|
167
|
+
@env.extend
|
168
|
+
@env[:blah] = 27
|
169
|
+
assert_equal expected2, @env.all
|
170
|
+
|
171
|
+
@env.unextend
|
172
|
+
assert_equal expected1, @env.all
|
173
|
+
|
174
|
+
@env.unextend
|
175
|
+
assert_equal expected0, @env.all
|
176
|
+
end
|
177
|
+
end
|