ParseTree 3.0.7 → 3.0.8

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,9 @@
1
+ === 3.0.8 / 2011-09-27
2
+
3
+ * 1 minor enhancement:
4
+
5
+ * ParseTree.translate now does 'include Mod' calls instead of including their methods directly
6
+
1
7
  === 3.0.7 / 2011-02-18
2
8
 
3
9
  * 1 bug fix:
@@ -12,7 +12,6 @@ lib/gauntlet_parsetree.rb
12
12
  lib/parse_tree.rb
13
13
  lib/parse_tree_extensions.rb
14
14
  lib/unified_ruby.rb
15
- test/pt_testcase.rb
16
15
  test/something.rb
17
16
  test/test_parse_tree.rb
18
17
  test/test_parse_tree_extensions.rb
data/README.txt CHANGED
@@ -1,8 +1,7 @@
1
1
  = ParseTree
2
2
 
3
- * http://rubyforge.org/projects/parsetree/
4
- * http://www.zenspider.com/ZSS/Products/ParseTree/
5
- * ryand-ruby@zenspider.com
3
+ home :: https://github.com/seattlerb/parsetree
4
+ rdoc :: http://docs.seattlerb.org/ParseTree/
6
5
 
7
6
  == DESCRIPTION:
8
7
 
@@ -76,7 +75,7 @@ or:
76
75
 
77
76
  (The MIT License)
78
77
 
79
- Copyright (c) 2001-2007 Ryan Davis, Zen Spider Software
78
+ Copyright (c) Ryan Davis, seattle.rb
80
79
 
81
80
  Permission is hereby granted, free of charge, to any person obtaining
82
81
  a copy of this software and associated documentation files (the
@@ -43,7 +43,7 @@ end
43
43
 
44
44
  class RawParseTree
45
45
 
46
- VERSION = '3.0.7'
46
+ VERSION = '3.0.8'
47
47
 
48
48
  ##
49
49
  # Front end translation method.
@@ -123,11 +123,11 @@ class RawParseTree
123
123
  code << r
124
124
  end
125
125
 
126
- klass.modules.each do |mod| # TODO: add a test for this damnit
127
- mod.instance_methods.each do |m|
128
- r = parse_tree_for_method(mod, m.to_sym)
129
- code << r
130
- end
126
+ mods = klass.modules
127
+ mods -= mods.map { |mod| mod.modules }.flatten
128
+
129
+ mods.each do |mod| # TODO: add a test for this damnit
130
+ code << process("include #{mod}")
131
131
  end
132
132
 
133
133
  klass.singleton_methods(false).sort.each do |m|
@@ -13,6 +13,19 @@ require 'parse_tree'
13
13
  require 'pt_testcase'
14
14
  require 'test/something'
15
15
 
16
+ module Mod1
17
+ define_method :mod_method do
18
+ end
19
+ end
20
+
21
+ module Mod2
22
+ include Mod1
23
+ end
24
+
25
+ class ClassInclude
26
+ include Mod2
27
+ end
28
+
16
29
  class SomethingWithInitialize
17
30
  def initialize; end # this method is private
18
31
  protected
@@ -222,6 +235,18 @@ class TestRawParseTree < ParseTreeTestCase
222
235
  @processor.parse_tree(Something),
223
236
  "Must return a lot of shit")
224
237
  end
238
+
239
+ def test_process_modules
240
+ exp = [[:module, :Mod1, [:defn, :mod_method, [:bmethod, nil]]]]
241
+ assert_equal exp, @processor.parse_tree(Mod1)
242
+
243
+ exp = [[:module, :Mod2, [:fcall, :include, [:array, [:const, :Mod1]]]]]
244
+ assert_equal exp, @processor.parse_tree(Mod2)
245
+
246
+ exp = [[:class, :ClassInclude, [:const, :Object],
247
+ [:fcall, :include, [:array, [:const, :Mod2]]]]]
248
+ assert_equal exp, @processor.parse_tree(ClassInclude)
249
+ end
225
250
  end
226
251
 
227
252
  class TestParseTree < ParseTreeTestCase
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ParseTree
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
- - 7
10
- version: 3.0.7
9
+ - 8
10
+ version: 3.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Davis
@@ -36,8 +36,7 @@ cert_chain:
36
36
  FBHgymkyj/AOSqKRIpXPhjC6
37
37
  -----END CERTIFICATE-----
38
38
 
39
- date: 2011-02-18 00:00:00 -08:00
40
- default_executable:
39
+ date: 2011-09-27 00:00:00 Z
41
40
  dependencies:
42
41
  - !ruby/object:Gem::Dependency
43
42
  name: RubyInline
@@ -77,14 +76,13 @@ dependencies:
77
76
  requirement: &id003 !ruby/object:Gem::Requirement
78
77
  none: false
79
78
  requirements:
80
- - - ">="
79
+ - - ~>
81
80
  - !ruby/object:Gem::Version
82
- hash: 11
81
+ hash: 9
83
82
  segments:
84
83
  - 2
85
- - 0
86
- - 2
87
- version: 2.0.2
84
+ - 5
85
+ version: "2.5"
88
86
  type: :development
89
87
  version_requirements: *id003
90
88
  - !ruby/object:Gem::Dependency
@@ -93,14 +91,13 @@ dependencies:
93
91
  requirement: &id004 !ruby/object:Gem::Requirement
94
92
  none: false
95
93
  requirements:
96
- - - ">="
94
+ - - ~>
97
95
  - !ruby/object:Gem::Version
98
- hash: 41
96
+ hash: 27
99
97
  segments:
100
98
  - 2
101
- - 9
102
- - 1
103
- version: 2.9.1
99
+ - 12
100
+ version: "2.12"
104
101
  type: :development
105
102
  version_requirements: *id004
106
103
  description: |-
@@ -158,15 +155,13 @@ files:
158
155
  - lib/parse_tree.rb
159
156
  - lib/parse_tree_extensions.rb
160
157
  - lib/unified_ruby.rb
161
- - test/pt_testcase.rb
162
158
  - test/something.rb
163
159
  - test/test_parse_tree.rb
164
160
  - test/test_parse_tree_extensions.rb
165
161
  - test/test_unified_ruby.rb
166
162
  - validate.sh
167
163
  - .gemtest
168
- has_rdoc: true
169
- homepage: http://rubyforge.org/projects/parsetree/
164
+ homepage: https://github.com/seattlerb/parsetree
170
165
  licenses: []
171
166
 
172
167
  post_install_message:
@@ -197,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
192
  requirements: []
198
193
 
199
194
  rubyforge_project: parsetree
200
- rubygems_version: 1.4.2
195
+ rubygems_version: 1.8.10
201
196
  signing_key:
202
197
  specification_version: 3
203
198
  summary: ParseTree is a C extension (using RubyInline) that extracts the parse tree for an entire class or a specific method and returns it as a s-expression (aka sexp) using ruby's arrays, strings, symbols, and integers
metadata.gz.sig CHANGED
Binary file
@@ -1,4417 +0,0 @@
1
- $TESTING = true
2
-
3
- require 'minitest/unit'
4
- require 'sexp_processor' # for deep_clone
5
-
6
- # key:
7
- # wwtt = what were they thinking?
8
-
9
- # TODO: <ko1_> 1.8.7 support {|&b|} syntax
10
-
11
- class Examples
12
- attr_reader :reader
13
- attr_writer :writer
14
-
15
- def a_method(x); x+1; end
16
- alias an_alias a_method
17
-
18
- define_method(:bmethod_noargs) do
19
- x + 1
20
- end
21
-
22
- define_method(:unsplatted) do |x|
23
- x + 1
24
- end
25
-
26
- define_method :splatted do |*args|
27
- y = args.first
28
- y + 42
29
- end
30
-
31
- define_method :dmethod_added, instance_method(:a_method) if
32
- RUBY_VERSION < "1.9"
33
- end
34
-
35
- class ParseTreeTestCase < MiniTest::Unit::TestCase
36
- attr_accessor :processor # to be defined by subclass
37
-
38
- def setup
39
- super
40
- @processor = nil
41
- end
42
-
43
- def after_process_hook klass, node, data, input_name, output_name
44
- end
45
-
46
- def before_process_hook klass, node, data, input_name, output_name
47
- end
48
-
49
- def self.add_test name, data, klass = self.name[4..-1]
50
- name = name.to_s
51
- klass = klass.to_s
52
-
53
- if testcases.has_key? name then
54
- if testcases[name].has_key? klass then
55
- warn "testcase #{klass}##{name} already has data"
56
- else
57
- testcases[name][klass] = data
58
- end
59
- else
60
- warn "testcase #{name} does not exist"
61
- end
62
- end
63
-
64
- def self.add_tests name, hash
65
- name = name.to_s
66
-
67
- hash.each do |klass, data|
68
- warn "testcase #{klass}##{name} already has data" if
69
- testcases[name].has_key? klass
70
- testcases[name][klass] = data
71
- end
72
- end
73
-
74
- def self.clone_same
75
- @@testcases.each do |node, data|
76
- data.each do |key, val|
77
- if val == :same then
78
- prev_key = self.previous(key)
79
- data[key] = data[prev_key].deep_clone
80
- end
81
- end
82
- end
83
- end
84
-
85
- def self.copy_test_case nonverbose, klass
86
- verbose = nonverbose + "_mri_verbose_flag"
87
- testcases[verbose][klass] = testcases[nonverbose][klass]
88
- end
89
-
90
- def self.generate_test klass, node, data, input_name, output_name
91
- klass.send(:define_method, "test_#{node}".to_sym) do
92
- flunk "Processor is nil" if processor.nil?
93
-
94
- assert data.has_key?(input_name), "Unknown input data"
95
- assert data.has_key?(output_name), "Missing test data"
96
-
97
- $missing[node] << output_name unless data.has_key? output_name
98
-
99
- input = data[input_name].deep_clone
100
- expected = data[output_name].deep_clone
101
-
102
- case expected
103
- when :unsupported then
104
- assert_raises(UnsupportedNodeError) do
105
- processor.process(input)
106
- end
107
- else
108
- extra_expected = []
109
- extra_input = []
110
-
111
- _, expected, extra_expected = *expected if
112
- Array === expected and expected.first == :defx
113
- _, input, extra_input = *input if
114
- Array === input and input.first == :defx
115
-
116
- # OMG... I can't believe I have to do this this way. these
117
- # hooks are here instead of refactoring this define_method
118
- # body into an assertion. It'll allow subclasses to hook in
119
- # and add behavior before or after the processor does it's
120
- # thing. If you go the body refactor route, some of the
121
- # RawParseTree test casese fail for completely bogus reasons.
122
-
123
- before_process_hook klass, node, data, input_name, output_name
124
- refute_nil data[input_name], "testcase does not exist?"
125
- @result = processor.process input
126
- assert_equal(expected, @result,
127
- "failed on input: #{data[input_name].inspect}")
128
- after_process_hook klass, node, data, input_name, output_name
129
-
130
- extra_input.each do |extra|
131
- processor.process(extra)
132
- end
133
- extra = processor.extra_methods rescue []
134
- assert_equal extra_expected, extra
135
- end
136
- end
137
- end
138
-
139
- def self.generate_tests klass
140
- install_missing_reporter
141
- clone_same
142
-
143
- output_name = klass.name.to_s.sub(/^Test/, '')
144
-
145
- input_name = self.previous(output_name)
146
-
147
- @@testcases.each do |node, data|
148
- next if [:skip, :unsupported].include? data[input_name]
149
- next if data[output_name] == :skip
150
-
151
- generate_test klass, node, data, input_name, output_name
152
- end
153
- end
154
-
155
- def self.inherited klass
156
- super
157
-
158
- generate_tests klass unless klass.name =~ /TestCase/
159
- end
160
-
161
- def self.install_missing_reporter
162
- unless defined? $missing then
163
- $missing = Hash.new { |h,k| h[k] = [] }
164
- at_exit {
165
- at_exit {
166
- warn ""
167
- $missing.sort.each do |name, klasses|
168
- warn "add_tests(#{name.inspect},"
169
- klasses.map! { |klass| " #{klass.inspect} => :same" }
170
- warn klasses.join("\n") + ")"
171
- end
172
- warn ""
173
- }
174
- }
175
- end
176
- end
177
-
178
- def self.previous(key, extra=0) # FIX: remove R2C code
179
- idx = @@testcase_order.index(key)
180
-
181
- raise "Unknown class #{key} in @@testcase_order" if idx.nil?
182
-
183
- case key
184
- when "RubyToRubyC" then
185
- idx -= 1
186
- end
187
- @@testcase_order[idx - 1 - extra]
188
- end
189
-
190
- def self.testcase_order; @@testcase_order; end
191
- def self.testcases; @@testcases; end
192
-
193
- def self.unsupported_tests *tests
194
- tests.flatten.each do |name|
195
- add_test name, :unsupported
196
- end
197
- end
198
-
199
- ############################################################
200
- # Shared TestCases:
201
-
202
- @@testcase_order = %w(Ruby RawParseTree ParseTree)
203
-
204
- @@testcases = Hash.new { |h,k| h[k] = {} }
205
-
206
- add_tests("alias",
207
- "Ruby" => "class X\n alias :y :x\nend",
208
- "RawParseTree" => [:class, :X, nil,
209
- [:scope, [:alias, [:lit, :y], [:lit, :x]]]],
210
- "ParseTree" => s(:class, :X, nil,
211
- s(:scope, s(:alias, s(:lit, :y), s(:lit, :x)))))
212
-
213
- add_tests("alias_ugh",
214
- "Ruby" => "class X\n alias y x\nend",
215
- "RawParseTree" => [:class, :X, nil,
216
- [:scope, [:alias, [:lit, :y], [:lit, :x]]]],
217
- "ParseTree" => s(:class, :X, nil,
218
- s(:scope, s(:alias, s(:lit, :y), s(:lit, :x)))),
219
- "Ruby2Ruby" => "class X\n alias :y :x\nend")
220
-
221
- add_tests("and",
222
- "Ruby" => "(a and b)",
223
- "RawParseTree" => [:and, [:vcall, :a], [:vcall, :b]],
224
- "ParseTree" => s(:and,
225
- s(:call, nil, :a, s(:arglist)),
226
- s(:call, nil, :b, s(:arglist))))
227
-
228
- add_tests("argscat_inside",
229
- "Ruby" => "a = [b, *c]",
230
- "RawParseTree" => [:lasgn, :a,
231
- [:argscat,
232
- [:array, [:vcall, :b]], [:vcall, :c]]],
233
- "ParseTree" => s(:lasgn, :a,
234
- s(:array,
235
- s(:call, nil, :b, s(:arglist)),
236
- s(:splat, s(:call, nil, :c, s(:arglist))))))
237
-
238
- add_tests("argscat_svalue",
239
- "Ruby" => "a = b, c, *d",
240
- "RawParseTree" => [:lasgn, :a,
241
- [:svalue,
242
- [:argscat,
243
- [:array, [:vcall, :b], [:vcall, :c]],
244
- [:vcall, :d]]]],
245
- "ParseTree" => s(:lasgn, :a,
246
- s(:svalue,
247
- s(:array,
248
- s(:call, nil, :b, s(:arglist)),
249
- s(:call, nil, :c, s(:arglist)),
250
- s(:splat,
251
- s(:call, nil, :d, s(:arglist)))))))
252
-
253
- add_tests("argspush",
254
- "Ruby" => "a[*b] = c",
255
- "RawParseTree" => [:attrasgn,
256
- [:vcall, :a],
257
- :[]=,
258
- [:argspush,
259
- [:splat,
260
- [:vcall, :b]],
261
- [:vcall, :c]]],
262
- "ParseTree" => s(:attrasgn,
263
- s(:call, nil, :a, s(:arglist)),
264
- :[]=,
265
- s(:arglist,
266
- s(:splat,
267
- s(:call, nil, :b, s(:arglist))),
268
- s(:call, nil, :c, s(:arglist)))))
269
-
270
- add_tests("array",
271
- "Ruby" => "[1, :b, \"c\"]",
272
- "RawParseTree" => [:array, [:lit, 1], [:lit, :b], [:str, "c"]],
273
- "ParseTree" => s(:array, s(:lit, 1), s(:lit, :b), s(:str, "c")))
274
-
275
- add_tests("array_pct_W",
276
- "Ruby" => "%W[a b c]",
277
- "RawParseTree" => [:array, [:str, "a"], [:str, "b"], [:str, "c"]],
278
- "ParseTree" => s(:array,
279
- s(:str, "a"), s(:str, "b"), s(:str, "c")),
280
- "Ruby2Ruby" => "[\"a\", \"b\", \"c\"]")
281
-
282
- add_tests("array_pct_W_dstr",
283
- "Ruby" => "%W[a #\{@b} c]",
284
- "RawParseTree" => [:array,
285
- [:str, "a"],
286
- [:dstr, "", [:evstr, [:ivar, :@b]]],
287
- [:str, "c"]],
288
- "ParseTree" => s(:array,
289
- s(:str, "a"),
290
- s(:dstr, "", s(:evstr, s(:ivar, :@b))),
291
- s(:str, "c")),
292
- "Ruby2Ruby" => "[\"a\", \"#\{@b}\", \"c\"]")
293
-
294
- add_tests("array_pct_w",
295
- "Ruby" => "%w[a b c]",
296
- "RawParseTree" => [:array, [:str, "a"], [:str, "b"], [:str, "c"]],
297
- "ParseTree" => s(:array,
298
- s(:str, "a"), s(:str, "b"), s(:str, "c")),
299
- "Ruby2Ruby" => "[\"a\", \"b\", \"c\"]")
300
-
301
- add_tests("array_pct_w_dstr",
302
- "Ruby" => "%w[a #\{@b} c]",
303
- "RawParseTree" => [:array,
304
- [:str, "a"],
305
- [:str, "#\{@b}"],
306
- [:str, "c"]],
307
- "ParseTree" => s(:array,
308
- s(:str, "a"),
309
- s(:str, "#\{@b}"),
310
- s(:str, "c")),
311
- "Ruby2Ruby" => "[\"a\", \"\\\#{@b}\", \"c\"]") # TODO: huh?
312
-
313
- add_tests("attrasgn",
314
- "Ruby" => "y = 0\n42.method = y\n",
315
- "RawParseTree" => [:block,
316
- [:lasgn, :y, [:lit, 0]],
317
- [:attrasgn, [:lit, 42], :method=,
318
- [:array, [:lvar, :y]]]],
319
- "ParseTree" => s(:block,
320
- s(:lasgn, :y, s(:lit, 0)),
321
- s(:attrasgn, s(:lit, 42), :method=,
322
- s(:arglist, s(:lvar, :y)))))
323
-
324
- add_tests("attrasgn_index_equals",
325
- "Ruby" => "a[42] = 24",
326
- "RawParseTree" => [:attrasgn, [:vcall, :a], :[]=,
327
- [:array, [:lit, 42], [:lit, 24]]],
328
- "ParseTree" => s(:attrasgn,
329
- s(:call, nil, :a, s(:arglist)),
330
- :[]=,
331
- s(:arglist, s(:lit, 42), s(:lit, 24))))
332
-
333
- add_tests("attrasgn_index_equals_space",
334
- "Ruby" => "a = []; a [42] = 24",
335
- "RawParseTree" => [:block,
336
- [:lasgn, :a, [:zarray]],
337
- [:attrasgn, [:lvar, :a], :[]=,
338
- [:array, [:lit, 42], [:lit, 24]]]],
339
- "ParseTree" => s(:block,
340
- s(:lasgn, :a, s(:array)),
341
- s(:attrasgn, s(:lvar, :a), :[]=,
342
- s(:arglist, s(:lit, 42), s(:lit, 24)))),
343
- "Ruby2Ruby" => "a = []\na[42] = 24\n")
344
-
345
- add_tests("attrset",
346
- "Ruby" => [Examples, :writer=],
347
- "RawParseTree" => [:defn, :writer=, [:attrset, :@writer]],
348
- "ParseTree" => s(:defn, :writer=,
349
- s(:args, :arg),
350
- s(:attrset, :@writer)),
351
- "Ruby2Ruby" => "attr_writer :writer")
352
-
353
- add_tests("back_ref",
354
- "Ruby" => "[$&, $`, $', $+]",
355
- "RawParseTree" => [:array,
356
- [:back_ref, :&],
357
- [:back_ref, :"`"],
358
- [:back_ref, :"'"],
359
- [:back_ref, :+]],
360
- "ParseTree" => s(:array,
361
- s(:back_ref, :&),
362
- s(:back_ref, :"`"),
363
- s(:back_ref, :"'"),
364
- s(:back_ref, :+)))
365
-
366
- add_tests("begin",
367
- "Ruby" => "begin\n (1 + 1)\nend",
368
- "RawParseTree" => [:call, [:lit, 1], :+, [:array, [:lit, 1]]],
369
- "ParseTree" => s(:call, s(:lit, 1), :+,
370
- s(:arglist, s(:lit, 1))),
371
- "Ruby2Ruby" => "(1 + 1)")
372
-
373
- add_tests("begin_def",
374
- "Ruby" => "def m\n begin\n\n end\nend",
375
- "RawParseTree" => [:defn, :m, [:scope, [:block, [:args], [:nil]]]],
376
- "ParseTree" => s(:defn, :m, s(:args),
377
- s(:scope, s(:block, s(:nil)))),
378
- "Ruby2Ruby" => "def m\n # do nothing\nend")
379
-
380
- add_tests("begin_rescue_ensure",
381
- "Ruby" => "begin\n a\nrescue\n # do nothing\nensure\n # do nothing\nend",
382
- "RawParseTree" => [:ensure,
383
- [:rescue,
384
- [:vcall, :a],
385
- [:resbody, nil]],
386
- [:nil]],
387
- "ParseTree" => s(:ensure,
388
- s(:rescue,
389
- s(:call, nil, :a, s(:arglist)),
390
- s(:resbody, s(:array), nil)),
391
- s(:nil)))
392
-
393
- add_tests("begin_rescue_ensure_all_empty",
394
- "Ruby" => "begin\n # do nothing\nrescue\n # do nothing\nensure\n # do nothing\nend",
395
- "RawParseTree" => [:ensure,
396
- [:rescue,
397
- [:resbody, nil]],
398
- [:nil]],
399
- "ParseTree" => s(:ensure,
400
- s(:rescue,
401
- s(:resbody, s(:array), nil)),
402
- s(:nil)))
403
-
404
- add_tests("begin_rescue_twice",
405
- "Ruby" => "begin\n a\nrescue => mes\n # do nothing\nend\nbegin\n b\nrescue => mes\n # do nothing\nend\n",
406
- "RawParseTree" => [:block,
407
- [:rescue,
408
- [:vcall, :a],
409
- [:resbody, nil,
410
- [:lasgn, :mes, [:gvar, :$!]]]],
411
- [:rescue,
412
- [:vcall, :b],
413
- [:resbody, nil,
414
- [:lasgn, :mes, [:gvar, :$!]]]]],
415
- "ParseTree" => s(:block,
416
- s(:rescue,
417
- s(:call, nil, :a, s(:arglist)),
418
- s(:resbody,
419
- s(:array, s(:lasgn, :mes, s(:gvar, :$!))),
420
- nil)),
421
- s(:rescue,
422
- s(:call, nil, :b, s(:arglist)),
423
- s(:resbody,
424
- s(:array,
425
- s(:lasgn, :mes, s(:gvar, :$!))),
426
- nil))))
427
-
428
- add_tests("begin_rescue_twice_mri_verbose_flag",
429
- "RawParseTree" => [:block,
430
- [:rescue, # no begin
431
- [:vcall, :a],
432
- [:resbody, nil,
433
- [:lasgn, :mes, [:gvar, :$!]]]],
434
- [:rescue,
435
- [:vcall, :b],
436
- [:resbody, nil,
437
- [:lasgn, :mes, [:gvar, :$!]]]]])
438
-
439
- copy_test_case "begin_rescue_twice", "Ruby"
440
- copy_test_case "begin_rescue_twice", "ParseTree"
441
-
442
- add_tests("block_attrasgn",
443
- "Ruby" => "def self.setup(ctx)\n bind = allocate\n bind.context = ctx\n return bind\nend",
444
- "RawParseTree" => [:defs, [:self], :setup,
445
- [:scope,
446
- [:block,
447
- [:args, :ctx],
448
- [:lasgn, :bind, [:vcall, :allocate]],
449
- [:attrasgn, [:lvar, :bind], :context=,
450
- [:array, [:lvar, :ctx]]],
451
- [:return, [:lvar, :bind]]]]],
452
- "ParseTree" => s(:defs, s(:self), :setup,
453
- s(:args, :ctx),
454
- s(:scope,
455
- s(:block,
456
- s(:lasgn, :bind,
457
- s(:call, nil, :allocate, s(:arglist))),
458
- s(:attrasgn, s(:lvar, :bind), :context=,
459
- s(:arglist, s(:lvar, :ctx))),
460
- s(:return, s(:lvar, :bind))))))
461
-
462
-
463
- add_tests("block_lasgn",
464
- "Ruby" => "x = (y = 1\n(y + 2))",
465
- "RawParseTree" => [:lasgn, :x,
466
- [:block,
467
- [:lasgn, :y, [:lit, 1]],
468
- [:call, [:lvar, :y], :+, [:array, [:lit, 2]]]]],
469
- "ParseTree" => s(:lasgn, :x,
470
- s(:block,
471
- s(:lasgn, :y, s(:lit, 1)),
472
- s(:call, s(:lvar, :y), :+,
473
- s(:arglist, s(:lit, 2))))))
474
-
475
- add_tests("block_mystery_block",
476
- "Ruby" => "a(b) do\n if b then\n true\n else\n c = false\n d { |x| c = true }\n c\n end\nend",
477
- "RawParseTree" => [:iter,
478
- [:fcall, :a, [:array, [:vcall, :b]]],
479
- nil,
480
- [:if,
481
- [:vcall, :b],
482
- [:true],
483
- [:block,
484
- [:dasgn_curr, :c, [:false]],
485
- [:iter,
486
- [:fcall, :d],
487
- [:dasgn_curr, :x],
488
- [:dasgn, :c, [:true]]],
489
- [:dvar, :c]]]],
490
- "ParseTree" => s(:iter,
491
- s(:call, nil, :a,
492
- s(:arglist, s(:call, nil, :b, s(:arglist)))),
493
- nil,
494
- s(:if,
495
- s(:call, nil, :b, s(:arglist)),
496
- s(:true),
497
- s(:block,
498
- s(:lasgn, :c, s(:false)),
499
- s(:iter,
500
- s(:call, nil, :d, s(:arglist)),
501
- s(:lasgn, :x),
502
- s(:lasgn, :c, s(:true))),
503
- s(:lvar, :c)))))
504
-
505
- add_tests("block_pass_args_and_splat",
506
- "Ruby" => "def blah(*args, &block)\n other(42, *args, &block)\nend",
507
- "RawParseTree" => [:defn, :blah,
508
- [:scope,
509
- [:block,
510
- [:args, :"*args"],
511
- [:block_arg, :block],
512
- [:block_pass,
513
- [:lvar, :block],
514
- [:fcall, :other,
515
- [:argscat,
516
- [:array, [:lit, 42]], [:lvar, :args]]]]]]],
517
- "ParseTree" => s(:defn, :blah,
518
- s(:args, :"*args", :"&block"),
519
- s(:scope,
520
- s(:block,
521
- s(:call, nil, :other,
522
- s(:arglist,
523
- s(:lit, 42),
524
- s(:splat, s(:lvar, :args)),
525
- s(:block_pass, s(:lvar, :block))))))))
526
-
527
- add_tests("block_pass_call_0",
528
- "Ruby" => "a.b(&c)",
529
- "RawParseTree" => [:block_pass,
530
- [:vcall, :c], [:call, [:vcall, :a], :b]],
531
- "ParseTree" => s(:call,
532
- s(:call, nil, :a, s(:arglist)),
533
- :b,
534
- s(:arglist,
535
- s(:block_pass,
536
- s(:call, nil, :c, s(:arglist))))))
537
-
538
- add_tests("block_pass_call_1",
539
- "Ruby" => "a.b(4, &c)",
540
- "RawParseTree" => [:block_pass,
541
- [:vcall, :c],
542
- [:call, [:vcall, :a], :b, [:array, [:lit, 4]]]],
543
- "ParseTree" => s(:call,
544
- s(:call, nil, :a, s(:arglist)),
545
- :b,
546
- s(:arglist,
547
- s(:lit, 4),
548
- s(:block_pass,
549
- s(:call, nil, :c, s(:arglist))))))
550
-
551
- add_tests("block_pass_call_n",
552
- "Ruby" => "a.b(1, 2, 3, &c)",
553
- "RawParseTree" => [:block_pass,
554
- [:vcall, :c],
555
- [:call, [:vcall, :a], :b,
556
- [:array, [:lit, 1], [:lit, 2], [:lit, 3]]]],
557
- "ParseTree" => s(:call,
558
- s(:call, nil, :a, s(:arglist)),
559
- :b,
560
- s(:arglist,
561
- s(:lit, 1), s(:lit, 2), s(:lit, 3),
562
- s(:block_pass,
563
- s(:call, nil, :c, s(:arglist))))))
564
-
565
- add_tests("block_pass_fcall_0",
566
- "Ruby" => "a(&b)",
567
- "RawParseTree" => [:block_pass, [:vcall, :b], [:fcall, :a]],
568
- "ParseTree" => s(:call, nil, :a,
569
- s(:arglist,
570
- s(:block_pass,
571
- s(:call, nil, :b, s(:arglist))))))
572
-
573
- add_tests("block_pass_fcall_1",
574
- "Ruby" => "a(4, &b)",
575
- "RawParseTree" => [:block_pass,
576
- [:vcall, :b],
577
- [:fcall, :a, [:array, [:lit, 4]]]],
578
- "ParseTree" => s(:call, nil, :a,
579
- s(:arglist,
580
- s(:lit, 4),
581
- s(:block_pass,
582
- s(:call, nil, :b, s(:arglist))))))
583
-
584
- add_tests("block_pass_fcall_n",
585
- "Ruby" => "a(1, 2, 3, &b)",
586
- "RawParseTree" => [:block_pass,
587
- [:vcall, :b],
588
- [:fcall, :a,
589
- [:array, [:lit, 1], [:lit, 2], [:lit, 3]]]],
590
- "ParseTree" => s(:call, nil, :a,
591
- s(:arglist,
592
- s(:lit, 1), s(:lit, 2), s(:lit, 3),
593
- s(:block_pass,
594
- s(:call, nil, :b, s(:arglist))))))
595
-
596
- add_tests("block_pass_omgwtf",
597
- "Ruby" => "define_attr_method(:x, :sequence_name, &Proc.new { |*args| nil })",
598
- "RawParseTree" => [:block_pass,
599
- [:iter,
600
- [:call, [:const, :Proc], :new],
601
- [:masgn, nil, [:dasgn_curr, :args], nil],
602
- [:nil]],
603
- [:fcall, :define_attr_method,
604
- [:array, [:lit, :x], [:lit, :sequence_name]]]],
605
- "ParseTree" => s(:call, nil, :define_attr_method,
606
- s(:arglist,
607
- s(:lit, :x),
608
- s(:lit, :sequence_name),
609
- s(:block_pass,
610
- s(:iter,
611
- s(:call, s(:const, :Proc), :new,
612
- s(:arglist)),
613
- s(:masgn,
614
- s(:array, s(:splat, s(:lasgn, :args)))),
615
- s(:nil))))))
616
-
617
- add_tests("block_pass_splat",
618
- "Ruby" => "def blah(*args, &block)\n other(*args, &block)\nend",
619
- "RawParseTree" => [:defn, :blah,
620
- [:scope,
621
- [:block,
622
- [:args, :"*args"],
623
- [:block_arg, :block],
624
- [:block_pass,
625
- [:lvar, :block],
626
- [:fcall, :other,
627
- [:splat, [:lvar, :args]]]]]]],
628
- "ParseTree" => s(:defn, :blah,
629
- s(:args, :"*args", :"&block"),
630
- s(:scope,
631
- s(:block,
632
- s(:call, nil, :other,
633
- s(:arglist,
634
- s(:splat, s(:lvar, :args)),
635
- s(:block_pass, s(:lvar, :block))))))))
636
-
637
- add_tests("block_pass_thingy",
638
- "Ruby" => "r.read_body(dest, &block)",
639
- "RawParseTree" => [:block_pass,
640
- [:vcall, :block],
641
- [:call, [:vcall, :r], :read_body,
642
- [:array, [:vcall, :dest]]]],
643
- "ParseTree" => s(:call,
644
- s(:call, nil, :r, s(:arglist)),
645
- :read_body,
646
- s(:arglist,
647
- s(:call, nil, :dest, s(:arglist)),
648
- s(:block_pass,
649
- s(:call, nil, :block, s(:arglist))))))
650
-
651
- add_tests("block_stmt_after",
652
- "Ruby" => "def f\n begin\n b\n rescue\n c\n end\n\n d\nend",
653
- "RawParseTree" => [:defn, :f,
654
- [:scope,
655
- [:block,
656
- [:args],
657
- [:rescue,
658
- [:vcall, :b],
659
- [:resbody, nil, [:vcall, :c]]],
660
- [:vcall, :d]]]],
661
- "ParseTree" => s(:defn, :f,
662
- s(:args),
663
- s(:scope,
664
- s(:block,
665
- s(:rescue,
666
- s(:call, nil, :b, s(:arglist)),
667
- s(:resbody,
668
- s(:array),
669
- s(:call, nil, :c, s(:arglist)))),
670
- s(:call, nil, :d, s(:arglist))))),
671
- "Ruby2Ruby" => "def f\n b rescue c\n d\nend")
672
-
673
- add_tests("block_stmt_after_mri_verbose_flag",
674
- "RawParseTree" => [:defn, :f,
675
- [:scope,
676
- [:block,
677
- [:args],
678
- [:rescue, # no begin
679
- [:vcall, :b],
680
- [:resbody, nil, [:vcall, :c]]],
681
- [:vcall, :d]]]])
682
-
683
- copy_test_case "block_stmt_after", "Ruby"
684
- copy_test_case "block_stmt_after", "ParseTree"
685
- copy_test_case "block_stmt_after", "Ruby2Ruby"
686
-
687
- add_tests("block_stmt_before",
688
- "Ruby" => "def f\n a\n begin\n b\n rescue\n c\n end\nend",
689
- "RawParseTree" => [:defn, :f,
690
- [:scope,
691
- [:block,
692
- [:args],
693
- [:vcall, :a],
694
- [:rescue, [:vcall, :b],
695
- [:resbody, nil, [:vcall, :c]]]]]],
696
- "ParseTree" => s(:defn, :f,
697
- s(:args),
698
- s(:scope,
699
- s(:block,
700
- s(:call, nil, :a, s(:arglist)),
701
- s(:rescue, s(:call, nil, :b, s(:arglist)),
702
- s(:resbody,
703
- s(:array),
704
- s(:call, nil, :c, s(:arglist))))))),
705
- "Ruby2Ruby" => "def f\n a\n b rescue c\nend")
706
-
707
- # oddly... this one doesn't HAVE any differences when verbose... new?
708
- copy_test_case "block_stmt_before", "Ruby"
709
- copy_test_case "block_stmt_before", "ParseTree"
710
- copy_test_case "block_stmt_before", "RawParseTree"
711
- copy_test_case "block_stmt_before", "Ruby2Ruby"
712
-
713
- add_tests("block_stmt_both",
714
- "Ruby" => "def f\n a\n begin\n b\n rescue\n c\n end\n d\nend",
715
- "RawParseTree" => [:defn, :f,
716
- [:scope,
717
- [:block,
718
- [:args],
719
- [:vcall, :a],
720
- [:rescue,
721
- [:vcall, :b],
722
- [:resbody,
723
- nil,
724
- [:vcall, :c]]],
725
- [:vcall, :d]]]],
726
- "ParseTree" => s(:defn, :f, s(:args),
727
- s(:scope,
728
- s(:block,
729
- s(:call, nil, :a, s(:arglist)),
730
- s(:rescue,
731
- s(:call, nil, :b, s(:arglist)),
732
- s(:resbody,
733
- s(:array),
734
- s(:call, nil, :c, s(:arglist)))),
735
- s(:call, nil, :d, s(:arglist))))),
736
- "Ruby2Ruby" => "def f\n a\n b rescue c\n d\nend")
737
-
738
- add_tests("block_stmt_both_mri_verbose_flag",
739
- "RawParseTree" => [:defn, :f,
740
- [:scope,
741
- [:block,
742
- [:args],
743
- [:vcall, :a],
744
- [:rescue, # no begin
745
- [:vcall, :b],
746
- [:resbody,
747
- nil,
748
- [:vcall, :c]]],
749
- [:vcall, :d]]]])
750
-
751
- copy_test_case "block_stmt_both", "Ruby"
752
- copy_test_case "block_stmt_both", "ParseTree"
753
- copy_test_case "block_stmt_both", "Ruby2Ruby"
754
-
755
- add_tests("bmethod",
756
- "Ruby" => [Examples, :unsplatted],
757
- "RawParseTree" => [:defn, :unsplatted,
758
- [:bmethod,
759
- [:dasgn_curr, :x],
760
- [:call, [:dvar, :x], :+, [:array, [:lit, 1]]]]],
761
- "ParseTree" => s(:defn, :unsplatted,
762
- s(:args, :x),
763
- s(:scope,
764
- s(:block,
765
- s(:call,
766
- s(:lvar, :x),
767
- :+,
768
- s(:arglist, s(:lit, 1)))))),
769
- "Ruby2Ruby" => "def unsplatted(x)\n (x + 1)\nend")
770
-
771
- add_tests("bmethod_noargs",
772
- "Ruby" => [Examples, :bmethod_noargs],
773
- "RawParseTree" => [:defn, :bmethod_noargs,
774
- [:bmethod,
775
- nil,
776
- [:call,
777
- [:vcall, :x], :"+", [:array, [:lit, 1]]]]],
778
- "ParseTree" => s(:defn, :bmethod_noargs,
779
- s(:args),
780
- s(:scope,
781
- s(:block,
782
- s(:call,
783
- s(:call, nil, :x, s(:arglist)),
784
- :"+",
785
- s(:arglist, s(:lit, 1)))))),
786
- "Ruby2Ruby" => "def bmethod_noargs\n (x + 1)\nend")
787
-
788
- add_tests("bmethod_splat",
789
- "Ruby" => [Examples, :splatted],
790
- "RawParseTree" => [:defn, :splatted,
791
- [:bmethod,
792
- [:masgn, nil, [:dasgn_curr, :args], nil],
793
- [:block,
794
- [:dasgn_curr, :y,
795
- [:call, [:dvar, :args], :first]],
796
- [:call, [:dvar, :y], :+,
797
- [:array, [:lit, 42]]]]]],
798
- "ParseTree" => s(:defn, :splatted,
799
- s(:args, :"*args"),
800
- s(:scope,
801
- s(:block,
802
- s(:lasgn, :y,
803
- s(:call, s(:lvar, :args), :first,
804
- s(:arglist))),
805
- s(:call, s(:lvar, :y), :+,
806
- s(:arglist, s(:lit, 42)))))),
807
- "Ruby2Ruby" => "def splatted(*args)\n y = args.first\n (y + 42)\nend")
808
-
809
- add_tests("break",
810
- "Ruby" => "loop { break if true }",
811
- "RawParseTree" => [:iter,
812
- [:fcall, :loop], nil,
813
- [:if, [:true], [:break], nil]],
814
- "ParseTree" => s(:iter,
815
- s(:call, nil, :loop, s(:arglist)), nil,
816
- s(:if, s(:true), s(:break), nil)))
817
-
818
- add_tests("break_arg",
819
- "Ruby" => "loop { break 42 if true }",
820
- "RawParseTree" => [:iter,
821
- [:fcall, :loop], nil,
822
- [:if, [:true], [:break, [:lit, 42]], nil]],
823
- "ParseTree" => s(:iter,
824
- s(:call, nil, :loop, s(:arglist)), nil,
825
- s(:if, s(:true), s(:break, s(:lit, 42)), nil)))
826
-
827
- add_tests("call",
828
- "Ruby" => "self.method",
829
- "RawParseTree" => [:call, [:self], :method],
830
- "ParseTree" => s(:call, s(:self), :method, s(:arglist)))
831
-
832
- add_tests("call_arglist",
833
- "Ruby" => "o.puts(42)",
834
- "RawParseTree" => [:call, [:vcall, :o], :puts,
835
- [:array, [:lit, 42]]],
836
- "ParseTree" => s(:call, s(:call, nil, :o, s(:arglist)), :puts,
837
- s(:arglist, s(:lit, 42))))
838
-
839
- add_tests("call_arglist_hash",
840
- "Ruby" => "o.m(:a => 1, :b => 2)",
841
- "RawParseTree" => [:call,
842
- [:vcall, :o], :m,
843
- [:array,
844
- [:hash,
845
- [:lit, :a], [:lit, 1],
846
- [:lit, :b], [:lit, 2]]]],
847
- "ParseTree" => s(:call,
848
- s(:call, nil, :o, s(:arglist)), :m,
849
- s(:arglist,
850
- s(:hash,
851
- s(:lit, :a), s(:lit, 1),
852
- s(:lit, :b), s(:lit, 2)))))
853
-
854
- add_tests("call_arglist_norm_hash",
855
- "Ruby" => "o.m(42, :a => 1, :b => 2)",
856
- "RawParseTree" => [:call,
857
- [:vcall, :o], :m,
858
- [:array,
859
- [:lit, 42],
860
- [:hash,
861
- [:lit, :a], [:lit, 1],
862
- [:lit, :b], [:lit, 2]]]],
863
- "ParseTree" => s(:call,
864
- s(:call, nil, :o, s(:arglist)), :m,
865
- s(:arglist,
866
- s(:lit, 42),
867
- s(:hash,
868
- s(:lit, :a), s(:lit, 1),
869
- s(:lit, :b), s(:lit, 2)))))
870
-
871
- add_tests("call_arglist_norm_hash_splat",
872
- "Ruby" => "o.m(42, :a => 1, :b => 2, *c)",
873
- "RawParseTree" => [:call,
874
- [:vcall, :o], :m,
875
- [:argscat,
876
- [:array,
877
- [:lit, 42],
878
- [:hash,
879
- [:lit, :a], [:lit, 1],
880
- [:lit, :b], [:lit, 2]]],
881
- [:vcall, :c]]],
882
- "ParseTree" => s(:call,
883
- s(:call, nil, :o, s(:arglist)), :m,
884
- s(:arglist,
885
- s(:lit, 42),
886
- s(:hash,
887
- s(:lit, :a), s(:lit, 1),
888
- s(:lit, :b), s(:lit, 2)),
889
- s(:splat, s(:call, nil, :c, s(:arglist))))))
890
-
891
- add_tests("call_arglist_space",
892
- "Ruby" => "a (1,2,3)",
893
- "RawParseTree" => [:fcall, :a,
894
- [:array, [:lit, 1], [:lit, 2], [:lit, 3]]],
895
- "ParseTree" => s(:call, nil, :a,
896
- s(:arglist,
897
- s(:lit, 1), s(:lit, 2), s(:lit, 3))),
898
- "Ruby2Ruby" => "a(1, 2, 3)")
899
-
900
- add_tests("call_command",
901
- "Ruby" => "1.b(c)",
902
- "RawParseTree" => [:call, [:lit, 1], :b, [:array, [:vcall, :c]]],
903
- "ParseTree" => s(:call,
904
- s(:lit, 1),
905
- :b,
906
- s(:arglist, s(:call, nil, :c, s(:arglist)))))
907
-
908
- add_tests("call_expr",
909
- "Ruby" => "(v = (1 + 1)).zero?",
910
- "RawParseTree" => [:call,
911
- [:lasgn, :v,
912
- [:call, [:lit, 1], :+, [:array, [:lit, 1]]]],
913
- :zero?],
914
- "ParseTree" => s(:call,
915
- s(:lasgn, :v,
916
- s(:call, s(:lit, 1), :+,
917
- s(:arglist, s(:lit, 1)))),
918
- :zero?, s(:arglist)))
919
-
920
- add_tests("call_index",
921
- "Ruby" => "a = []\na[42]\n",
922
- "RawParseTree" => [:block,
923
- [:lasgn, :a, [:zarray]],
924
- [:call, [:lvar, :a], :[], [:array, [:lit, 42]]]],
925
- "ParseTree" => s(:block,
926
- s(:lasgn, :a, s(:array)),
927
- s(:call, s(:lvar, :a), :[],
928
- s(:arglist, s(:lit, 42)))))
929
-
930
- add_tests("call_index_no_args",
931
- "Ruby" => "a[]",
932
- "RawParseTree" => [:call, [:vcall, :a], :[]],
933
- "ParseTree" => s(:call, s(:call, nil, :a, s(:arglist)),
934
- :[], s(:arglist)))
935
-
936
- add_tests("call_index_space",
937
- "Ruby" => "a = []\na [42]\n",
938
- "RawParseTree" => [:block,
939
- [:lasgn, :a, [:zarray]],
940
- [:call, [:lvar, :a], :[], [:array, [:lit, 42]]]],
941
- "ParseTree" => s(:block,
942
- s(:lasgn, :a, s(:array)),
943
- s(:call, s(:lvar, :a), :[],
944
- s(:arglist, s(:lit, 42)))),
945
- "Ruby2Ruby" => "a = []\na[42]\n")
946
-
947
- add_tests("call_unary_neg",
948
- "Ruby" => "-2**31",
949
- "RawParseTree" => [:call,
950
- [:call, [:lit, 2], :**, [:array, [:lit, 31]]],
951
- :-@],
952
- "ParseTree" => s(:call,
953
- s(:call,
954
- s(:lit, 2),
955
- :**,
956
- s(:arglist, s(:lit, 31))),
957
- :-@, s(:arglist)),
958
- "Ruby2Ruby" => "-(2 ** 31)")
959
-
960
- add_tests("case",
961
- "Ruby" => "var = 2\nresult = \"\"\ncase var\nwhen 1 then\n puts(\"something\")\n result = \"red\"\nwhen 2, 3 then\n result = \"yellow\"\nwhen 4 then\n # do nothing\nelse\n result = \"green\"\nend\ncase result\nwhen \"red\" then\n var = 1\nwhen \"yellow\" then\n var = 2\nwhen \"green\" then\n var = 3\nelse\n # do nothing\nend\n",
962
- "RawParseTree" => [:block,
963
- [:lasgn, :var, [:lit, 2]],
964
- [:lasgn, :result, [:str, ""]],
965
- [:case,
966
- [:lvar, :var],
967
- [:when,
968
- [:array, [:lit, 1]],
969
- [:block,
970
- [:fcall, :puts,
971
- [:array, [:str, "something"]]],
972
- [:lasgn, :result, [:str, "red"]]]],
973
- [:when,
974
- [:array, [:lit, 2], [:lit, 3]],
975
- [:lasgn, :result, [:str, "yellow"]]],
976
- [:when, [:array, [:lit, 4]], nil],
977
- [:lasgn, :result, [:str, "green"]]],
978
- [:case,
979
- [:lvar, :result],
980
- [:when, [:array, [:str, "red"]],
981
- [:lasgn, :var, [:lit, 1]]],
982
- [:when, [:array, [:str, "yellow"]],
983
- [:lasgn, :var, [:lit, 2]]],
984
- [:when, [:array, [:str, "green"]],
985
- [:lasgn, :var, [:lit, 3]]],
986
- nil]],
987
- "ParseTree" => s(:block,
988
- s(:lasgn, :var, s(:lit, 2)),
989
- s(:lasgn, :result, s(:str, "")),
990
- s(:case,
991
- s(:lvar, :var),
992
- s(:when,
993
- s(:array, s(:lit, 1)),
994
- s(:block,
995
- s(:call, nil, :puts,
996
- s(:arglist, s(:str, "something"))),
997
- s(:lasgn, :result, s(:str, "red")))),
998
- s(:when,
999
- s(:array, s(:lit, 2), s(:lit, 3)),
1000
- s(:lasgn, :result, s(:str, "yellow"))),
1001
- s(:when, s(:array, s(:lit, 4)), nil),
1002
- s(:lasgn, :result, s(:str, "green"))),
1003
- s(:case,
1004
- s(:lvar, :result),
1005
- s(:when, s(:array, s(:str, "red")),
1006
- s(:lasgn, :var, s(:lit, 1))),
1007
- s(:when, s(:array, s(:str, "yellow")),
1008
- s(:lasgn, :var, s(:lit, 2))),
1009
- s(:when, s(:array, s(:str, "green")),
1010
- s(:lasgn, :var, s(:lit, 3))),
1011
- nil)))
1012
-
1013
- add_tests("case_nested",
1014
- "Ruby" => "var1 = 1\nvar2 = 2\nresult = nil\ncase var1\nwhen 1 then\n case var2\n when 1 then\n result = 1\n when 2 then\n result = 2\n else\n result = 3\n end\nwhen 2 then\n case var2\n when 1 then\n result = 4\n when 2 then\n result = 5\n else\n result = 6\n end\nelse\n result = 7\nend\n",
1015
- "RawParseTree" => [:block,
1016
- [:lasgn, :var1, [:lit, 1]],
1017
- [:lasgn, :var2, [:lit, 2]],
1018
- [:lasgn, :result, [:nil]],
1019
- [:case,
1020
- [:lvar, :var1],
1021
- [:when, [:array, [:lit, 1]],
1022
- [:case,
1023
- [:lvar, :var2],
1024
- [:when, [:array, [:lit, 1]],
1025
- [:lasgn, :result, [:lit, 1]]],
1026
- [:when, [:array, [:lit, 2]],
1027
- [:lasgn, :result, [:lit, 2]]],
1028
- [:lasgn, :result, [:lit, 3]]]],
1029
- [:when, [:array, [:lit, 2]],
1030
- [:case,
1031
- [:lvar, :var2],
1032
- [:when, [:array, [:lit, 1]],
1033
- [:lasgn, :result, [:lit, 4]]],
1034
- [:when, [:array, [:lit, 2]],
1035
- [:lasgn, :result, [:lit, 5]]],
1036
- [:lasgn, :result, [:lit, 6]]]],
1037
- [:lasgn, :result, [:lit, 7]]]],
1038
- "ParseTree" => s(:block,
1039
- s(:lasgn, :var1, s(:lit, 1)),
1040
- s(:lasgn, :var2, s(:lit, 2)),
1041
- s(:lasgn, :result, s(:nil)),
1042
- s(:case,
1043
- s(:lvar, :var1),
1044
- s(:when, s(:array, s(:lit, 1)),
1045
- s(:case,
1046
- s(:lvar, :var2),
1047
- s(:when, s(:array, s(:lit, 1)),
1048
- s(:lasgn, :result, s(:lit, 1))),
1049
- s(:when, s(:array, s(:lit, 2)),
1050
- s(:lasgn, :result, s(:lit, 2))),
1051
- s(:lasgn, :result, s(:lit, 3)))),
1052
- s(:when, s(:array, s(:lit, 2)),
1053
- s(:case,
1054
- s(:lvar, :var2),
1055
- s(:when, s(:array, s(:lit, 1)),
1056
- s(:lasgn, :result, s(:lit, 4))),
1057
- s(:when, s(:array, s(:lit, 2)),
1058
- s(:lasgn, :result, s(:lit, 5))),
1059
- s(:lasgn, :result, s(:lit, 6)))),
1060
- s(:lasgn, :result, s(:lit, 7)))))
1061
-
1062
- add_tests("case_nested_inner_no_expr",
1063
- "Ruby" => "case a\nwhen b then\n case\n when (d and e) then\n f\n else\n # do nothing\n end\nelse\n # do nothing\nend",
1064
- "RawParseTree" => [:case, [:vcall, :a],
1065
- [:when, [:array, [:vcall, :b]],
1066
- [:case, nil,
1067
- [:when,
1068
- [:array, [:and, [:vcall, :d], [:vcall, :e]]],
1069
- [:vcall, :f]],
1070
- nil]],
1071
- nil],
1072
- "ParseTree" => s(:case, s(:call, nil, :a, s(:arglist)),
1073
- s(:when,
1074
- s(:array, s(:call, nil, :b, s(:arglist))),
1075
- s(:case, nil,
1076
- s(:when,
1077
- s(:array,
1078
- s(:and,
1079
- s(:call, nil, :d, s(:arglist)),
1080
- s(:call, nil, :e, s(:arglist)))),
1081
- s(:call, nil, :f, s(:arglist))),
1082
- nil)),
1083
- nil))
1084
-
1085
- add_tests("case_no_expr",
1086
- "Ruby" => "case\nwhen (a == 1) then\n :a\nwhen (a == 2) then\n :b\nelse\n :c\nend",
1087
- "RawParseTree" => [:case, nil,
1088
- [:when,
1089
- [:array,
1090
- [:call, [:vcall, :a], :==,
1091
- [:array, [:lit, 1]]]],
1092
- [:lit, :a]],
1093
- [:when,
1094
- [:array,
1095
- [:call, [:vcall, :a], :==,
1096
- [:array, [:lit, 2]]]],
1097
- [:lit, :b]],
1098
- [:lit, :c]],
1099
- "ParseTree" => s(:case, nil,
1100
- s(:when,
1101
- s(:array,
1102
- s(:call,
1103
- s(:call, nil, :a, s(:arglist)),
1104
- :==,
1105
- s(:arglist, s(:lit, 1)))),
1106
- s(:lit, :a)),
1107
- s(:when,
1108
- s(:array,
1109
- s(:call,
1110
- s(:call, nil, :a, s(:arglist)),
1111
- :==,
1112
- s(:arglist, s(:lit, 2)))),
1113
- s(:lit, :b)),
1114
- s(:lit, :c)))
1115
-
1116
- add_tests("case_splat",
1117
- "Ruby" => "case a\nwhen :b, *c then\n d\nelse\n e\nend",
1118
- "RawParseTree" => [:case, [:vcall, :a],
1119
- [:when,
1120
- [:array,
1121
- [:lit, :b], [:when, [:vcall, :c], nil]], # wtf?
1122
- [:vcall, :d]],
1123
- [:vcall, :e]],
1124
- "ParseTree" => s(:case, s(:call, nil, :a, s(:arglist)),
1125
- s(:when,
1126
- s(:array,
1127
- s(:lit, :b),
1128
- s(:when,
1129
- s(:call, nil, :c, s(:arglist)),
1130
- nil)), # wtf?
1131
- s(:call, nil, :d, s(:arglist))),
1132
- s(:call, nil, :e, s(:arglist))))
1133
-
1134
- add_tests("cdecl",
1135
- "Ruby" => "X = 42",
1136
- "RawParseTree" => [:cdecl, :X, [:lit, 42]],
1137
- "ParseTree" => s(:cdecl, :X, s(:lit, 42)))
1138
-
1139
- add_tests("class_plain",
1140
- "Ruby" => "class X\n puts((1 + 1))\n def blah\n puts(\"hello\")\n end\nend",
1141
- "RawParseTree" => [:class,
1142
- :X,
1143
- nil,
1144
- [:scope,
1145
- [:block,
1146
- [:fcall, :puts,
1147
- [:array,
1148
- [:call, [:lit, 1], :+,
1149
- [:array, [:lit, 1]]]]],
1150
- [:defn, :blah,
1151
- [:scope,
1152
- [:block,
1153
- [:args],
1154
- [:fcall, :puts,
1155
- [:array, [:str, "hello"]]]]]]]]],
1156
- "ParseTree" => s(:class,
1157
- :X,
1158
- nil,
1159
- s(:scope,
1160
- s(:block,
1161
- s(:call, nil, :puts,
1162
- s(:arglist,
1163
- s(:call, s(:lit, 1), :+,
1164
- s(:arglist, s(:lit, 1))))),
1165
- s(:defn, :blah,
1166
- s(:args),
1167
- s(:scope,
1168
- s(:block,
1169
- s(:call, nil, :puts,
1170
- s(:arglist,
1171
- s(:str, "hello"))))))))))
1172
-
1173
- add_tests("class_scoped",
1174
- "Ruby" => "class X::Y\n c\nend",
1175
- "RawParseTree" => [:class, [:colon2, [:const, :X], :Y], nil,
1176
- [:scope, [:vcall, :c]]],
1177
- "ParseTree" => s(:class, s(:colon2, s(:const, :X), :Y), nil,
1178
- s(:scope, s(:call, nil, :c, s(:arglist)))))
1179
-
1180
- add_tests("class_scoped3",
1181
- "Ruby" => "class ::Y\n c\nend",
1182
- "RawParseTree" => [:class, [:colon3, :Y], nil,
1183
- [:scope, [:vcall, :c]]],
1184
- "ParseTree" => s(:class, s(:colon3, :Y), nil,
1185
- s(:scope, s(:call, nil, :c, s(:arglist)))))
1186
-
1187
- add_tests("class_super_array",
1188
- "Ruby" => "class X < Array\nend",
1189
- "RawParseTree" => [:class,
1190
- :X,
1191
- [:const, :Array],
1192
- [:scope]],
1193
- "ParseTree" => s(:class,
1194
- :X,
1195
- s(:const, :Array),
1196
- s(:scope)))
1197
-
1198
- add_tests("class_super_expr",
1199
- "Ruby" => "class X < expr\nend",
1200
- "RawParseTree" => [:class,
1201
- :X,
1202
- [:vcall, :expr],
1203
- [:scope]],
1204
- "ParseTree" => s(:class,
1205
- :X,
1206
- s(:call, nil, :expr, s(:arglist)),
1207
- s(:scope)))
1208
-
1209
- add_tests("class_super_object",
1210
- "Ruby" => "class X < Object\nend",
1211
- "RawParseTree" => [:class,
1212
- :X,
1213
- [:const, :Object],
1214
- [:scope]],
1215
- "ParseTree" => s(:class,
1216
- :X,
1217
- s(:const, :Object),
1218
- s(:scope)))
1219
-
1220
- add_tests("colon2",
1221
- "Ruby" => "X::Y",
1222
- "RawParseTree" => [:colon2, [:const, :X], :Y],
1223
- "ParseTree" => s(:colon2, s(:const, :X), :Y))
1224
-
1225
- add_tests("colon3",
1226
- "Ruby" => "::X",
1227
- "RawParseTree" => [:colon3, :X],
1228
- "ParseTree" => s(:colon3, :X))
1229
-
1230
- add_tests("const",
1231
- "Ruby" => "X",
1232
- "RawParseTree" => [:const, :X],
1233
- "ParseTree" => s(:const, :X))
1234
-
1235
- add_tests("constX",
1236
- "Ruby" => "X = 1",
1237
- "RawParseTree" => [:cdecl, :X, [:lit, 1]],
1238
- "ParseTree" => s(:cdecl, :X, s(:lit, 1)))
1239
-
1240
- add_tests("constY",
1241
- "Ruby" => "::X = 1",
1242
- "RawParseTree" => [:cdecl, [:colon3, :X], [:lit, 1]],
1243
- "ParseTree" => s(:cdecl, s(:colon3, :X), s(:lit, 1)))
1244
-
1245
- add_tests("constZ",
1246
- "Ruby" => "X::Y = 1",
1247
- "RawParseTree" => [:cdecl, [:colon2, [:const, :X], :Y], [:lit, 1]],
1248
- "ParseTree" => s(:cdecl,
1249
- s(:colon2, s(:const, :X), :Y),
1250
- s(:lit, 1)))
1251
-
1252
- add_tests("cvar",
1253
- "Ruby" => "@@x",
1254
- "RawParseTree" => [:cvar, :@@x],
1255
- "ParseTree" => s(:cvar, :@@x))
1256
-
1257
- add_tests("cvasgn",
1258
- "Ruby" => "def x\n @@blah = 1\nend",
1259
- "RawParseTree" => [:defn, :x,
1260
- [:scope,
1261
- [:block, [:args],
1262
- [:cvasgn, :@@blah, [:lit, 1]]]]],
1263
- "ParseTree" => s(:defn, :x,
1264
- s(:args),
1265
- s(:scope,
1266
- s(:block,
1267
- s(:cvasgn, :@@blah, s(:lit, 1))))))
1268
-
1269
- add_tests("cvasgn_cls_method",
1270
- "Ruby" => "def self.quiet_mode=(boolean)\n @@quiet_mode = boolean\nend",
1271
- "RawParseTree" => [:defs, [:self], :quiet_mode=,
1272
- [:scope,
1273
- [:block,
1274
- [:args, :boolean],
1275
- [:cvasgn, :@@quiet_mode, [:lvar, :boolean]]]]],
1276
- "ParseTree" => s(:defs, s(:self), :quiet_mode=,
1277
- s(:args, :boolean),
1278
- s(:scope,
1279
- s(:block,
1280
- s(:cvasgn, :@@quiet_mode,
1281
- s(:lvar, :boolean))))))
1282
-
1283
- add_tests("cvdecl",
1284
- "Ruby" => "class X\n @@blah = 1\nend",
1285
- "RawParseTree" => [:class, :X, nil,
1286
- [:scope, [:cvdecl, :@@blah, [:lit, 1]]]],
1287
- "ParseTree" => s(:class, :X, nil,
1288
- s(:scope, s(:cvdecl, :@@blah, s(:lit, 1)))))
1289
-
1290
- add_tests("dasgn_0",
1291
- "Ruby" => "a.each { |x| b.each { |y| x = (x + 1) } if true }",
1292
- "RawParseTree" => [:iter,
1293
- [:call, [:vcall, :a], :each],
1294
- [:dasgn_curr, :x],
1295
- [:if, [:true],
1296
- [:iter,
1297
- [:call, [:vcall, :b], :each],
1298
- [:dasgn_curr, :y],
1299
- [:dasgn, :x,
1300
- [:call, [:dvar, :x], :+,
1301
- [:array, [:lit, 1]]]]],
1302
- nil]],
1303
- "ParseTree" => s(:iter,
1304
- s(:call, s(:call, nil, :a, s(:arglist)), :each,
1305
- s(:arglist)),
1306
- s(:lasgn, :x),
1307
- s(:if, s(:true),
1308
- s(:iter,
1309
- s(:call, s(:call, nil, :b, s(:arglist)),
1310
- :each,
1311
- s(:arglist)),
1312
- s(:lasgn, :y),
1313
- s(:lasgn, :x,
1314
- s(:call, s(:lvar, :x), :+,
1315
- s(:arglist, s(:lit, 1))))),
1316
- nil)))
1317
-
1318
- add_tests("dasgn_1",
1319
- "Ruby" => "a.each { |x| b.each { |y| c = (c + 1) } if true }",
1320
- "RawParseTree" => [:iter,
1321
- [:call, [:vcall, :a], :each],
1322
- [:dasgn_curr, :x],
1323
- [:if, [:true],
1324
- [:iter,
1325
- [:call, [:vcall, :b], :each],
1326
- [:dasgn_curr, :y],
1327
- [:dasgn_curr, :c,
1328
- [:call, [:dvar, :c], :+,
1329
- [:array, [:lit, 1]]]]],
1330
- nil]],
1331
- "ParseTree" => s(:iter,
1332
- s(:call, s(:call, nil, :a, s(:arglist)), :each,
1333
- s(:arglist)),
1334
- s(:lasgn, :x),
1335
- s(:if, s(:true),
1336
- s(:iter,
1337
- s(:call, s(:call, nil, :b, s(:arglist)),
1338
- :each,
1339
- s(:arglist)),
1340
- s(:lasgn, :y),
1341
- s(:lasgn, :c,
1342
- s(:call, s(:lvar, :c), :+,
1343
- s(:arglist, s(:lit, 1))))),
1344
- nil)))
1345
-
1346
- add_tests("dasgn_2",
1347
- "Ruby" => "a.each do |x|\n if true then\n c = 0\n b.each { |y| c = (c + 1) }\n end\nend", # FIX: hate that extra newline!
1348
- "RawParseTree" => [:iter,
1349
- [:call, [:vcall, :a], :each],
1350
- [:dasgn_curr, :x],
1351
- [:if, [:true],
1352
- [:block,
1353
- [:dasgn_curr, :c, [:lit, 0]],
1354
- [:iter,
1355
- [:call, [:vcall, :b], :each],
1356
- [:dasgn_curr, :y],
1357
- [:dasgn, :c,
1358
- [:call, [:dvar, :c], :+,
1359
- [:array, [:lit, 1]]]]]],
1360
- nil]],
1361
- "ParseTree" => s(:iter,
1362
- s(:call, s(:call, nil, :a, s(:arglist)), :each,
1363
- s(:arglist)),
1364
- s(:lasgn, :x),
1365
- s(:if, s(:true),
1366
- s(:block,
1367
- s(:lasgn, :c, s(:lit, 0)),
1368
- s(:iter,
1369
- s(:call, s(:call, nil, :b, s(:arglist)),
1370
- :each,
1371
- s(:arglist)),
1372
- s(:lasgn, :y),
1373
- s(:lasgn, :c,
1374
- s(:call, s(:lvar, :c), :+,
1375
- s(:arglist, s(:lit, 1)))))),
1376
- nil)))
1377
-
1378
- add_tests("dasgn_curr",
1379
- "Ruby" => "data.each do |x, y|\n a = 1\n b = a\n b = a = x\nend",
1380
- "RawParseTree" => [:iter,
1381
- [:call, [:vcall, :data], :each],
1382
- [:masgn,
1383
- [:array, [:dasgn_curr, :x], [:dasgn_curr, :y]],
1384
- nil, nil],
1385
- [:block,
1386
- [:dasgn_curr, :a, [:lit, 1]],
1387
- [:dasgn_curr, :b, [:dvar, :a]],
1388
- [:dasgn_curr, :b,
1389
- [:dasgn_curr, :a, [:dvar, :x]]]]],
1390
- "ParseTree" => s(:iter,
1391
- s(:call, s(:call, nil, :data,
1392
- s(:arglist)), :each, s(:arglist)),
1393
- s(:masgn,
1394
- s(:array, s(:lasgn, :x), s(:lasgn, :y))),
1395
- s(:block,
1396
- s(:lasgn, :a, s(:lit, 1)),
1397
- s(:lasgn, :b, s(:lvar, :a)),
1398
- s(:lasgn, :b, s(:lasgn, :a, s(:lvar, :x))))))
1399
-
1400
- add_tests("dasgn_icky",
1401
- "Ruby" => "a do\n v = nil\n assert_block(full_message) do\n begin\n yield\n rescue Exception => v\n break\n end\n end\nend",
1402
- "RawParseTree" => [:iter,
1403
- [:fcall, :a],
1404
- nil,
1405
- [:block,
1406
- [:dasgn_curr, :v, [:nil]],
1407
- [:iter,
1408
- [:fcall, :assert_block,
1409
- [:array, [:vcall, :full_message]]],
1410
- nil,
1411
- [:rescue,
1412
- [:yield],
1413
- [:resbody,
1414
- [:array, [:const, :Exception]],
1415
- [:block,
1416
- [:dasgn, :v,
1417
- [:gvar, :$!]], [:break]]]]]]],
1418
- "ParseTree" => s(:iter,
1419
- s(:call, nil, :a, s(:arglist)),
1420
- nil,
1421
- s(:block,
1422
- s(:lasgn, :v, s(:nil)),
1423
- s(:iter,
1424
- s(:call, nil, :assert_block,
1425
- s(:arglist,
1426
- s(:call, nil, :full_message,
1427
- s(:arglist)))),
1428
- nil,
1429
- s(:rescue,
1430
- s(:yield),
1431
- s(:resbody,
1432
- s(:array,
1433
- s(:const, :Exception),
1434
- s(:lasgn, :v, s(:gvar, :$!))),
1435
- s(:break)))))))
1436
-
1437
- add_tests("dasgn_mixed",
1438
- "Ruby" => "t = 0\nns.each { |n| t += n }\n",
1439
- "RawParseTree" => [:block,
1440
- [:lasgn, :t, [:lit, 0]],
1441
- [:iter,
1442
- [:call, [:vcall, :ns], :each],
1443
- [:dasgn_curr, :n],
1444
- [:lasgn, :t,
1445
- [:call, [:lvar, :t], :+,
1446
- [:array, [:dvar, :n]]]]]],
1447
- "ParseTree" => s(:block,
1448
- s(:lasgn, :t, s(:lit, 0)),
1449
- s(:iter,
1450
- s(:call, s(:call, nil, :ns,
1451
- s(:arglist)), :each, s(:arglist)),
1452
- s(:lasgn, :n),
1453
- s(:lasgn, :t,
1454
- s(:call, s(:lvar, :t), :+,
1455
- s(:arglist, s(:lvar, :n)))))),
1456
- "Ruby2Ruby" => "t = 0\nns.each { |n| t = (t + n) }\n")
1457
-
1458
- add_tests("defined",
1459
- "Ruby" => "defined? $x",
1460
- "RawParseTree" => [:defined, [:gvar, :$x]],
1461
- "ParseTree" => s(:defined, s(:gvar, :$x)))
1462
-
1463
- # TODO: make all the defn_args* p their arglist
1464
- add_tests("defn_args_block",
1465
- "Ruby" => "def f(&block)\n # do nothing\nend",
1466
- "RawParseTree" => [:defn, :f,
1467
- [:scope,
1468
- [:block,
1469
- [:args],
1470
- [:block_arg, :block],
1471
- [:nil]]]],
1472
- "ParseTree" => s(:defn, :f,
1473
- s(:args, :"&block"),
1474
- s(:scope, s(:block, s(:nil)))))
1475
-
1476
- add_tests("defn_args_mand",
1477
- "Ruby" => "def f(mand)\n # do nothing\nend",
1478
- "RawParseTree" => [:defn, :f,
1479
- [:scope,
1480
- [:block,
1481
- [:args, :mand],
1482
- [:nil]]]],
1483
- "ParseTree" => s(:defn, :f,
1484
- s(:args, :mand),
1485
- s(:scope, s(:block, s(:nil)))))
1486
-
1487
- add_tests("defn_args_mand_block",
1488
- "Ruby" => "def f(mand, &block)\n # do nothing\nend",
1489
- "RawParseTree" => [:defn, :f,
1490
- [:scope,
1491
- [:block,
1492
- [:args, :mand],
1493
- [:block_arg, :block],
1494
- [:nil]]]],
1495
- "ParseTree" => s(:defn, :f,
1496
- s(:args, :mand, :"&block"),
1497
- s(:scope, s(:block, s(:nil)))))
1498
-
1499
- add_tests("defn_args_mand_opt",
1500
- "Ruby" => "def f(mand, opt = 42)\n # do nothing\nend",
1501
- "RawParseTree" => [:defn, :f,
1502
- [:scope,
1503
- [:block,
1504
- [:args, :mand, :opt,
1505
- [:block,
1506
- [:lasgn, :opt, [:lit, 42]]]],
1507
- [:nil]]]],
1508
- "ParseTree" => s(:defn, :f,
1509
- s(:args, :mand, :opt,
1510
- s(:block,
1511
- s(:lasgn, :opt, s(:lit, 42)))),
1512
- s(:scope, s(:block, s(:nil)))))
1513
-
1514
- add_tests("defn_args_mand_opt_block",
1515
- "Ruby" => "def f(mand, opt = 42, &block)\n # do nothing\nend",
1516
- "RawParseTree" => [:defn, :f,
1517
- [:scope,
1518
- [:block,
1519
- [:args, :mand, :opt,
1520
- [:block,
1521
- [:lasgn, :opt, [:lit, 42]]]],
1522
- [:block_arg, :block],
1523
- [:nil]]]],
1524
- "ParseTree" => s(:defn, :f,
1525
- s(:args, :mand, :opt, :"&block",
1526
- s(:block,
1527
- s(:lasgn, :opt, s(:lit, 42)))),
1528
- s(:scope, s(:block, s(:nil)))))
1529
-
1530
- add_tests("defn_args_mand_opt_splat",
1531
- "Ruby" => "def f(mand, opt = 42, *rest)\n # do nothing\nend",
1532
- "RawParseTree" => [:defn, :f,
1533
- [:scope,
1534
- [:block,
1535
- [:args, :mand, :opt, :"*rest",
1536
- [:block,
1537
- [:lasgn, :opt, [:lit, 42]]]],
1538
- [:nil]]]],
1539
- "ParseTree" => s(:defn, :f,
1540
- s(:args, :mand, :opt, :"*rest",
1541
- s(:block,
1542
- s(:lasgn, :opt, s(:lit, 42)))),
1543
- s(:scope, s(:block, s(:nil)))))
1544
-
1545
- add_tests("defn_args_mand_opt_splat_block",
1546
- "Ruby" => "def f(mand, opt = 42, *rest, &block)\n # do nothing\nend",
1547
- "RawParseTree" => [:defn, :f,
1548
- [:scope,
1549
- [:block,
1550
- [:args, :mand, :opt, :"*rest",
1551
- [:block,
1552
- [:lasgn, :opt, [:lit, 42]]]],
1553
- [:block_arg, :block],
1554
- [:nil]]]],
1555
- "ParseTree" => s(:defn, :f,
1556
- s(:args, :mand, :opt, :"*rest", :"&block",
1557
- s(:block,
1558
- s(:lasgn, :opt, s(:lit, 42)))),
1559
- s(:scope, s(:block, s(:nil)))))
1560
-
1561
- add_tests("defn_args_mand_opt_splat_no_name",
1562
- "Ruby" => "def x(a, b = 42, *)\n # do nothing\nend",
1563
- "RawParseTree" => [:defn, :x,
1564
- [:scope,
1565
- [:block,
1566
- [:args, :a, :b, :"*",
1567
- [:block, [:lasgn, :b, [:lit, 42]]]],
1568
- [:nil]]]],
1569
- "ParseTree" => s(:defn, :x,
1570
- s(:args, :a, :b, :"*",
1571
- s(:block, s(:lasgn, :b, s(:lit, 42)))),
1572
- s(:scope,
1573
- s(:block,
1574
- s(:nil)))))
1575
-
1576
- add_tests("defn_args_mand_splat",
1577
- "Ruby" => "def f(mand, *rest)\n # do nothing\nend",
1578
- "RawParseTree" => [:defn, :f,
1579
- [:scope,
1580
- [:block,
1581
- [:args, :mand, :"*rest"],
1582
- [:nil]]]],
1583
- "ParseTree" => s(:defn, :f,
1584
- s(:args, :mand, :"*rest"),
1585
- s(:scope, s(:block, s(:nil)))))
1586
-
1587
- add_tests("defn_args_mand_splat_block",
1588
- "Ruby" => "def f(mand, *rest, &block)\n # do nothing\nend",
1589
- "RawParseTree" => [:defn, :f,
1590
- [:scope,
1591
- [:block,
1592
- [:args, :mand, :"*rest"],
1593
- [:block_arg, :block],
1594
- [:nil]]]],
1595
- "ParseTree" => s(:defn, :f,
1596
- s(:args, :mand, :"*rest", :"&block"),
1597
- s(:scope, s(:block, s(:nil)))))
1598
-
1599
- add_tests("defn_args_mand_splat_no_name",
1600
- "Ruby" => "def x(a, *args)\n p(a, args)\nend",
1601
- "RawParseTree" => [:defn, :x,
1602
- [:scope,
1603
- [:block,
1604
- [:args, :a, :"*args"],
1605
- [:fcall, :p,
1606
- [:array, [:lvar, :a], [:lvar, :args]]]]]],
1607
- "ParseTree" => s(:defn, :x,
1608
- s(:args, :a, :"*args"),
1609
- s(:scope,
1610
- s(:block,
1611
- s(:call, nil, :p,
1612
- s(:arglist, s(:lvar, :a), s(:lvar, :args)))))))
1613
-
1614
- add_tests("defn_args_none",
1615
- "Ruby" => "def empty\n # do nothing\nend",
1616
- "RawParseTree" => [:defn, :empty,
1617
- [:scope, [:block, [:args], [:nil]]]],
1618
- "ParseTree" => s(:defn, :empty,
1619
- s(:args),
1620
- s(:scope, s(:block, s(:nil)))))
1621
-
1622
- add_tests("defn_args_opt",
1623
- "Ruby" => "def f(opt = 42)\n # do nothing\nend",
1624
- "RawParseTree" => [:defn, :f,
1625
- [:scope,
1626
- [:block,
1627
- [:args, :opt,
1628
- [:block,
1629
- [:lasgn, :opt, [:lit, 42]]]],
1630
- [:nil]]]],
1631
- "ParseTree" => s(:defn, :f,
1632
- s(:args, :opt,
1633
- s(:block,
1634
- s(:lasgn, :opt, s(:lit, 42)))),
1635
- s(:scope, s(:block, s(:nil)))))
1636
-
1637
- add_tests("defn_args_opt_block",
1638
- "Ruby" => "def f(opt = 42, &block)\n # do nothing\nend",
1639
- "RawParseTree" => [:defn, :f,
1640
- [:scope,
1641
- [:block,
1642
- [:args, :opt,
1643
- [:block,
1644
- [:lasgn, :opt, [:lit, 42]]]],
1645
- [:block_arg, :block],
1646
- [:nil]]]],
1647
- "ParseTree" => s(:defn, :f,
1648
- s(:args, :opt, :"&block",
1649
- s(:block,
1650
- s(:lasgn, :opt, s(:lit, 42)))),
1651
- s(:scope, s(:block, s(:nil)))))
1652
-
1653
- add_tests("defn_args_opt_splat",
1654
- "Ruby" => "def f(opt = 42, *rest)\n # do nothing\nend",
1655
- "RawParseTree" => [:defn, :f,
1656
- [:scope,
1657
- [:block,
1658
- [:args, :opt, :"*rest",
1659
- [:block,
1660
- [:lasgn, :opt, [:lit, 42]]]],
1661
- [:nil]]]],
1662
- "ParseTree" => s(:defn, :f,
1663
- s(:args, :opt, :"*rest",
1664
- s(:block,
1665
- s(:lasgn, :opt, s(:lit, 42)))),
1666
- s(:scope, s(:block, s(:nil)))))
1667
-
1668
- add_tests("defn_args_opt_splat_block",
1669
- "Ruby" => "def f(opt = 42, *rest, &block)\n # do nothing\nend",
1670
- "RawParseTree" => [:defn, :f,
1671
- [:scope,
1672
- [:block,
1673
- [:args, :opt, :"*rest",
1674
- [:block,
1675
- [:lasgn, :opt, [:lit, 42]]]],
1676
- [:block_arg, :block],
1677
- [:nil]]]],
1678
- "ParseTree" => s(:defn, :f,
1679
- s(:args, :opt, :"*rest", :"&block",
1680
- s(:block,
1681
- s(:lasgn, :opt, s(:lit, 42)))),
1682
- s(:scope, s(:block, s(:nil)))))
1683
-
1684
- add_tests("defn_args_opt_splat_no_name",
1685
- "Ruby" => "def x(b = 42, *)\n # do nothing\nend",
1686
- "RawParseTree" => [:defn, :x,
1687
- [:scope,
1688
- [:block,
1689
- [:args, :b, :"*",
1690
- [:block, [:lasgn, :b, [:lit, 42]]]],
1691
- [:nil]]]],
1692
- "ParseTree" => s(:defn, :x,
1693
- s(:args, :b, :"*",
1694
- s(:block, s(:lasgn, :b, s(:lit, 42)))),
1695
- s(:scope,
1696
- s(:block,
1697
- s(:nil)))))
1698
-
1699
- add_tests("defn_args_splat",
1700
- "Ruby" => "def f(*rest)\n # do nothing\nend",
1701
- "RawParseTree" => [:defn, :f,
1702
- [:scope,
1703
- [:block,
1704
- [:args, :"*rest"],
1705
- [:nil]]]],
1706
- "ParseTree" => s(:defn, :f,
1707
- s(:args, :"*rest"),
1708
- s(:scope, s(:block, s(:nil)))))
1709
-
1710
- add_tests("defn_args_splat_no_name",
1711
- "Ruby" => "def x(*)\n # do nothing\nend",
1712
- "RawParseTree" => [:defn, :x,
1713
- [:scope,
1714
- [:block,
1715
- [:args, :"*"],
1716
- [:nil]]]],
1717
- "ParseTree" => s(:defn, :x,
1718
- s(:args, :"*"),
1719
- s(:scope,
1720
- s(:block,
1721
- s(:nil)))))
1722
-
1723
- add_tests("defn_or",
1724
- "Ruby" => "def |(o)\n # do nothing\nend",
1725
- "RawParseTree" => [:defn, :|,
1726
- [:scope, [:block, [:args, :o], [:nil]]]],
1727
- "ParseTree" => s(:defn, :|,
1728
- s(:args, :o),
1729
- s(:scope, s(:block, s(:nil)))))
1730
-
1731
- add_tests("defn_rescue",
1732
- "Ruby" => "def eql?(resource)\n (self.uuid == resource.uuid)\nrescue\n false\nend",
1733
- "RawParseTree" => [:defn, :eql?,
1734
- [:scope,
1735
- [:block,
1736
- [:args, :resource],
1737
- [:rescue,
1738
- [:call,
1739
- [:call, [:self], :uuid],
1740
- :==,
1741
- [:array,
1742
- [:call, [:lvar, :resource], :uuid]]],
1743
- [:resbody, nil, [:false]]]]]],
1744
- "ParseTree" => s(:defn, :eql?,
1745
- s(:args, :resource),
1746
- s(:scope,
1747
- s(:block,
1748
- s(:rescue,
1749
- s(:call,
1750
- s(:call, s(:self), :uuid, s(:arglist)),
1751
- :==,
1752
- s(:arglist,
1753
- s(:call, s(:lvar, :resource),
1754
- :uuid, s(:arglist)))),
1755
- s(:resbody, s(:array), s(:false)))))),
1756
- "Ruby2Ruby" => "def eql?(resource)\n (self.uuid == resource.uuid) rescue false\nend")
1757
-
1758
- add_tests("defn_rescue_mri_verbose_flag",
1759
- "Ruby" => "def eql?(resource)\n (self.uuid == resource.uuid)\nrescue\n false\nend",
1760
- "RawParseTree" => [:defn, :eql?,
1761
- [:scope,
1762
- [:block,
1763
- [:args, :resource],
1764
- [:rescue,
1765
- [:call,
1766
- [:call, [:self], :uuid],
1767
- :==,
1768
- [:array,
1769
- [:call, [:lvar, :resource], :uuid]]],
1770
- [:resbody, nil, [:false]]]]]],
1771
- "ParseTree" => s(:defn, :eql?,
1772
- s(:args, :resource),
1773
- s(:scope,
1774
- s(:block,
1775
- s(:rescue,
1776
- s(:call,
1777
- s(:call, s(:self), :uuid, s(:arglist)),
1778
- :==,
1779
- s(:arglist,
1780
- s(:call, s(:lvar, :resource),
1781
- :uuid, s(:arglist)))),
1782
- s(:resbody, s(:array), s(:false)))))),
1783
- "Ruby2Ruby" => "def eql?(resource)\n (self.uuid == resource.uuid) rescue false\nend")
1784
-
1785
- add_tests("defn_something_eh",
1786
- "Ruby" => "def something?\n # do nothing\nend",
1787
- "RawParseTree" => [:defn, :something?,
1788
- [:scope, [:block, [:args], [:nil]]]],
1789
- "ParseTree" => s(:defn, :something?,
1790
- s(:args),
1791
- s(:scope, s(:block, s(:nil)))))
1792
-
1793
- add_tests("defn_splat_no_name",
1794
- "Ruby" => "def x(a, *)\n p(a)\nend",
1795
- "RawParseTree" => [:defn, :x,
1796
- [:scope,
1797
- [:block,
1798
- [:args, :a, :"*"],
1799
- [:fcall, :p,
1800
- [:array, [:lvar, :a]]]]]],
1801
- "ParseTree" => s(:defn, :x,
1802
- s(:args, :a, :"*"),
1803
- s(:scope,
1804
- s(:block,
1805
- s(:call, nil, :p,
1806
- s(:arglist, s(:lvar, :a)))))))
1807
-
1808
- add_tests("defn_zarray",
1809
- "Ruby" => "def zarray\n a = []\n return a\nend",
1810
- "RawParseTree" => [:defn, :zarray,
1811
- [:scope,
1812
- [:block, [:args],
1813
- [:lasgn, :a, [:zarray]],
1814
- [:return, [:lvar, :a]]]]],
1815
- "ParseTree" => s(:defn, :zarray,
1816
- s(:args),
1817
- s(:scope,
1818
- s(:block,
1819
- s(:lasgn, :a, s(:array)),
1820
- s(:return, s(:lvar, :a))))))
1821
-
1822
- add_tests("defs",
1823
- "Ruby" => "def self.x(y)\n (y + 1)\nend",
1824
- "RawParseTree" => [:defs, [:self], :x,
1825
- [:scope,
1826
- [:block,
1827
- [:args, :y],
1828
- [:call, [:lvar, :y], :+,
1829
- [:array, [:lit, 1]]]]]],
1830
- "ParseTree" => s(:defs, s(:self), :x,
1831
- s(:args, :y),
1832
- s(:scope,
1833
- s(:block,
1834
- s(:call, s(:lvar, :y), :+,
1835
- s(:arglist, s(:lit, 1)))))))
1836
-
1837
- add_tests("defs_empty",
1838
- "Ruby" => "def self.empty\n # do nothing\nend",
1839
- "RawParseTree" => [:defs, [:self], :empty,
1840
- [:scope, [:args]]],
1841
- "ParseTree" => s(:defs, s(:self), :empty,
1842
- s(:args),
1843
- s(:scope, s(:block))))
1844
-
1845
- add_tests("defs_empty_args",
1846
- "Ruby" => "def self.empty(*)\n # do nothing\nend",
1847
- "RawParseTree" => [:defs, [:self], :empty,
1848
- [:scope, [:args, :*]]],
1849
- "ParseTree" => s(:defs, s(:self), :empty,
1850
- s(:args, :*),
1851
- s(:scope, s(:block))))
1852
-
1853
- add_tests("defs_expr_wtf",
1854
- "Ruby" => "def (a.b).empty(*)\n # do nothing\nend",
1855
- "RawParseTree" => [:defs,
1856
- [:call, [:vcall, :a], :b],
1857
- :empty,
1858
- [:scope, [:args, :*]]],
1859
- "ParseTree" => s(:defs,
1860
- s(:call,
1861
- s(:call, nil, :a, s(:arglist)),
1862
- :b, s(:arglist)),
1863
- :empty,
1864
- s(:args, :*),
1865
- s(:scope, s(:block))))
1866
-
1867
- add_tests("dmethod",
1868
- "Ruby" => [Examples, :dmethod_added],
1869
- "RawParseTree" => [:defn, :dmethod_added,
1870
- [:dmethod,
1871
- :a_method,
1872
- [:scope,
1873
- [:block,
1874
- [:args, :x],
1875
- [:call, [:lvar, :x], :+,
1876
- [:array, [:lit, 1]]]]]]],
1877
- "ParseTree" => s(:defn, :dmethod_added,
1878
- s(:args, :x),
1879
- s(:scope,
1880
- s(:block,
1881
- s(:call, s(:lvar, :x), :+,
1882
- s(:arglist, s(:lit, 1)))))),
1883
- "Ruby2Ruby" => "def dmethod_added(x)\n (x + 1)\nend")
1884
-
1885
- add_tests("dot2",
1886
- "Ruby" => "(a..b)",
1887
- "RawParseTree" => [:dot2, [:vcall, :a], [:vcall, :b]],
1888
- "ParseTree" => s(:dot2,
1889
- s(:call, nil, :a, s(:arglist)),
1890
- s(:call, nil, :b, s(:arglist))))
1891
-
1892
- add_tests("dot3",
1893
- "Ruby" => "(a...b)",
1894
- "RawParseTree" => [:dot3, [:vcall, :a], [:vcall, :b]],
1895
- "ParseTree" => s(:dot3,
1896
- s(:call, nil, :a, s(:arglist)),
1897
- s(:call, nil, :b, s(:arglist))))
1898
-
1899
- add_tests("dregx",
1900
- "Ruby" => "/x#\{(1 + 1)}y/",
1901
- "RawParseTree" => [:dregx, "x",
1902
- [:evstr,
1903
- [:call, [:lit, 1], :+, [:array, [:lit, 1]]]],
1904
- [:str, "y"]],
1905
- "ParseTree" => s(:dregx, "x",
1906
- s(:evstr,
1907
- s(:call, s(:lit, 1), :+,
1908
- s(:arglist, s(:lit, 1)))),
1909
- s(:str, "y")))
1910
-
1911
- add_tests("dregx_interp",
1912
- "Ruby" => "/#\{@rakefile}/",
1913
- "RawParseTree" => [:dregx, '', [:evstr, [:ivar, :@rakefile]]],
1914
- "ParseTree" => s(:dregx, '', s(:evstr, s(:ivar, :@rakefile))))
1915
-
1916
- add_tests("dregx_interp_empty",
1917
- "Ruby" => "/a#\{}b/",
1918
- "RawParseTree" => [:dregx, 'a', [:evstr], [:str, "b"]],
1919
- "ParseTree" => s(:dregx, 'a', s(:evstr), s(:str, "b")))
1920
-
1921
- add_tests("dregx_n",
1922
- "Ruby" => '/#{1}/n',
1923
- "RawParseTree" => [:dregx, '', [:evstr, [:lit, 1]], /x/n.options],
1924
- "ParseTree" => s(:dregx, '',
1925
- s(:evstr, s(:lit, 1)), /x/n.options),
1926
- "Ruby2Ruby" => "/#\{1}/") # HACK - need to support regexp flag
1927
-
1928
- add_tests("dregx_once",
1929
- "Ruby" => "/x#\{(1 + 1)}y/o",
1930
- "RawParseTree" => [:dregx_once, "x",
1931
- [:evstr,
1932
- [:call, [:lit, 1], :+, [:array, [:lit, 1]]]],
1933
- [:str, "y"]],
1934
- "ParseTree" => s(:dregx_once, "x",
1935
- s(:evstr,
1936
- s(:call, s(:lit, 1), :+,
1937
- s(:arglist, s(:lit, 1)))),
1938
- s(:str, "y")))
1939
-
1940
- add_tests("dregx_once_n_interp",
1941
- "Ruby" => "/#\{IAC}#\{SB}/no",
1942
- "RawParseTree" => [:dregx_once, '',
1943
- [:evstr, [:const, :IAC]],
1944
- [:evstr, [:const, :SB]], /x/n.options],
1945
- "ParseTree" => s(:dregx_once, '',
1946
- s(:evstr, s(:const, :IAC)),
1947
- s(:evstr, s(:const, :SB)), /x/n.options),
1948
- "Ruby2Ruby" => "/#\{IAC}#\{SB}/o") # HACK
1949
-
1950
- add_tests("dstr",
1951
- "Ruby" => "argl = 1\n\"x#\{argl}y\"\n",
1952
- "RawParseTree" => [:block,
1953
- [:lasgn, :argl, [:lit, 1]],
1954
- [:dstr, "x", [:evstr, [:lvar, :argl]],
1955
- [:str, "y"]]],
1956
- "ParseTree" => s(:block,
1957
- s(:lasgn, :argl, s(:lit, 1)),
1958
- s(:dstr, "x", s(:evstr, s(:lvar, :argl)),
1959
- s(:str, "y"))))
1960
-
1961
- add_tests("dstr_2",
1962
- "Ruby" => "argl = 1\n\"x#\{(\"%.2f\" % 3.14159)}y\"\n",
1963
- "RawParseTree" => [:block,
1964
- [:lasgn, :argl, [:lit, 1]],
1965
- [:dstr,
1966
- "x",
1967
- [:evstr,
1968
- [:call, [:str, "%.2f"], :%,
1969
- [:array, [:lit, 3.14159]]]],
1970
- [:str, "y"]]],
1971
- "ParseTree" => s(:block,
1972
- s(:lasgn, :argl, s(:lit, 1)),
1973
- s(:dstr,
1974
- "x",
1975
- s(:evstr,
1976
- s(:call, s(:str, "%.2f"), :%,
1977
- s(:arglist, s(:lit, 3.14159)))),
1978
- s(:str, "y"))))
1979
-
1980
- add_tests("dstr_3",
1981
- "Ruby" => "max = 2\nargl = 1\n\"x#\{(\"%.#\{max}f\" % 3.14159)}y\"\n",
1982
- "RawParseTree" => [:block,
1983
- [:lasgn, :max, [:lit, 2]],
1984
- [:lasgn, :argl, [:lit, 1]],
1985
- [:dstr, "x",
1986
- [:evstr,
1987
- [:call,
1988
- [:dstr, "%.",
1989
- [:evstr, [:lvar, :max]],
1990
- [:str, "f"]],
1991
- :%,
1992
- [:array, [:lit, 3.14159]]]],
1993
- [:str, "y"]]],
1994
- "ParseTree" => s(:block,
1995
- s(:lasgn, :max, s(:lit, 2)),
1996
- s(:lasgn, :argl, s(:lit, 1)),
1997
- s(:dstr, "x",
1998
- s(:evstr,
1999
- s(:call,
2000
- s(:dstr, "%.",
2001
- s(:evstr, s(:lvar, :max)),
2002
- s(:str, "f")),
2003
- :%,
2004
- s(:arglist, s(:lit, 3.14159)))),
2005
- s(:str, "y"))))
2006
-
2007
- add_tests("dstr_concat",
2008
- "Ruby" => '"#{22}aa" "cd#{44}" "55" "#{66}"',
2009
- "RawParseTree" => [:dstr,
2010
- "",
2011
- [:evstr, [:lit, 22]],
2012
- [:str, "aa"],
2013
- [:str, "cd"],
2014
- [:evstr, [:lit, 44]],
2015
- [:str, "55"],
2016
- [:evstr, [:lit, 66]]],
2017
- "ParseTree" => s(:dstr,
2018
- "",
2019
- s(:evstr, s(:lit, 22)),
2020
- s(:str, "aa"),
2021
- s(:str, "cd"),
2022
- s(:evstr, s(:lit, 44)),
2023
- s(:str, "55"),
2024
- s(:evstr, s(:lit, 66))),
2025
- "Ruby2Ruby" => '"#{22}aacd#{44}55#{66}"')
2026
-
2027
- add_tests("dstr_gross",
2028
- "Ruby" => '"a #$global b #@ivar c #@@cvar d"',
2029
- "RawParseTree" => [:dstr, "a ",
2030
- [:evstr, [:gvar, :$global]],
2031
- [:str, " b "],
2032
- [:evstr, [:ivar, :@ivar]],
2033
- [:str, " c "],
2034
- [:evstr, [:cvar, :@@cvar]],
2035
- [:str, " d"]],
2036
- "ParseTree" => s(:dstr, "a ",
2037
- s(:evstr, s(:gvar, :$global)),
2038
- s(:str, " b "),
2039
- s(:evstr, s(:ivar, :@ivar)),
2040
- s(:str, " c "),
2041
- s(:evstr, s(:cvar, :@@cvar)),
2042
- s(:str, " d")),
2043
- "Ruby2Ruby" => '"a #{$global} b #{@ivar} c #{@@cvar} d"')
2044
-
2045
- add_tests("dstr_heredoc_expand",
2046
- "Ruby" => "<<EOM\n blah\n#\{1 + 1}blah\nEOM\n",
2047
- "RawParseTree" => [:dstr, " blah\n",
2048
- [:evstr, [:call, [:lit, 1], :+,
2049
- [:array, [:lit, 1]]]],
2050
- [:str, "blah\n"]],
2051
- "ParseTree" => s(:dstr, " blah\n",
2052
- s(:evstr, s(:call, s(:lit, 1), :+,
2053
- s(:arglist, s(:lit, 1)))),
2054
- s(:str, "blah\n")),
2055
- "Ruby2Ruby" => "\" blah\\n#\{(1 + 1)}blah\\n\"")
2056
-
2057
- add_tests("dstr_heredoc_windoze_sucks",
2058
- "Ruby" => "<<-EOF\r\ndef test_#\{action}_valid_feed\r\n EOF\r\n",
2059
- "RawParseTree" => [:dstr,
2060
- 'def test_',
2061
- [:evstr, [:vcall, :action]],
2062
- [:str, "_valid_feed\n"]],
2063
- "ParseTree" => s(:dstr,
2064
- 'def test_',
2065
- s(:evstr, s(:call, nil, :action, s(:arglist))),
2066
- s(:str, "_valid_feed\n")),
2067
- "Ruby2Ruby" => "\"def test_#\{action}_valid_feed\\n\"")
2068
-
2069
- add_tests("dstr_heredoc_yet_again",
2070
- "Ruby" => "<<-EOF\ns1 '#\{RUBY_PLATFORM}' s2\n#\{__FILE__}\n EOF\n",
2071
- "RawParseTree" => [:dstr, "s1 '",
2072
- [:evstr, [:const, :RUBY_PLATFORM]],
2073
- [:str, "' s2\n"],
2074
- [:str, "(string)"],
2075
- [:str, "\n"]],
2076
- "ParseTree" => s(:dstr, "s1 '",
2077
- s(:evstr, s(:const, :RUBY_PLATFORM)),
2078
- s(:str, "' s2\n"),
2079
- s(:str, "(string)"),
2080
- s(:str, "\n")),
2081
- "Ruby2Ruby" => "\"s1 '#\{RUBY_PLATFORM}' s2\\n(string)\\n\"")
2082
-
2083
- add_tests("dstr_nest",
2084
- "Ruby" => "%Q[before [#\{nest}] after]",
2085
- "RawParseTree" => [:dstr, "before [",
2086
- [:evstr, [:vcall, :nest]], [:str, "] after"]],
2087
- "ParseTree" => s(:dstr, "before [",
2088
- s(:evstr, s(:call, nil, :nest, s(:arglist))),
2089
- s(:str, "] after")),
2090
- "Ruby2Ruby" => "\"before [#\{nest}] after\"")
2091
-
2092
- add_tests("dstr_str_lit_start",
2093
- "Ruby" => '"#{"blah"}#{__FILE__}:#{__LINE__}: warning: #{$!.message} (#{$!.class})"',
2094
- "RawParseTree" => [:dstr,
2095
- "blah(string):",
2096
- [:evstr, [:lit, 1]],
2097
- [:str, ": warning: "],
2098
- [:evstr, [:call, [:gvar, :$!], :message]],
2099
- [:str, " ("],
2100
- [:evstr, [:call, [:gvar, :$!], :class]],
2101
- [:str, ")"]],
2102
- "ParseTree" => s(:dstr,
2103
- "blah(string):",
2104
- s(:evstr, s(:lit, 1)),
2105
- s(:str, ": warning: "),
2106
- s(:evstr, s(:call, s(:gvar, :$!), :message,
2107
- s(:arglist))),
2108
- s(:str, " ("),
2109
- s(:evstr, s(:call, s(:gvar, :$!), :class,
2110
- s(:arglist))),
2111
- s(:str, ")")),
2112
- "Ruby2Ruby" => '"blah(string):#{1}: warning: #{$!.message} (#{$!.class})"')
2113
-
2114
- add_tests("dstr_the_revenge",
2115
- "Ruby" => '"before #{from} middle #{to} (#{__FILE__}:#{__LINE__})"',
2116
- "RawParseTree" => [:dstr,
2117
- "before ",
2118
- [:evstr, [:vcall, :from]],
2119
- [:str, " middle "],
2120
- [:evstr, [:vcall, :to]],
2121
- [:str, " ("],
2122
- [:str, "(string)"],
2123
- [:str, ":"],
2124
- [:evstr, [:lit, 1]],
2125
- [:str, ")"]],
2126
- "ParseTree" => s(:dstr,
2127
- "before ",
2128
- s(:evstr, s(:call, nil, :from, s(:arglist))),
2129
- s(:str, " middle "),
2130
- s(:evstr, s(:call, nil, :to, s(:arglist))),
2131
- s(:str, " ("),
2132
- s(:str, "(string)"),
2133
- s(:str, ":"),
2134
- s(:evstr, s(:lit, 1)),
2135
- s(:str, ")")),
2136
- "Ruby2Ruby" => '"before #{from} middle #{to} ((string):#{1})"')
2137
-
2138
- add_tests("dsym",
2139
- "Ruby" => ":\"x#\{(1 + 1)}y\"",
2140
- "RawParseTree" => [:dsym, "x",
2141
- [:evstr, [:call, [:lit, 1], :+,
2142
- [:array, [:lit, 1]]]], [:str, "y"]],
2143
- "ParseTree" => s(:dsym, "x",
2144
- s(:evstr, s(:call, s(:lit, 1), :+,
2145
- s(:arglist, s(:lit, 1)))), s(:str, "y")))
2146
-
2147
- add_tests("dxstr",
2148
- "Ruby" => "t = 5\n`touch #\{t}`\n",
2149
- "RawParseTree" => [:block,
2150
- [:lasgn, :t, [:lit, 5]],
2151
- [:dxstr, 'touch ', [:evstr, [:lvar, :t]]]],
2152
- "ParseTree" => s(:block,
2153
- s(:lasgn, :t, s(:lit, 5)),
2154
- s(:dxstr, 'touch ', s(:evstr, s(:lvar, :t)))))
2155
-
2156
- add_tests("ensure",
2157
- "Ruby" => "begin\n (1 + 1)\nrescue SyntaxError => e1\n 2\nrescue Exception => e2\n 3\nelse\n 4\nensure\n 5\nend",
2158
- "RawParseTree" => [:ensure,
2159
- [:rescue,
2160
- [:call, [:lit, 1], :+, [:array, [:lit, 1]]],
2161
- [:resbody,
2162
- [:array, [:const, :SyntaxError]],
2163
- [:block,
2164
- [:lasgn, :e1, [:gvar, :$!]], [:lit, 2]],
2165
- [:resbody,
2166
- [:array, [:const, :Exception]],
2167
- [:block,
2168
- [:lasgn, :e2, [:gvar, :$!]], [:lit, 3]]]],
2169
- [:lit, 4]],
2170
- [:lit, 5]],
2171
- "ParseTree" => s(:ensure,
2172
- s(:rescue,
2173
- s(:call, s(:lit, 1), :+,
2174
- s(:arglist, s(:lit, 1))),
2175
- s(:resbody,
2176
- s(:array,
2177
- s(:const, :SyntaxError),
2178
- s(:lasgn, :e1, s(:gvar, :$!))),
2179
- s(:lit, 2)),
2180
- s(:resbody,
2181
- s(:array,
2182
- s(:const, :Exception),
2183
- s(:lasgn, :e2, s(:gvar, :$!))),
2184
- s(:lit, 3)),
2185
- s(:lit, 4)),
2186
- s(:lit, 5)))
2187
-
2188
- add_tests("false",
2189
- "Ruby" => "false",
2190
- "RawParseTree" => [:false],
2191
- "ParseTree" => s(:false))
2192
-
2193
- add_tests("fbody",
2194
- "Ruby" => [Examples, :an_alias],
2195
- "RawParseTree" => [:defn, :an_alias,
2196
- [:fbody,
2197
- [:scope,
2198
- [:block,
2199
- [:args, :x],
2200
- [:call, [:lvar, :x], :+,
2201
- [:array, [:lit, 1]]]]]]],
2202
- "ParseTree" => s(:defn, :an_alias,
2203
- s(:args, :x),
2204
- s(:scope,
2205
- s(:block,
2206
- s(:call, s(:lvar, :x), :+,
2207
- s(:arglist, s(:lit, 1)))))),
2208
- "Ruby2Ruby" => "def an_alias(x)\n (x + 1)\nend")
2209
-
2210
- add_tests("fcall_arglist",
2211
- "Ruby" => "m(42)",
2212
- "RawParseTree" => [:fcall, :m, [:array, [:lit, 42]]],
2213
- "ParseTree" => s(:call, nil, :m, s(:arglist, s(:lit, 42))))
2214
-
2215
- add_tests("fcall_arglist_hash",
2216
- "Ruby" => "m(:a => 1, :b => 2)",
2217
- "RawParseTree" => [:fcall, :m,
2218
- [:array,
2219
- [:hash,
2220
- [:lit, :a], [:lit, 1],
2221
- [:lit, :b], [:lit, 2]]]],
2222
- "ParseTree" => s(:call, nil, :m,
2223
- s(:arglist,
2224
- s(:hash,
2225
- s(:lit, :a), s(:lit, 1),
2226
- s(:lit, :b), s(:lit, 2)))))
2227
-
2228
- add_tests("fcall_arglist_norm_hash",
2229
- "Ruby" => "m(42, :a => 1, :b => 2)",
2230
- "RawParseTree" => [:fcall, :m,
2231
- [:array,
2232
- [:lit, 42],
2233
- [:hash,
2234
- [:lit, :a], [:lit, 1],
2235
- [:lit, :b], [:lit, 2]]]],
2236
- "ParseTree" => s(:call, nil, :m,
2237
- s(:arglist,
2238
- s(:lit, 42),
2239
- s(:hash,
2240
- s(:lit, :a), s(:lit, 1),
2241
- s(:lit, :b), s(:lit, 2)))))
2242
-
2243
- add_tests("fcall_arglist_norm_hash_splat",
2244
- "Ruby" => "m(42, :a => 1, :b => 2, *c)",
2245
- "RawParseTree" => [:fcall, :m,
2246
- [:argscat,
2247
- [:array,
2248
- [:lit, 42],
2249
- [:hash,
2250
- [:lit, :a], [:lit, 1],
2251
- [:lit, :b], [:lit, 2]]],
2252
- [:vcall, :c]]],
2253
- "ParseTree" => s(:call, nil, :m,
2254
- s(:arglist,
2255
- s(:lit, 42),
2256
- s(:hash,
2257
- s(:lit, :a), s(:lit, 1),
2258
- s(:lit, :b), s(:lit, 2)),
2259
- s(:splat, s(:call, nil, :c, s(:arglist))))))
2260
-
2261
- add_tests("fcall_block",
2262
- "Ruby" => "a(:b) { :c }",
2263
- "RawParseTree" => [:iter,
2264
- [:fcall, :a, [:array, [:lit, :b]]], nil,
2265
- [:lit, :c]],
2266
- "ParseTree" => s(:iter,
2267
- s(:call, nil, :a,
2268
- s(:arglist, s(:lit, :b))), nil,
2269
- s(:lit, :c)))
2270
-
2271
- add_tests("fcall_index_space",
2272
- "Ruby" => "a [42]",
2273
- "RawParseTree" => [:fcall, :a, [:array, [:array, [:lit, 42]]]],
2274
- "ParseTree" => s(:call, nil, :a,
2275
- s(:arglist, s(:array, s(:lit, 42)))),
2276
- "Ruby2Ruby" => "a([42])")
2277
-
2278
- add_tests("fcall_keyword",
2279
- "Ruby" => "42 if block_given?",
2280
- "RawParseTree" => [:if, [:fcall, :block_given?], [:lit, 42], nil],
2281
- "ParseTree" => s(:if,
2282
- s(:call, nil, :block_given?, s(:arglist)),
2283
- s(:lit, 42), nil))
2284
-
2285
- add_tests("flip2",
2286
- "Ruby" => "x = if ((i % 4) == 0)..((i % 3) == 0) then\n i\nelse\n nil\nend",
2287
- "RawParseTree" => [:lasgn,
2288
- :x,
2289
- [:if,
2290
- [:flip2,
2291
- [:call,
2292
- [:call, [:vcall, :i], :%,
2293
- [:array, [:lit, 4]]],
2294
- :==,
2295
- [:array, [:lit, 0]]],
2296
- [:call,
2297
- [:call, [:vcall, :i], :%,
2298
- [:array, [:lit, 3]]],
2299
- :==,
2300
- [:array, [:lit, 0]]]],
2301
- [:vcall, :i],
2302
- [:nil]]],
2303
- "ParseTree" => s(:lasgn,
2304
- :x,
2305
- s(:if,
2306
- s(:flip2,
2307
- s(:call,
2308
- s(:call, s(:call, nil, :i, s(:arglist)),
2309
- :%,
2310
- s(:arglist, s(:lit, 4))),
2311
- :==,
2312
- s(:arglist, s(:lit, 0))),
2313
- s(:call,
2314
- s(:call, s(:call, nil, :i, s(:arglist)),
2315
- :%,
2316
- s(:arglist, s(:lit, 3))),
2317
- :==,
2318
- s(:arglist, s(:lit, 0)))),
2319
- s(:call, nil, :i, s(:arglist)),
2320
- s(:nil))))
2321
-
2322
- add_tests("flip2_method",
2323
- "Ruby" => "if 1..2.a?(b) then\n nil\nend",
2324
- "RawParseTree" => [:if,
2325
- [:flip2,
2326
- [:call, [:lit, 1], :==,
2327
- [:array, [:gvar, :$.]]],
2328
- [:call, [:lit, 2], :a?,
2329
- [:array, [:vcall, :b]]]],
2330
- [:nil],
2331
- nil],
2332
- "ParseTree" => s(:if,
2333
- s(:flip2,
2334
- s(:lit, 1),
2335
- s(:call, s(:lit, 2), :a?,
2336
- s(:arglist,
2337
- s(:call, nil, :b, s(:arglist))))),
2338
- s(:nil),
2339
- nil))
2340
-
2341
- add_tests("flip3",
2342
- "Ruby" => "x = if ((i % 4) == 0)...((i % 3) == 0) then\n i\nelse\n nil\nend",
2343
- "RawParseTree" => [:lasgn,
2344
- :x,
2345
- [:if,
2346
- [:flip3,
2347
- [:call,
2348
- [:call, [:vcall, :i], :%,
2349
- [:array, [:lit, 4]]],
2350
- :==,
2351
- [:array, [:lit, 0]]],
2352
- [:call,
2353
- [:call, [:vcall, :i], :%,
2354
- [:array, [:lit, 3]]],
2355
- :==,
2356
- [:array, [:lit, 0]]]],
2357
- [:vcall, :i],
2358
- [:nil]]],
2359
- "ParseTree" => s(:lasgn,
2360
- :x,
2361
- s(:if,
2362
- s(:flip3,
2363
- s(:call,
2364
- s(:call, s(:call, nil, :i, s(:arglist)),
2365
- :%,
2366
- s(:arglist, s(:lit, 4))),
2367
- :==,
2368
- s(:arglist, s(:lit, 0))),
2369
- s(:call,
2370
- s(:call, s(:call, nil, :i, s(:arglist)),
2371
- :%,
2372
- s(:arglist, s(:lit, 3))),
2373
- :==,
2374
- s(:arglist, s(:lit, 0)))),
2375
- s(:call, nil, :i, s(:arglist)),
2376
- s(:nil))))
2377
-
2378
- add_tests("for",
2379
- "Ruby" => "for o in ary do\n puts(o)\nend",
2380
- "RawParseTree" => [:for,
2381
- [:vcall, :ary],
2382
- [:lasgn, :o],
2383
- [:fcall, :puts, [:array, [:lvar, :o]]]],
2384
- "ParseTree" => s(:for,
2385
- s(:call, nil, :ary, s(:arglist)),
2386
- s(:lasgn, :o),
2387
- s(:call, nil, :puts,
2388
- s(:arglist, s(:lvar, :o)))))
2389
-
2390
- add_tests("for_no_body",
2391
- "Ruby" => "for i in (0..max) do\n # do nothing\nend",
2392
- "RawParseTree" => [:for,
2393
- [:dot2, [:lit, 0], [:vcall, :max]],
2394
- [:lasgn, :i]],
2395
- "ParseTree" => s(:for,
2396
- s(:dot2,
2397
- s(:lit, 0),
2398
- s(:call, nil, :max, s(:arglist))),
2399
- s(:lasgn, :i)))
2400
-
2401
- add_tests("gasgn",
2402
- "Ruby" => "$x = 42",
2403
- "RawParseTree" => [:gasgn, :$x, [:lit, 42]],
2404
- "ParseTree" => s(:gasgn, :$x, s(:lit, 42)))
2405
-
2406
- add_tests("global",
2407
- "Ruby" => "$stderr",
2408
- "RawParseTree" => [:gvar, :$stderr],
2409
- "ParseTree" => s(:gvar, :$stderr))
2410
-
2411
- add_tests("gvar",
2412
- "Ruby" => "$x",
2413
- "RawParseTree" => [:gvar, :$x],
2414
- "ParseTree" => s(:gvar, :$x))
2415
-
2416
- add_tests("gvar_underscore",
2417
- "Ruby" => "$_",
2418
- "RawParseTree" => [:gvar, :$_],
2419
- "ParseTree" => s(:gvar, :$_))
2420
-
2421
- add_tests("gvar_underscore_blah",
2422
- "Ruby" => "$__blah",
2423
- "RawParseTree" => [:gvar, :$__blah],
2424
- "ParseTree" => s(:gvar, :$__blah))
2425
-
2426
- add_tests("hash",
2427
- "Ruby" => "{ 1 => 2, 3 => 4 }",
2428
- "RawParseTree" => [:hash,
2429
- [:lit, 1], [:lit, 2],
2430
- [:lit, 3], [:lit, 4]],
2431
- "ParseTree" => s(:hash,
2432
- s(:lit, 1), s(:lit, 2),
2433
- s(:lit, 3), s(:lit, 4)))
2434
-
2435
- add_tests("hash_rescue",
2436
- "Ruby" => "{ 1 => (2 rescue 3) }",
2437
- "RawParseTree" => [:hash,
2438
- [:lit, 1],
2439
- [:rescue,
2440
- [:lit, 2],
2441
- [:resbody, nil, [:lit, 3]]]],
2442
- "ParseTree" => s(:hash,
2443
- s(:lit, 1),
2444
- s(:rescue,
2445
- s(:lit, 2),
2446
- s(:resbody, s(:array), s(:lit, 3)))))
2447
-
2448
- add_tests("iasgn",
2449
- "Ruby" => "@a = 4",
2450
- "RawParseTree" => [:iasgn, :@a, [:lit, 4]],
2451
- "ParseTree" => s(:iasgn, :@a, s(:lit, 4)))
2452
-
2453
- add_tests("if_block_condition",
2454
- "Ruby" => "if (x = 5\n(x + 1)) then\n nil\nend",
2455
- "RawParseTree" => [:if,
2456
- [:block,
2457
- [:lasgn, :x, [:lit, 5]],
2458
- [:call,
2459
- [:lvar, :x],
2460
- :+,
2461
- [:array, [:lit, 1]]]],
2462
- [:nil],
2463
- nil],
2464
- "ParseTree" => s(:if,
2465
- s(:block,
2466
- s(:lasgn, :x, s(:lit, 5)),
2467
- s(:call,
2468
- s(:lvar, :x),
2469
- :+,
2470
- s(:arglist, s(:lit, 1)))),
2471
- s(:nil),
2472
- nil))
2473
-
2474
- add_tests("if_lasgn_short",
2475
- "Ruby" => "if x = obj.x then\n x.do_it\nend",
2476
- "RawParseTree" => [:if,
2477
- [:lasgn, :x,
2478
- [:call, [:vcall, :obj], :x]],
2479
- [:call,
2480
- [:lvar, :x], :do_it],
2481
- nil],
2482
- "ParseTree" => s(:if,
2483
- s(:lasgn, :x,
2484
- s(:call,
2485
- s(:call, nil, :obj, s(:arglist)),
2486
- :x, s(:arglist))),
2487
- s(:call, s(:lvar, :x), :do_it, s(:arglist)),
2488
- nil))
2489
-
2490
- add_tests("if_nested",
2491
- "Ruby" => "return if false unless true",
2492
- "RawParseTree" => [:if, [:true], nil,
2493
- [:if, [:false], [:return], nil]],
2494
- "ParseTree" => s(:if, s(:true), nil,
2495
- s(:if, s(:false), s(:return), nil)))
2496
-
2497
- add_tests("if_post",
2498
- "Ruby" => "a if b",
2499
- "RawParseTree" => [:if, [:vcall, :b], [:vcall, :a], nil],
2500
- "ParseTree" => s(:if, s(:call, nil, :b, s(:arglist)),
2501
- s(:call, nil, :a, s(:arglist)), nil))
2502
-
2503
- add_tests("if_post_not",
2504
- "Ruby" => "a if not b",
2505
- "RawParseTree" => [:if, [:vcall, :b], nil, [:vcall, :a]],
2506
- "ParseTree" => s(:if, s(:call, nil, :b, s(:arglist)), nil,
2507
- s(:call, nil, :a, s(:arglist))),
2508
- "Ruby2Ruby" => "a unless b")
2509
-
2510
- add_tests("if_pre",
2511
- "Ruby" => "if b then a end",
2512
- "RawParseTree" => [:if, [:vcall, :b], [:vcall, :a], nil],
2513
- "ParseTree" => s(:if, s(:call, nil, :b, s(:arglist)),
2514
- s(:call, nil, :a, s(:arglist)), nil),
2515
- "Ruby2Ruby" => "a if b")
2516
-
2517
- add_tests("if_pre_not",
2518
- "Ruby" => "if not b then a end",
2519
- "RawParseTree" => [:if, [:vcall, :b], nil, [:vcall, :a]],
2520
- "ParseTree" => s(:if, s(:call, nil, :b, s(:arglist)), nil,
2521
- s(:call, nil, :a, s(:arglist))),
2522
- "Ruby2Ruby" => "a unless b")
2523
-
2524
- add_tests("iter_call_arglist_space",
2525
- "Ruby" => "a (1) {|c|d}",
2526
- "RawParseTree" => [:iter,
2527
- [:fcall, :a, [:array, [:lit, 1]]],
2528
- [:dasgn_curr, :c],
2529
- [:vcall, :d]],
2530
- "ParseTree" => s(:iter,
2531
- s(:call, nil, :a, s(:arglist, s(:lit, 1))),
2532
- s(:lasgn, :c),
2533
- s(:call, nil, :d, s(:arglist))),
2534
- "Ruby2Ruby" => "a(1) { |c| d }")
2535
-
2536
- add_tests("iter_dasgn_curr_dasgn_madness",
2537
- "Ruby" => "as.each { |a|\n b += a.b(false) }",
2538
- "RawParseTree" => [:iter,
2539
- [:call, [:vcall, :as], :each],
2540
- [:dasgn_curr, :a],
2541
- [:dasgn_curr,
2542
- :b,
2543
- [:call,
2544
- [:dvar, :b],
2545
- :+,
2546
- [:array,
2547
- [:call, [:dvar, :a], :b,
2548
- [:array, [:false]]]]]]],
2549
- "ParseTree" => s(:iter,
2550
- s(:call,
2551
- s(:call, nil, :as, s(:arglist)),
2552
- :each, s(:arglist)),
2553
- s(:lasgn, :a),
2554
- s(:lasgn, :b,
2555
- s(:call,
2556
- s(:lvar, :b),
2557
- :+,
2558
- s(:arglist,
2559
- s(:call, s(:lvar, :a), :b,
2560
- s(:arglist, s(:false))))))),
2561
- "Ruby2Ruby" => "as.each { |a| b = (b + a.b(false)) }")
2562
-
2563
- add_tests("iter_downto",
2564
- "Ruby" => "3.downto(1) { |n| puts(n.to_s) }",
2565
- "RawParseTree" => [:iter,
2566
- [:call, [:lit, 3], :downto, [:array, [:lit, 1]]],
2567
- [:dasgn_curr, :n],
2568
- [:fcall, :puts,
2569
- [:array, [:call, [:dvar, :n], :to_s]]]],
2570
- "ParseTree" => s(:iter,
2571
- s(:call, s(:lit, 3), :downto,
2572
- s(:arglist, s(:lit, 1))),
2573
- s(:lasgn, :n),
2574
- s(:call, nil, :puts,
2575
- s(:arglist,
2576
- s(:call, s(:lvar, :n),
2577
- :to_s, s(:arglist))))))
2578
-
2579
- add_tests("iter_each_lvar",
2580
- "Ruby" => "array = [1, 2, 3]\narray.each { |x| puts(x.to_s) }\n",
2581
- "RawParseTree" => [:block,
2582
- [:lasgn, :array,
2583
- [:array, [:lit, 1], [:lit, 2], [:lit, 3]]],
2584
- [:iter,
2585
- [:call, [:lvar, :array], :each],
2586
- [:dasgn_curr, :x],
2587
- [:fcall, :puts,
2588
- [:array, [:call, [:dvar, :x], :to_s]]]]],
2589
- "ParseTree" => s(:block,
2590
- s(:lasgn, :array,
2591
- s(:array,
2592
- s(:lit, 1), s(:lit, 2), s(:lit, 3))),
2593
- s(:iter,
2594
- s(:call, s(:lvar, :array), :each,
2595
- s(:arglist)),
2596
- s(:lasgn, :x),
2597
- s(:call, nil, :puts,
2598
- s(:arglist, s(:call, s(:lvar, :x),
2599
- :to_s, s(:arglist)))))))
2600
-
2601
- add_tests("iter_each_nested",
2602
- "Ruby" => "array1 = [1, 2, 3]\narray2 = [4, 5, 6, 7]\narray1.each do |x|\n array2.each do |y|\n puts(x.to_s)\n puts(y.to_s)\n end\nend\n",
2603
- "RawParseTree" => [:block,
2604
- [:lasgn, :array1,
2605
- [:array, [:lit, 1], [:lit, 2], [:lit, 3]]],
2606
- [:lasgn, :array2,
2607
- [:array,
2608
- [:lit, 4], [:lit, 5], [:lit, 6], [:lit, 7]]],
2609
- [:iter,
2610
- [:call,
2611
- [:lvar, :array1], :each],
2612
- [:dasgn_curr, :x],
2613
- [:iter,
2614
- [:call,
2615
- [:lvar, :array2], :each],
2616
- [:dasgn_curr, :y],
2617
- [:block,
2618
- [:fcall, :puts,
2619
- [:array, [:call, [:dvar, :x], :to_s]]],
2620
- [:fcall, :puts,
2621
- [:array, [:call, [:dvar, :y], :to_s]]]]]]],
2622
- "ParseTree" => s(:block,
2623
- s(:lasgn, :array1,
2624
- s(:array,
2625
- s(:lit, 1), s(:lit, 2), s(:lit, 3))),
2626
- s(:lasgn, :array2,
2627
- s(:array,
2628
- s(:lit, 4), s(:lit, 5),
2629
- s(:lit, 6), s(:lit, 7))),
2630
- s(:iter,
2631
- s(:call,
2632
- s(:lvar, :array1), :each, s(:arglist)),
2633
- s(:lasgn, :x),
2634
- s(:iter,
2635
- s(:call,
2636
- s(:lvar, :array2), :each, s(:arglist)),
2637
- s(:lasgn, :y),
2638
- s(:block,
2639
- s(:call, nil, :puts,
2640
- s(:arglist,
2641
- s(:call, s(:lvar, :x),
2642
- :to_s, s(:arglist)))),
2643
- s(:call, nil, :puts,
2644
- s(:arglist,
2645
- s(:call, s(:lvar, :y),
2646
- :to_s, s(:arglist)))))))))
2647
-
2648
- add_tests("iter_loop_empty",
2649
- "Ruby" => "loop { }",
2650
- "RawParseTree" => [:iter, [:fcall, :loop], nil],
2651
- "ParseTree" => s(:iter, s(:call, nil, :loop, s(:arglist)), nil))
2652
-
2653
- add_tests("iter_masgn_2",
2654
- "Ruby" => "a { |b, c| p(c) }",
2655
- "RawParseTree" => [:iter,
2656
- [:fcall, :a],
2657
- [:masgn,
2658
- [:array, [:dasgn_curr, :b], [:dasgn_curr, :c]],
2659
- nil, nil],
2660
- [:fcall, :p, [:array, [:dvar, :c]]]],
2661
- "ParseTree" => s(:iter,
2662
- s(:call, nil, :a, s(:arglist)),
2663
- s(:masgn,
2664
- s(:array, s(:lasgn, :b), s(:lasgn, :c))),
2665
- s(:call, nil, :p, s(:arglist, s(:lvar, :c)))))
2666
-
2667
- add_tests("iter_masgn_args_splat",
2668
- "Ruby" => "a { |b, c, *d| p(c) }",
2669
- "RawParseTree" => [:iter,
2670
- [:fcall, :a],
2671
- [:masgn,
2672
- [:array, [:dasgn_curr, :b], [:dasgn_curr, :c]],
2673
- [:dasgn_curr, :d], nil],
2674
- [:fcall, :p, [:array, [:dvar, :c]]]],
2675
- "ParseTree" => s(:iter,
2676
- s(:call, nil, :a, s(:arglist)),
2677
- s(:masgn,
2678
- s(:array,
2679
- s(:lasgn, :b),
2680
- s(:lasgn, :c),
2681
- s(:splat, s(:lasgn, :d)))),
2682
- s(:call, nil, :p, s(:arglist, s(:lvar, :c)))))
2683
-
2684
- add_tests("iter_masgn_args_splat_no_name",
2685
- "Ruby" => "a { |b, c, *| p(c) }",
2686
- "RawParseTree" => [:iter,
2687
- [:fcall, :a],
2688
- [:masgn,
2689
- [:array, [:dasgn_curr, :b], [:dasgn_curr, :c]],
2690
- [:splat], nil],
2691
- [:fcall, :p, [:array, [:dvar, :c]]]],
2692
- "ParseTree" => s(:iter,
2693
- s(:call, nil, :a, s(:arglist)),
2694
- s(:masgn,
2695
- s(:array,
2696
- s(:lasgn, :b),
2697
- s(:lasgn, :c),
2698
- s(:splat))),
2699
- s(:call, nil, :p, s(:arglist, s(:lvar, :c)))))
2700
-
2701
- add_tests("iter_masgn_splat",
2702
- "Ruby" => "a { |*c| p(c) }",
2703
- "RawParseTree" => [:iter,
2704
- [:fcall, :a],
2705
- [:masgn, nil, [:dasgn_curr, :c], nil],
2706
- [:fcall, :p, [:array, [:dvar, :c]]]],
2707
- "ParseTree" => s(:iter,
2708
- s(:call, nil, :a, s(:arglist)),
2709
- s(:masgn, s(:array, s(:splat, s(:lasgn, :c)))),
2710
- s(:call, nil, :p, s(:arglist, s(:lvar, :c)))))
2711
-
2712
- add_tests("iter_masgn_splat_no_name",
2713
- "Ruby" => "a { |*| p(c) }",
2714
- "RawParseTree" => [:iter,
2715
- [:fcall, :a],
2716
- [:masgn, nil, [:splat], nil],
2717
- [:fcall, :p, [:array, [:vcall, :c]]]],
2718
- "ParseTree" => s(:iter,
2719
- s(:call, nil, :a, s(:arglist)),
2720
- s(:masgn, s(:array, s(:splat))),
2721
- s(:call, nil, :p,
2722
- s(:arglist, s(:call, nil, :c, s(:arglist))))))
2723
-
2724
- add_tests("iter_shadowed_var",
2725
- "Ruby" => "a do |x|\n b do |x|\n puts x\n end\nend",
2726
- "RawParseTree" => [:iter,
2727
- [:fcall, :a],
2728
- [:dasgn_curr, :x],
2729
- [:iter,
2730
- [:fcall, :b],
2731
- [:dasgn, :x],
2732
- [:fcall, :puts, [:array, [:dvar, :x]]]]],
2733
- "ParseTree" => s(:iter,
2734
- s(:call, nil, :a, s(:arglist)),
2735
- s(:lasgn, :x),
2736
- s(:iter,
2737
- s(:call, nil, :b, s(:arglist)),
2738
- s(:lasgn, :x),
2739
- s(:call, nil, :puts,
2740
- s(:arglist, s(:lvar, :x))))),
2741
- "Ruby2Ruby" => "a { |x| b { |x| puts(x) } }")
2742
-
2743
- add_tests("iter_upto",
2744
- "Ruby" => "1.upto(3) { |n| puts(n.to_s) }",
2745
- "RawParseTree" => [:iter,
2746
- [:call, [:lit, 1], :upto, [:array, [:lit, 3]]],
2747
- [:dasgn_curr, :n],
2748
- [:fcall, :puts,
2749
- [:array, [:call, [:dvar, :n], :to_s]]]],
2750
- "ParseTree" => s(:iter,
2751
- s(:call, s(:lit, 1), :upto,
2752
- s(:arglist, s(:lit, 3))),
2753
- s(:lasgn, :n),
2754
- s(:call, nil, :puts,
2755
- s(:arglist,
2756
- s(:call, s(:lvar, :n), :to_s,
2757
- s(:arglist))))))
2758
-
2759
- add_tests("iter_while",
2760
- "Ruby" => "argl = 10\nwhile (argl >= 1) do\n puts(\"hello\")\n argl = (argl - 1)\nend\n",
2761
- "RawParseTree" => [:block,
2762
- [:lasgn, :argl, [:lit, 10]],
2763
- [:while,
2764
- [:call, [:lvar, :argl], :">=",
2765
- [:array, [:lit, 1]]],
2766
- [:block,
2767
- [:fcall, :puts, [:array, [:str, "hello"]]],
2768
- [:lasgn,
2769
- :argl,
2770
- [:call, [:lvar, :argl],
2771
- :"-", [:array, [:lit, 1]]]]], true]],
2772
- "ParseTree" => s(:block,
2773
- s(:lasgn, :argl, s(:lit, 10)),
2774
- s(:while,
2775
- s(:call, s(:lvar, :argl), :">=",
2776
- s(:arglist, s(:lit, 1))),
2777
- s(:block,
2778
- s(:call, nil, :puts,
2779
- s(:arglist, s(:str, "hello"))),
2780
- s(:lasgn,
2781
- :argl,
2782
- s(:call, s(:lvar, :argl), :"-",
2783
- s(:arglist, s(:lit, 1))))), true)))
2784
-
2785
- add_tests("ivar",
2786
- "Ruby" => [Examples, :reader],
2787
- "RawParseTree" => [:defn, :reader, [:ivar, :@reader]],
2788
- "ParseTree" => s(:defn, :reader, # FIX should be unified?
2789
- s(:args),
2790
- s(:ivar, :@reader)),
2791
- "Ruby2Ruby" => "attr_reader :reader")
2792
-
2793
- add_tests("lasgn_array",
2794
- "Ruby" => "var = [\"foo\", \"bar\"]",
2795
- "RawParseTree" => [:lasgn, :var,
2796
- [:array,
2797
- [:str, "foo"],
2798
- [:str, "bar"]]],
2799
- "ParseTree" => s(:lasgn, :var,
2800
- s(:array,
2801
- s(:str, "foo"),
2802
- s(:str, "bar"))))
2803
-
2804
- add_tests("lasgn_call",
2805
- "Ruby" => "c = (2 + 3)",
2806
- "RawParseTree" => [:lasgn, :c, [:call, [:lit, 2], :+,
2807
- [:array, [:lit, 3]]]],
2808
- "ParseTree" => s(:lasgn, :c, s(:call, s(:lit, 2), :+,
2809
- s(:arglist, s(:lit, 3)))))
2810
-
2811
- add_tests("lit_bool_false",
2812
- "Ruby" => "false",
2813
- "RawParseTree" => [:false],
2814
- "ParseTree" => s(:false))
2815
-
2816
- add_tests("lit_bool_true",
2817
- "Ruby" => "true",
2818
- "RawParseTree" => [:true],
2819
- "ParseTree" => s(:true))
2820
-
2821
- add_tests("lit_float",
2822
- "Ruby" => "1.1",
2823
- "RawParseTree" => [:lit, 1.1],
2824
- "ParseTree" => s(:lit, 1.1))
2825
-
2826
- add_tests("lit_long",
2827
- "Ruby" => "1",
2828
- "RawParseTree" => [:lit, 1],
2829
- "ParseTree" => s(:lit, 1))
2830
-
2831
- add_tests("lit_long_negative",
2832
- "Ruby" => "-1",
2833
- "RawParseTree" => [:lit, -1],
2834
- "ParseTree" => s(:lit, -1))
2835
-
2836
- add_tests("lit_range2",
2837
- "Ruby" => "(1..10)",
2838
- "RawParseTree" => [:lit, 1..10],
2839
- "ParseTree" => s(:lit, 1..10))
2840
-
2841
- add_tests("lit_range3",
2842
- "Ruby" => "(1...10)",
2843
- "RawParseTree" => [:lit, 1...10],
2844
- "ParseTree" => s(:lit, 1...10))
2845
-
2846
- # TODO: discuss and decide which lit we like
2847
- # it "converts a regexp to an sexp" do
2848
- # "/blah/".to_sexp.should == s(:regex, "blah", 0)
2849
- # "/blah/i".to_sexp.should == s(:regex, "blah", 1)
2850
- # "/blah/u".to_sexp.should == s(:regex, "blah", 64)
2851
- # end
2852
-
2853
- add_tests("lit_regexp",
2854
- "Ruby" => "/x/",
2855
- "RawParseTree" => [:lit, /x/],
2856
- "ParseTree" => s(:lit, /x/))
2857
-
2858
- add_tests("lit_regexp_i_wwtt",
2859
- "Ruby" => 'str.split(//i)',
2860
- "RawParseTree" => [:call, [:vcall, :str], :split,
2861
- [:array, [:lit, //i]]],
2862
- "ParseTree" => s(:call, s(:call, nil, :str, s(:arglist)), :split,
2863
- s(:arglist, s(:lit, //i))))
2864
-
2865
- add_tests("lit_regexp_n",
2866
- "Ruby" => "/x/n", # HACK differs on 1.9 - this is easiest
2867
- "RawParseTree" => [:lit, /x/n],
2868
- "ParseTree" => s(:lit, /x/n),
2869
- "Ruby2Ruby" => /x/n.inspect)
2870
-
2871
- add_tests("lit_regexp_once",
2872
- "Ruby" => "/x/o",
2873
- "RawParseTree" => [:lit, /x/],
2874
- "ParseTree" => s(:lit, /x/),
2875
- "Ruby2Ruby" => "/x/")
2876
-
2877
- add_tests("lit_sym",
2878
- "Ruby" => ":x",
2879
- "RawParseTree" => [:lit, :x],
2880
- "ParseTree" => s(:lit, :x))
2881
-
2882
- add_tests("lit_sym_splat",
2883
- "Ruby" => ":\"*args\"",
2884
- "RawParseTree" => [:lit, :"*args"],
2885
- "ParseTree" => s(:lit, :"*args"))
2886
-
2887
- add_tests("lvar_def_boundary",
2888
- "Ruby" => "b = 42\ndef a\n c do\n begin\n do_stuff\n rescue RuntimeError => b\n puts(b)\n end\n end\nend\n",
2889
- "RawParseTree" => [:block,
2890
- [:lasgn, :b, [:lit, 42]],
2891
- [:defn, :a,
2892
- [:scope,
2893
- [:block,
2894
- [:args],
2895
- [:iter,
2896
- [:fcall, :c],
2897
- nil,
2898
- [:rescue,
2899
- [:vcall, :do_stuff],
2900
- [:resbody,
2901
- [:array, [:const, :RuntimeError]],
2902
- [:block,
2903
- [:dasgn_curr, :b, [:gvar, :$!]],
2904
- [:fcall, :puts,
2905
- [:array, [:dvar, :b]]]]]]]]]]],
2906
- "ParseTree" => s(:block,
2907
- s(:lasgn, :b, s(:lit, 42)),
2908
- s(:defn, :a,
2909
- s(:args),
2910
- s(:scope,
2911
- s(:block,
2912
- s(:iter,
2913
- s(:call, nil, :c, s(:arglist)),
2914
- nil,
2915
- s(:rescue,
2916
- s(:call, nil, :do_stuff, s(:arglist)),
2917
- s(:resbody,
2918
- s(:array,
2919
- s(:const, :RuntimeError),
2920
- s(:lasgn, :b, s(:gvar, :$!))),
2921
- s(:call, nil, :puts,
2922
- s(:arglist,
2923
- s(:lvar, :b)))))))))))
2924
-
2925
- add_tests("masgn",
2926
- "Ruby" => "a, b = c, d",
2927
- "RawParseTree" => [:masgn,
2928
- [:array, [:lasgn, :a], [:lasgn, :b]], nil,
2929
- [:array, [:vcall, :c], [:vcall, :d]]],
2930
- "ParseTree" => s(:masgn,
2931
- s(:array, s(:lasgn, :a), s(:lasgn, :b)),
2932
- s(:array, s(:call, nil, :c, s(:arglist)),
2933
- s(:call, nil, :d, s(:arglist)))))
2934
-
2935
- add_tests("masgn_argscat",
2936
- "Ruby" => "a, b, *c = 1, 2, *[3, 4]",
2937
- "RawParseTree" => [:masgn,
2938
- [:array, [:lasgn, :a], [:lasgn, :b]],
2939
- [:lasgn, :c],
2940
- [:argscat,
2941
- [:array, [:lit, 1], [:lit, 2]],
2942
- [:array, [:lit, 3], [:lit, 4]]]],
2943
- "ParseTree" => s(:masgn,
2944
- s(:array,
2945
- s(:lasgn, :a),
2946
- s(:lasgn, :b),
2947
- s(:splat, s(:lasgn, :c))),
2948
- s(:array,
2949
- s(:lit, 1), s(:lit, 2),
2950
- s(:splat,
2951
- s(:array, s(:lit, 3), s(:lit, 4))))))
2952
-
2953
- add_tests("masgn_attrasgn",
2954
- "Ruby" => "a, b.c = d, e",
2955
- "RawParseTree" => [:masgn,
2956
- [:array, [:lasgn, :a],
2957
- [:attrasgn, [:vcall, :b], :c=]], nil,
2958
- [:array, [:vcall, :d], [:vcall, :e]]],
2959
- "ParseTree" => s(:masgn,
2960
- s(:array,
2961
- s(:lasgn, :a),
2962
- s(:attrasgn,
2963
- s(:call, nil, :b, s(:arglist)),
2964
- :c=, s(:arglist))),
2965
- s(:array,
2966
- s(:call, nil, :d, s(:arglist)),
2967
- s(:call, nil, :e, s(:arglist)))))
2968
-
2969
- add_tests("masgn_attrasgn_array_rhs",
2970
- "Ruby" => "a.b, a.c, _ = q",
2971
- "RawParseTree" => [:masgn,
2972
- [:array,
2973
- [:attrasgn, [:vcall, :a], :b=],
2974
- [:attrasgn, [:vcall, :a], :c=],
2975
- [:lasgn, :_]], nil,
2976
- [:to_ary, [:vcall, :q]]],
2977
- "ParseTree" => s(:masgn,
2978
- s(:array,
2979
- s(:attrasgn,
2980
- s(:call, nil, :a, s(:arglist)),
2981
- :b=, s(:arglist)),
2982
- s(:attrasgn,
2983
- s(:call, nil, :a, s(:arglist)),
2984
- :c=, s(:arglist)),
2985
- s(:lasgn, :_)),
2986
- s(:to_ary,
2987
- s(:call, nil, :q, s(:arglist)))))
2988
-
2989
- add_tests("masgn_attrasgn_idx",
2990
- "Ruby" => "a, i, j = [], 1, 2\na[i], a[j] = a[j], a[i]\n",
2991
- "RawParseTree" => [:block,
2992
- [:masgn,
2993
- [:array,
2994
- [:lasgn, :a], [:lasgn, :i], [:lasgn, :j]], nil,
2995
- [:array, [:zarray], [:lit, 1], [:lit, 2]]],
2996
- [:masgn,
2997
- [:array,
2998
- [:attrasgn,
2999
- [:lvar, :a], :[]=, [:array, [:lvar, :i]]],
3000
- [:attrasgn,
3001
- [:lvar, :a], :[]=, [:array, [:lvar, :j]]]],
3002
- nil,
3003
- [:array,
3004
- [:call, [:lvar, :a], :[],
3005
- [:array, [:lvar, :j]]],
3006
- [:call, [:lvar, :a], :[],
3007
- [:array, [:lvar, :i]]]]]],
3008
- "ParseTree" => s(:block,
3009
- s(:masgn,
3010
- s(:array,
3011
- s(:lasgn, :a),
3012
- s(:lasgn, :i), s(:lasgn, :j)),
3013
- s(:array, s(:array), s(:lit, 1), s(:lit, 2))),
3014
- s(:masgn,
3015
- s(:array,
3016
- s(:attrasgn, s(:lvar, :a), :[]=,
3017
- s(:arglist, s(:lvar, :i))),
3018
- s(:attrasgn, s(:lvar, :a), :[]=,
3019
- s(:arglist, s(:lvar, :j)))),
3020
- s(:array,
3021
- s(:call, s(:lvar, :a), :[],
3022
- s(:arglist, s(:lvar, :j))),
3023
- s(:call, s(:lvar, :a), :[],
3024
- s(:arglist, s(:lvar, :i)))))))
3025
-
3026
- add_tests("masgn_cdecl",
3027
- "Ruby" => "A, B, C = 1, 2, 3",
3028
- "RawParseTree" => [:masgn,
3029
- [:array, [:cdecl, :A], [:cdecl, :B],
3030
- [:cdecl, :C]], nil,
3031
- [:array, [:lit, 1], [:lit, 2], [:lit, 3]]],
3032
- "ParseTree" => s(:masgn,
3033
- s(:array, s(:cdecl, :A), s(:cdecl, :B),
3034
- s(:cdecl, :C)),
3035
- s(:array, s(:lit, 1), s(:lit, 2), s(:lit, 3))))
3036
-
3037
-
3038
- add_tests("masgn_iasgn",
3039
- "Ruby" => "a, @b = c, d",
3040
- "RawParseTree" => [:masgn,
3041
- [:array, [:lasgn, :a], [:iasgn, :"@b"]], nil,
3042
- [:array, [:vcall, :c], [:vcall, :d]]],
3043
- "ParseTree" => s(:masgn,
3044
- s(:array, s(:lasgn, :a), s(:iasgn, :"@b")),
3045
- s(:array,
3046
- s(:call, nil, :c, s(:arglist)),
3047
- s(:call, nil, :d, s(:arglist)))))
3048
-
3049
- add_tests("masgn_masgn",
3050
- "Ruby" => "a, (b, c) = [1, [2, 3]]",
3051
- "RawParseTree" => [:masgn,
3052
- [:array,
3053
- [:lasgn, :a],
3054
- [:masgn,
3055
- [:array,
3056
- [:lasgn, :b],
3057
- [:lasgn, :c]], nil, nil]],
3058
- nil,
3059
- [:to_ary,
3060
- [:array,
3061
- [:lit, 1],
3062
- [:array,
3063
- [:lit, 2],
3064
- [:lit, 3]]]]],
3065
- "ParseTree" => s(:masgn,
3066
- s(:array,
3067
- s(:lasgn, :a),
3068
- s(:masgn,
3069
- s(:array,
3070
- s(:lasgn, :b),
3071
- s(:lasgn, :c)))),
3072
- s(:to_ary,
3073
- s(:array,
3074
- s(:lit, 1),
3075
- s(:array,
3076
- s(:lit, 2),
3077
- s(:lit, 3))))))
3078
-
3079
- add_tests("masgn_splat_lhs",
3080
- "Ruby" => "a, b, *c = d, e, f, g",
3081
- "RawParseTree" => [:masgn,
3082
- [:array, [:lasgn, :a], [:lasgn, :b]],
3083
- [:lasgn, :c],
3084
- [:array,
3085
- [:vcall, :d], [:vcall, :e],
3086
- [:vcall, :f], [:vcall, :g]]],
3087
- "ParseTree" => s(:masgn,
3088
- s(:array,
3089
- s(:lasgn, :a),
3090
- s(:lasgn, :b),
3091
- s(:splat, s(:lasgn, :c))),
3092
- s(:array,
3093
- s(:call, nil, :d, s(:arglist)),
3094
- s(:call, nil, :e, s(:arglist)),
3095
- s(:call, nil, :f, s(:arglist)),
3096
- s(:call, nil, :g, s(:arglist)))))
3097
-
3098
- add_tests("masgn_splat_rhs_1",
3099
- "Ruby" => "a, b = *c",
3100
- "RawParseTree" => [:masgn,
3101
- [:array, [:lasgn, :a], [:lasgn, :b]],
3102
- nil,
3103
- [:splat, [:vcall, :c]]],
3104
- "ParseTree" => s(:masgn,
3105
- s(:array,
3106
- s(:lasgn, :a),
3107
- s(:lasgn, :b)),
3108
- s(:splat, s(:call, nil, :c, s(:arglist)))))
3109
-
3110
- add_tests("masgn_splat_rhs_n",
3111
- "Ruby" => "a, b = c, d, *e",
3112
- "RawParseTree" => [:masgn,
3113
- [:array, [:lasgn, :a], [:lasgn, :b]],
3114
- nil,
3115
- [:argscat,
3116
- [:array, [:vcall, :c], [:vcall, :d]],
3117
- [:vcall, :e]]],
3118
- "ParseTree" => s(:masgn,
3119
- s(:array,
3120
- s(:lasgn, :a),
3121
- s(:lasgn, :b)),
3122
- s(:array,
3123
- s(:call, nil, :c, s(:arglist)),
3124
- s(:call, nil, :d, s(:arglist)),
3125
- s(:splat, s(:call, nil, :e, s(:arglist))))))
3126
-
3127
- add_tests("masgn_splat_no_name_to_ary",
3128
- "Ruby" => "a, b, * = c",
3129
- "RawParseTree" => [:masgn,
3130
- [:array, [:lasgn, :a], [:lasgn, :b]],
3131
- [:splat],
3132
- [:to_ary, [:vcall, :c]]],
3133
- "ParseTree" => s(:masgn,
3134
- s(:array,
3135
- s(:lasgn, :a),
3136
- s(:lasgn, :b),
3137
- s(:splat)),
3138
- s(:to_ary, s(:call, nil, :c, s(:arglist)))))
3139
-
3140
- add_tests("masgn_splat_no_name_trailing",
3141
- "Ruby" => "a, b, = c",
3142
- "RawParseTree" => [:masgn,
3143
- [:array, [:lasgn, :a], [:lasgn, :b]], nil,
3144
- [:to_ary, [:vcall, :c]]],
3145
- "ParseTree" => s(:masgn,
3146
- s(:array, s(:lasgn, :a), s(:lasgn, :b)),
3147
- s(:to_ary, s(:call, nil, :c, s(:arglist)))),
3148
- "Ruby2Ruby" => "a, b = c") # TODO: check this is right
3149
-
3150
- add_tests("masgn_splat_to_ary",
3151
- "Ruby" => "a, b, *c = d",
3152
- "RawParseTree" => [:masgn,
3153
- [:array, [:lasgn, :a], [:lasgn, :b]],
3154
- [:lasgn, :c],
3155
- [:to_ary, [:vcall, :d]]],
3156
- "ParseTree" => s(:masgn,
3157
- s(:array,
3158
- s(:lasgn, :a),
3159
- s(:lasgn, :b),
3160
- s(:splat, s(:lasgn, :c))),
3161
- s(:to_ary, s(:call, nil, :d, s(:arglist)))))
3162
-
3163
- add_tests("masgn_splat_to_ary2",
3164
- "Ruby" => "a, b, *c = d.e(\"f\")",
3165
- "RawParseTree" => [:masgn,
3166
- [:array, [:lasgn, :a], [:lasgn, :b]],
3167
- [:lasgn, :c],
3168
- [:to_ary,
3169
- [:call, [:vcall, :d], :e,
3170
- [:array, [:str, 'f']]]]],
3171
- "ParseTree" => s(:masgn,
3172
- s(:array,
3173
- s(:lasgn, :a),
3174
- s(:lasgn, :b),
3175
- s(:splat, s(:lasgn, :c))),
3176
- s(:to_ary,
3177
- s(:call,
3178
- s(:call, nil, :d, s(:arglist)),
3179
- :e,
3180
- s(:arglist, s(:str, 'f'))))))
3181
-
3182
- add_tests("match",
3183
- "Ruby" => "1 if /x/",
3184
- "RawParseTree" => [:if, [:match, [:lit, /x/]], [:lit, 1], nil],
3185
- "ParseTree" => s(:if, s(:match, s(:lit, /x/)), s(:lit, 1), nil))
3186
-
3187
- add_tests("match2",
3188
- "Ruby" => "/x/ =~ \"blah\"",
3189
- "RawParseTree" => [:match2, [:lit, /x/], [:str, "blah"]],
3190
- "ParseTree" => s(:match2, s(:lit, /x/), s(:str, "blah")))
3191
-
3192
- add_tests("match3",
3193
- "Ruby" => "\"blah\" =~ /x/",
3194
- "RawParseTree" => [:match3, [:lit, /x/], [:str, "blah"]],
3195
- "ParseTree" => s(:match3, s(:lit, /x/), s(:str, "blah")))
3196
-
3197
- add_tests("module",
3198
- "Ruby" => "module X\n def y\n # do nothing\n end\nend",
3199
- "RawParseTree" => [:module, :X,
3200
- [:scope,
3201
- [:defn, :y,
3202
- [:scope, [:block, [:args], [:nil]]]]]],
3203
- "ParseTree" => s(:module, :X,
3204
- s(:scope,
3205
- s(:defn, :y,
3206
- s(:args),
3207
- s(:scope, s(:block, s(:nil)))))))
3208
-
3209
- add_tests("module_scoped",
3210
- "Ruby" => "module X::Y\n c\nend",
3211
- "RawParseTree" => [:module, [:colon2, [:const, :X], :Y],
3212
- [:scope, [:vcall, :c]]],
3213
- "ParseTree" => s(:module, s(:colon2, s(:const, :X), :Y),
3214
- s(:scope, s(:call, nil, :c, s(:arglist)))))
3215
-
3216
- add_tests("module_scoped3",
3217
- "Ruby" => "module ::Y\n c\nend",
3218
- "RawParseTree" => [:module, [:colon3, :Y], [:scope, [:vcall, :c]]],
3219
- "ParseTree" => s(:module,
3220
- s(:colon3, :Y),
3221
- s(:scope, s(:call, nil, :c, s(:arglist)))))
3222
-
3223
- add_tests("next",
3224
- "Ruby" => "loop { next if false }",
3225
- "RawParseTree" => [:iter,
3226
- [:fcall, :loop],
3227
- nil,
3228
- [:if, [:false], [:next], nil]],
3229
- "ParseTree" => s(:iter,
3230
- s(:call, nil, :loop, s(:arglist)),
3231
- nil,
3232
- s(:if, s(:false), s(:next), nil)))
3233
-
3234
- add_tests("next_arg",
3235
- "Ruby" => "loop { next 42 if false }",
3236
- "RawParseTree" => [:iter,
3237
- [:fcall, :loop],
3238
- nil,
3239
- [:if, [:false], [:next, [:lit, 42]], nil]],
3240
- "ParseTree" => s(:iter,
3241
- s(:call, nil, :loop, s(:arglist)),
3242
- nil,
3243
- s(:if, s(:false), s(:next, s(:lit, 42)), nil)))
3244
-
3245
- add_tests("not",
3246
- "Ruby" => "(not true)",
3247
- "RawParseTree" => [:not, [:true]],
3248
- "ParseTree" => s(:not, s(:true)))
3249
-
3250
- add_tests("nth_ref",
3251
- "Ruby" => "$1",
3252
- "RawParseTree" => [:nth_ref, 1],
3253
- "ParseTree" => s(:nth_ref, 1))
3254
-
3255
- add_tests("op_asgn1",
3256
- "Ruby" => "b = []\nb[1] ||= 10\nb[2] &&= 11\nb[3] += 12\n",
3257
- "RawParseTree" => [:block,
3258
- [:lasgn, :b, [:zarray]],
3259
- [:op_asgn1, [:lvar, :b],
3260
- [:array, [:lit, 1]], :"||", [:lit, 10]],
3261
- [:op_asgn1, [:lvar, :b],
3262
- [:array, [:lit, 2]], :"&&", [:lit, 11]],
3263
- [:op_asgn1, [:lvar, :b],
3264
- [:array, [:lit, 3]], :+, [:lit, 12]]],
3265
- "ParseTree" => s(:block,
3266
- s(:lasgn, :b, s(:array)),
3267
- s(:op_asgn1, s(:lvar, :b),
3268
- s(:arglist, s(:lit, 1)), :"||", s(:lit, 10)),
3269
- s(:op_asgn1, s(:lvar, :b),
3270
- s(:arglist, s(:lit, 2)), :"&&", s(:lit, 11)),
3271
- s(:op_asgn1, s(:lvar, :b),
3272
- s(:arglist, s(:lit, 3)), :+, s(:lit, 12))))
3273
-
3274
- add_tests("op_asgn1_ivar",
3275
- "Ruby" => "@b = []\n@b[1] ||= 10\n@b[2] &&= 11\n@b[3] += 12\n",
3276
- "RawParseTree" => [:block,
3277
- [:iasgn, :@b, [:zarray]],
3278
- [:op_asgn1, [:ivar, :@b],
3279
- [:array, [:lit, 1]], :"||", [:lit, 10]],
3280
- [:op_asgn1, [:ivar, :@b],
3281
- [:array, [:lit, 2]], :"&&", [:lit, 11]],
3282
- [:op_asgn1, [:ivar, :@b],
3283
- [:array, [:lit, 3]], :+, [:lit, 12]]],
3284
- "ParseTree" => s(:block,
3285
- s(:iasgn, :@b, s(:array)),
3286
- s(:op_asgn1, s(:ivar, :@b),
3287
- s(:arglist, s(:lit, 1)), :"||", s(:lit, 10)),
3288
- s(:op_asgn1, s(:ivar, :@b),
3289
- s(:arglist, s(:lit, 2)), :"&&", s(:lit, 11)),
3290
- s(:op_asgn1, s(:ivar, :@b),
3291
- s(:arglist, s(:lit, 3)), :+, s(:lit, 12))))
3292
-
3293
- add_tests("op_asgn2",
3294
- "Ruby" => "s = Struct.new(:var)\nc = s.new(nil)\nc.var ||= 20\nc.var &&= 21\nc.var += 22\nc.d.e.f ||= 42\n",
3295
- "RawParseTree" => [:block,
3296
- [:lasgn, :s,
3297
- [:call, [:const, :Struct],
3298
- :new, [:array, [:lit, :var]]]],
3299
- [:lasgn, :c,
3300
- [:call, [:lvar, :s], :new, [:array, [:nil]]]],
3301
-
3302
- [:op_asgn2, [:lvar, :c], :var=, :"||",
3303
- [:lit, 20]],
3304
- [:op_asgn2, [:lvar, :c], :var=, :"&&",
3305
- [:lit, 21]],
3306
- [:op_asgn2, [:lvar, :c], :var=, :+, [:lit, 22]],
3307
-
3308
- [:op_asgn2,
3309
- [:call,
3310
- [:call, [:lvar, :c], :d], :e], :f=, :"||",
3311
- [:lit, 42]]],
3312
- "ParseTree" => s(:block,
3313
- s(:lasgn, :s,
3314
- s(:call, s(:const, :Struct),
3315
- :new, s(:arglist, s(:lit, :var)))),
3316
- s(:lasgn, :c,
3317
- s(:call, s(:lvar, :s),
3318
- :new, s(:arglist, s(:nil)))),
3319
- s(:op_asgn2, s(:lvar, :c),
3320
- :var=, :"||", s(:lit, 20)),
3321
- s(:op_asgn2, s(:lvar, :c),
3322
- :var=, :"&&", s(:lit, 21)),
3323
- s(:op_asgn2, s(:lvar, :c),
3324
- :var=, :+, s(:lit, 22)),
3325
- s(:op_asgn2,
3326
- s(:call,
3327
- s(:call, s(:lvar, :c), :d, s(:arglist)),
3328
- :e, s(:arglist)),
3329
- :f=, :"||", s(:lit, 42))))
3330
-
3331
- add_tests("op_asgn2_self",
3332
- "Ruby" => "self.Bag ||= Bag.new",
3333
- "RawParseTree" => [:op_asgn2, [:self], :"Bag=", :"||",
3334
- [:call, [:const, :Bag], :new]],
3335
- "ParseTree" => s(:op_asgn2, s(:self), :"Bag=", :"||",
3336
- s(:call, s(:const, :Bag), :new, s(:arglist))))
3337
-
3338
- add_tests("op_asgn_and",
3339
- "Ruby" => "a = 0\na &&= 2\n",
3340
- "RawParseTree" => [:block,
3341
- [:lasgn, :a, [:lit, 0]],
3342
- [:op_asgn_and,
3343
- [:lvar, :a], [:lasgn, :a, [:lit, 2]]]],
3344
- "ParseTree" => s(:block,
3345
- s(:lasgn, :a, s(:lit, 0)),
3346
- s(:op_asgn_and,
3347
- s(:lvar, :a), s(:lasgn, :a, s(:lit, 2)))))
3348
-
3349
- add_tests("op_asgn_and_ivar2",
3350
- "Ruby" => "@fetcher &&= new(Gem.configuration[:http_proxy])",
3351
- "RawParseTree" => [:op_asgn_and,
3352
- [:ivar, :@fetcher],
3353
- [:iasgn,
3354
- :@fetcher,
3355
- [:fcall,
3356
- :new,
3357
- [:array,
3358
- [:call,
3359
- [:call, [:const, :Gem], :configuration],
3360
- :[],
3361
- [:array, [:lit, :http_proxy]]]]]]],
3362
- "ParseTree" => s(:op_asgn_and,
3363
- s(:ivar, :@fetcher),
3364
- s(:iasgn,
3365
- :@fetcher,
3366
- s(:call, nil,
3367
- :new,
3368
- s(:arglist,
3369
- s(:call,
3370
- s(:call, s(:const, :Gem),
3371
- :configuration,
3372
- s(:arglist)),
3373
- :[],
3374
- s(:arglist, s(:lit, :http_proxy))))))))
3375
-
3376
- add_tests("op_asgn_or",
3377
- "Ruby" => "a = 0\na ||= 1\n",
3378
- "RawParseTree" => [:block,
3379
- [:lasgn, :a, [:lit, 0]],
3380
- [:op_asgn_or,
3381
- [:lvar, :a], [:lasgn, :a, [:lit, 1]]]],
3382
- "ParseTree" => s(:block,
3383
- s(:lasgn, :a, s(:lit, 0)),
3384
- s(:op_asgn_or,
3385
- s(:lvar, :a), s(:lasgn, :a, s(:lit, 1)))))
3386
-
3387
- add_tests("op_asgn_or_block",
3388
- "Ruby" => "a ||= begin\n b\n rescue\n c\n end",
3389
- "RawParseTree" => [:op_asgn_or,
3390
- [:lvar, :a],
3391
- [:lasgn, :a,
3392
- [:rescue,
3393
- [:vcall, :b],
3394
- [:resbody, nil, [:vcall, :c]]]]],
3395
- "ParseTree" => s(:op_asgn_or,
3396
- s(:lvar, :a),
3397
- s(:lasgn, :a,
3398
- s(:rescue,
3399
- s(:call, nil, :b, s(:arglist)),
3400
- s(:resbody, s(:array),
3401
- s(:call, nil, :c, s(:arglist)))))),
3402
- "Ruby2Ruby" => "a ||= b rescue c")
3403
-
3404
- add_tests("op_asgn_or_ivar",
3405
- "Ruby" => "@v ||= { }",
3406
- "RawParseTree" => [:op_asgn_or,
3407
- [:ivar, :@v],
3408
- [:iasgn, :@v, [:hash]]],
3409
- "ParseTree" => s(:op_asgn_or,
3410
- s(:ivar, :@v),
3411
- s(:iasgn, :@v, s(:hash))))
3412
-
3413
- add_tests("op_asgn_or_ivar2",
3414
- "Ruby" => "@fetcher ||= new(Gem.configuration[:http_proxy])",
3415
- "RawParseTree" => [:op_asgn_or,
3416
- [:ivar, :@fetcher],
3417
- [:iasgn,
3418
- :@fetcher,
3419
- [:fcall,
3420
- :new,
3421
- [:array,
3422
- [:call,
3423
- [:call, [:const, :Gem], :configuration],
3424
- :[],
3425
- [:array, [:lit, :http_proxy]]]]]]],
3426
- "ParseTree" => s(:op_asgn_or,
3427
- s(:ivar, :@fetcher),
3428
- s(:iasgn,
3429
- :@fetcher,
3430
- s(:call, nil, :new,
3431
- s(:arglist,
3432
- s(:call,
3433
- s(:call, s(:const, :Gem),
3434
- :configuration,
3435
- s(:arglist)),
3436
- :[],
3437
- s(:arglist, s(:lit, :http_proxy))))))))
3438
-
3439
- add_tests("or",
3440
- "Ruby" => "(a or b)",
3441
- "RawParseTree" => [:or, [:vcall, :a], [:vcall, :b]],
3442
- "ParseTree" => s(:or,
3443
- s(:call, nil, :a, s(:arglist)),
3444
- s(:call, nil, :b, s(:arglist))))
3445
-
3446
- add_tests("or_big",
3447
- "Ruby" => "((a or b) or (c and d))",
3448
- "RawParseTree" => [:or,
3449
- [:or, [:vcall, :a], [:vcall, :b]],
3450
- [:and, [:vcall, :c], [:vcall, :d]]],
3451
- "ParseTree" => s(:or,
3452
- s(:or,
3453
- s(:call, nil, :a, s(:arglist)),
3454
- s(:call, nil, :b, s(:arglist))),
3455
- s(:and,
3456
- s(:call, nil, :c, s(:arglist)),
3457
- s(:call, nil, :d, s(:arglist)))))
3458
-
3459
- add_tests("or_big2",
3460
- "Ruby" => "((a || b) || (c && d))",
3461
- "RawParseTree" => [:or,
3462
- [:or, [:vcall, :a], [:vcall, :b]],
3463
- [:and, [:vcall, :c], [:vcall, :d]]],
3464
- "ParseTree" => s(:or,
3465
- s(:or,
3466
- s(:call, nil, :a, s(:arglist)),
3467
- s(:call, nil, :b, s(:arglist))),
3468
- s(:and,
3469
- s(:call, nil, :c, s(:arglist)),
3470
- s(:call, nil, :d, s(:arglist)))),
3471
- "Ruby2Ruby" => "((a or b) or (c and d))")
3472
-
3473
- add_tests("parse_floats_as_args",
3474
- "Ruby" => "def x(a=0.0,b=0.0)\n a+b\nend",
3475
- "RawParseTree" => [:defn, :x,
3476
- [:scope,
3477
- [:block,
3478
- [:args, :a, :b,
3479
- [:block,
3480
- [:lasgn, :a, [:lit, 0.0]],
3481
- [:lasgn, :b, [:lit, 0.0]]]],
3482
- [:call, [:lvar, :a], :+,
3483
- [:array, [:lvar, :b]]]]]],
3484
- "ParseTree" => s(:defn, :x,
3485
- s(:args, :a, :b,
3486
- s(:block,
3487
- s(:lasgn, :a, s(:lit, 0.0)),
3488
- s(:lasgn, :b, s(:lit, 0.0)))),
3489
- s(:scope,
3490
- s(:block,
3491
- s(:call, s(:lvar, :a), :+,
3492
- s(:arglist, s(:lvar, :b)))))),
3493
- "Ruby2Ruby" => "def x(a = 0.0, b = 0.0)\n (a + b)\nend")
3494
-
3495
- add_tests("postexe",
3496
- "Ruby" => "END { 1 }",
3497
- "RawParseTree" => [:iter, [:postexe], nil, [:lit, 1]],
3498
- "ParseTree" => s(:iter, s(:postexe), nil, s(:lit, 1)))
3499
-
3500
- add_tests("proc_args_0",
3501
- "Ruby" => "proc { || (x + 1) }",
3502
- "RawParseTree" => [:iter,
3503
- [:fcall, :proc],
3504
- 0,
3505
- [:call, [:vcall, :x], :+, [:array, [:lit, 1]]]],
3506
- "ParseTree" => s(:iter,
3507
- s(:call, nil, :proc, s(:arglist)),
3508
- 0,
3509
- s(:call,
3510
- s(:call, nil, :x, s(:arglist)),
3511
- :+,
3512
- s(:arglist, s(:lit, 1)))))
3513
-
3514
- add_tests("proc_args_1",
3515
- "Ruby" => "proc { |x| (x + 1) }",
3516
- "RawParseTree" => [:iter,
3517
- [:fcall, :proc],
3518
- [:dasgn_curr, :x],
3519
- [:call, [:dvar, :x], :+, [:array, [:lit, 1]]]],
3520
- "ParseTree" => s(:iter,
3521
- s(:call, nil, :proc, s(:arglist)),
3522
- s(:lasgn, :x),
3523
- s(:call, s(:lvar, :x), :+,
3524
- s(:arglist, s(:lit, 1)))))
3525
-
3526
- add_tests("proc_args_2",
3527
- "Ruby" => "proc { |x, y| (x + y) }",
3528
- "RawParseTree" => [:iter,
3529
- [:fcall, :proc],
3530
- [:masgn, [:array,
3531
- [:dasgn_curr, :x],
3532
- [:dasgn_curr, :y]], nil, nil],
3533
- [:call, [:dvar, :x], :+, [:array, [:dvar, :y]]]],
3534
- "ParseTree" => s(:iter,
3535
- s(:call, nil, :proc, s(:arglist)),
3536
- s(:masgn,
3537
- s(:array,
3538
- s(:lasgn, :x),
3539
- s(:lasgn, :y))),
3540
- s(:call, s(:lvar, :x), :+,
3541
- s(:arglist, s(:lvar, :y)))))
3542
-
3543
- add_tests("proc_args_no",
3544
- "Ruby" => "proc { (x + 1) }",
3545
- "RawParseTree" => [:iter,
3546
- [:fcall, :proc],
3547
- nil,
3548
- [:call, [:vcall, :x], :+, [:array, [:lit, 1]]]],
3549
- "ParseTree" => s(:iter,
3550
- s(:call, nil, :proc, s(:arglist)),
3551
- nil,
3552
- s(:call, s(:call, nil, :x, s(:arglist)),
3553
- :+, s(:arglist, s(:lit, 1)))))
3554
-
3555
- add_tests("redo",
3556
- "Ruby" => "loop { redo if false }",
3557
- "RawParseTree" => [:iter,
3558
- [:fcall, :loop], nil,
3559
- [:if, [:false], [:redo], nil]],
3560
- "ParseTree" => s(:iter,
3561
- s(:call, nil, :loop, s(:arglist)),
3562
- nil,
3563
- s(:if, s(:false), s(:redo), nil)))
3564
-
3565
- # TODO: need a resbody w/ multiple classes and a splat
3566
-
3567
- add_tests("rescue",
3568
- "Ruby" => "blah rescue nil",
3569
- "RawParseTree" => [:rescue,
3570
- [:vcall, :blah], [:resbody, nil, [:nil]]],
3571
- "ParseTree" => s(:rescue,
3572
- s(:call, nil, :blah, s(:arglist)),
3573
- s(:resbody, s(:array), s(:nil))))
3574
-
3575
- add_tests("rescue_block_body",
3576
- "Ruby" => "begin\n a\nrescue => e\n c\n d\nend",
3577
- "RawParseTree" => [:rescue,
3578
- [:vcall, :a],
3579
- [:resbody, nil,
3580
- [:block,
3581
- [:lasgn, :e, [:gvar, :$!]],
3582
- [:vcall, :c],
3583
- [:vcall, :d]]]],
3584
- "ParseTree" => s(:rescue,
3585
- s(:call, nil, :a, s(:arglist)),
3586
- s(:resbody,
3587
- s(:array, s(:lasgn, :e, s(:gvar, :$!))),
3588
- s(:block,
3589
- s(:call, nil, :c, s(:arglist)),
3590
- s(:call, nil, :d, s(:arglist))))))
3591
-
3592
- add_tests("rescue_block_body_3",
3593
- "Ruby" => "begin\n a\nrescue A\n b\nrescue B\n c\nrescue C\n d\nend",
3594
- "RawParseTree" => [:rescue,
3595
- [:vcall, :a],
3596
- [:resbody, [:array, [:const, :A]],
3597
- [:vcall, :b],
3598
- [:resbody, [:array, [:const, :B]],
3599
- [:vcall, :c],
3600
- [:resbody, [:array, [:const, :C]],
3601
- [:vcall, :d]]]]],
3602
- "ParseTree" => s(:rescue,
3603
- s(:call, nil, :a, s(:arglist)),
3604
- s(:resbody, s(:array, s(:const, :A)),
3605
- s(:call, nil, :b, s(:arglist))),
3606
- s(:resbody, s(:array, s(:const, :B)),
3607
- s(:call, nil, :c, s(:arglist))),
3608
- s(:resbody, s(:array, s(:const, :C)),
3609
- s(:call, nil, :d, s(:arglist)))))
3610
-
3611
- add_tests("rescue_block_body_ivar",
3612
- "Ruby" => "begin\n a\nrescue => @e\n c\n d\nend",
3613
- "RawParseTree" => [:rescue,
3614
- [:vcall, :a],
3615
- [:resbody, nil,
3616
- [:block,
3617
- [:iasgn, :@e, [:gvar, :$!]],
3618
- [:vcall, :c],
3619
- [:vcall, :d]]]],
3620
- "ParseTree" => s(:rescue,
3621
- s(:call, nil, :a, s(:arglist)),
3622
- s(:resbody,
3623
- s(:array, s(:iasgn, :@e, s(:gvar, :$!))),
3624
- s(:block,
3625
- s(:call, nil, :c, s(:arglist)),
3626
- s(:call, nil, :d, s(:arglist))))))
3627
-
3628
- add_tests("rescue_block_nada",
3629
- "Ruby" => "begin\n blah\nrescue\n # do nothing\nend",
3630
- "RawParseTree" => [:rescue, [:vcall, :blah], [:resbody, nil]],
3631
- "ParseTree" => s(:rescue,
3632
- s(:call, nil, :blah, s(:arglist)),
3633
- s(:resbody, s(:array), nil)))
3634
-
3635
- add_tests("rescue_exceptions",
3636
- "Ruby" => "begin\n blah\nrescue RuntimeError => r\n # do nothing\nend",
3637
- "RawParseTree" => [:rescue,
3638
- [:vcall, :blah],
3639
- [:resbody,
3640
- [:array, [:const, :RuntimeError]],
3641
- [:lasgn, :r, [:gvar, :$!]]]],
3642
- "ParseTree" => s(:rescue,
3643
- s(:call, nil, :blah, s(:arglist)),
3644
- s(:resbody,
3645
- s(:array,
3646
- s(:const, :RuntimeError),
3647
- s(:lasgn, :r, s(:gvar, :$!))),
3648
- nil)))
3649
-
3650
-
3651
- add_tests("rescue_iasgn_var_empty",
3652
- "Ruby" => "begin\n 1\nrescue => @e\n # do nothing\nend",
3653
- "RawParseTree" => [:rescue,
3654
- [:lit, 1],
3655
- [:resbody, nil, [:iasgn, :@e, [:gvar, :$!]]]],
3656
- "ParseTree" => s(:rescue,
3657
- s(:lit, 1),
3658
- s(:resbody,
3659
- s(:array, s(:iasgn, :@e, s(:gvar, :$!))),
3660
- nil)))
3661
-
3662
- add_tests("rescue_lasgn",
3663
- "Ruby" => "begin\n 1\nrescue\n var = 2\nend",
3664
- "RawParseTree" => [:rescue,
3665
- [:lit, 1],
3666
- [:resbody, nil, [:lasgn, :var, [:lit, 2]]]],
3667
- "ParseTree" => s(:rescue,
3668
- s(:lit, 1),
3669
- s(:resbody,
3670
- s(:array),
3671
- s(:lasgn, :var, s(:lit, 2)))),
3672
- "Ruby2Ruby" => "1 rescue var = 2")
3673
-
3674
- add_tests("rescue_lasgn_var",
3675
- "Ruby" => "begin\n 1\nrescue => e\n var = 2\nend",
3676
- "RawParseTree" => [:rescue,
3677
- [:lit, 1],
3678
- [:resbody, nil,
3679
- [:block,
3680
- [:lasgn, :e, [:gvar, :$!]],
3681
- [:lasgn, :var, [:lit, 2]]]]],
3682
- "ParseTree" => s(:rescue,
3683
- s(:lit, 1),
3684
- s(:resbody,
3685
- s(:array, s(:lasgn, :e, s(:gvar, :$!))),
3686
- s(:lasgn, :var, s(:lit, 2)))))
3687
-
3688
- add_tests("rescue_lasgn_var_empty",
3689
- "Ruby" => "begin\n 1\nrescue => e\n # do nothing\nend",
3690
- "RawParseTree" => [:rescue,
3691
- [:lit, 1],
3692
- [:resbody, nil, [:lasgn, :e, [:gvar, :$!]]]],
3693
- "ParseTree" => s(:rescue,
3694
- s(:lit, 1),
3695
- s(:resbody,
3696
- s(:array, s(:lasgn, :e, s(:gvar, :$!))),
3697
- nil)))
3698
-
3699
- add_tests("retry",
3700
- "Ruby" => "retry",
3701
- "RawParseTree" => [:retry],
3702
- "ParseTree" => s(:retry))
3703
-
3704
- add_tests("return_0",
3705
- "Ruby" => "return",
3706
- "RawParseTree" => [:return],
3707
- "ParseTree" => s(:return))
3708
-
3709
- add_tests("return_1",
3710
- "Ruby" => "return 1",
3711
- "RawParseTree" => [:return, [:lit, 1]],
3712
- "ParseTree" => s(:return, s(:lit, 1)))
3713
-
3714
- add_tests("return_1_splatted",
3715
- "Ruby" => "return *1",
3716
- "RawParseTree" => [:return, [:svalue, [:splat, [:lit, 1]]]],
3717
- "ParseTree" => s(:return, s(:svalue, s(:splat, s(:lit, 1)))))
3718
-
3719
- add_tests("return_n",
3720
- "Ruby" => "return 1, 2, 3",
3721
- "RawParseTree" => [:return, [:array,
3722
- [:lit, 1], [:lit, 2], [:lit, 3]]],
3723
- "ParseTree" => s(:return, s(:array,
3724
- s(:lit, 1), s(:lit, 2), s(:lit, 3))),
3725
- "Ruby2Ruby" => "return [1, 2, 3]")
3726
-
3727
- add_tests("sclass",
3728
- "Ruby" => "class << self\n 42\nend",
3729
- "RawParseTree" => [:sclass, [:self], [:scope, [:lit, 42]]],
3730
- "ParseTree" => s(:sclass, s(:self), s(:scope, s(:lit, 42))))
3731
-
3732
- add_tests("sclass_trailing_class",
3733
- "Ruby" => "class A\n class << self\n a\n end\n class B\n end\nend",
3734
- "RawParseTree" => [:class, :A, nil,
3735
- [:scope,
3736
- [:block,
3737
- [:sclass, [:self], [:scope, [:vcall, :a]]],
3738
- [:class, :B, nil, [:scope]]]]],
3739
- "ParseTree" => s(:class, :A, nil,
3740
- s(:scope,
3741
- s(:block,
3742
- s(:sclass, s(:self),
3743
- s(:scope,
3744
- s(:call, nil, :a, s(:arglist)))),
3745
- s(:class, :B, nil, s(:scope))))))
3746
-
3747
- add_tests("splat",
3748
- "Ruby" => "def x(*b)\n a(*b)\nend",
3749
- "RawParseTree" => [:defn, :x,
3750
- [:scope,
3751
- [:block,
3752
- [:args, :"*b"],
3753
- [:fcall, :a, [:splat, [:lvar, :b]]]]]],
3754
- "ParseTree" => s(:defn, :x,
3755
- s(:args, :"*b"),
3756
- s(:scope,
3757
- s(:block,
3758
- s(:call, nil, :a,
3759
- s(:arglist, s(:splat, s(:lvar, :b))))))))
3760
-
3761
- add_tests("splat_array",
3762
- "Ruby" => "[*[1]]",
3763
- "RawParseTree" => [:splat, [:array, [:lit, 1]]],
3764
- "ParseTree" => s(:array, s(:splat, s(:array, s(:lit, 1)))))
3765
-
3766
- add_tests("splat_break",
3767
- "Ruby" => "break *[1]",
3768
- "RawParseTree" => [:break, [:svalue, [:splat, [:array, [:lit, 1]]]]],
3769
- "ParseTree" => s(:break, s(:svalue, s(:splat, s(:array, s(:lit, 1))))))
3770
-
3771
- add_tests("splat_break_array",
3772
- "Ruby" => "break [*[1]]",
3773
- "RawParseTree" => [:break, [:splat, [:array, [:lit, 1]]]],
3774
- "ParseTree" => s(:break, s(:array, s(:splat, s(:array, s(:lit, 1))))))
3775
-
3776
- add_tests("splat_fcall",
3777
- "Ruby" => "meth(*[1])",
3778
- "RawParseTree" => [:fcall, :meth,
3779
- [:splat, [:array, [:lit, 1]]]],
3780
- "ParseTree" => s(:call, nil, :meth,
3781
- s(:arglist, s(:splat, s(:array, s(:lit, 1))))))
3782
-
3783
- add_tests("splat_fcall_array",
3784
- "Ruby" => "meth([*[1]])",
3785
- "RawParseTree" => [:fcall, :meth,
3786
- [:array, [:splat, [:array, [:lit, 1]]]]],
3787
- "ParseTree" => s(:call, nil, :meth,
3788
- s(:arglist,
3789
- s(:array, s(:splat, s(:array, s(:lit, 1)))))))
3790
-
3791
- add_tests("splat_lasgn",
3792
- "Ruby" => "x = *[1]",
3793
- "RawParseTree" => [:lasgn, :x, [:svalue, [:splat, [:array, [:lit, 1]]]]],
3794
- "ParseTree" => s(:lasgn, :x, s(:svalue, s(:splat, s(:array, s(:lit, 1))))))
3795
-
3796
- add_tests("splat_lasgn_array",
3797
- "Ruby" => "x = [*[1]]",
3798
- "RawParseTree" => [:lasgn, :x, [:splat, [:array, [:lit, 1]]]],
3799
- "ParseTree" => s(:lasgn, :x, s(:array, s(:splat, s(:array, s(:lit, 1))))))
3800
-
3801
- add_tests("splat_lit_1",
3802
- "Ruby" => "[*1]",
3803
- "RawParseTree" => [:splat, [:lit, 1]], # UGH - damn MRI
3804
- "ParseTree" => s(:array, s(:splat, s(:lit, 1))))
3805
-
3806
- add_tests("splat_lit_n",
3807
- "Ruby" => "[1, *2]",
3808
- "RawParseTree" => [:argscat, [:array, [:lit, 1]], [:lit, 2]],
3809
- "ParseTree" => s(:array, s(:lit, 1), s(:splat, s(:lit, 2))))
3810
-
3811
- add_tests("splat_next",
3812
- "Ruby" => "next *[1]",
3813
- "RawParseTree" => [:next, [:svalue, [:splat, [:array, [:lit, 1]]]]],
3814
- "ParseTree" => s(:next, s(:svalue, s(:splat, s(:array, s(:lit, 1))))))
3815
-
3816
- add_tests("splat_next_array",
3817
- "Ruby" => "next [*[1]]",
3818
- "RawParseTree" => [:next, [:splat, [:array, [:lit, 1]]]],
3819
- "ParseTree" => s(:next, s(:array, s(:splat, s(:array, s(:lit, 1))))))
3820
-
3821
- add_tests("splat_return",
3822
- "Ruby" => "return *[1]",
3823
- "RawParseTree" => [:return, [:svalue, [:splat, [:array, [:lit, 1]]]]],
3824
- "ParseTree" => s(:return, s(:svalue, s(:splat, s(:array, s(:lit, 1))))))
3825
-
3826
- add_tests("splat_return_array",
3827
- "Ruby" => "return [*[1]]",
3828
- "RawParseTree" => [:return, [:splat, [:array, [:lit, 1]]]],
3829
- "ParseTree" => s(:return, s(:array, s(:splat, s(:array, s(:lit, 1))))))
3830
-
3831
- add_tests("splat_super",
3832
- "Ruby" => "super(*[1])",
3833
- "RawParseTree" => [:super, [:splat, [:array, [:lit, 1]]]],
3834
- "ParseTree" => s(:super, s(:splat, s(:array, s(:lit, 1)))))
3835
-
3836
- add_tests("splat_super_array",
3837
- "Ruby" => "super([*[1]])",
3838
- "RawParseTree" => [:super, [:array, [:splat, [:array, [:lit, 1]]]]],
3839
- "ParseTree" => s(:super, s(:array, s(:splat, s(:array, s(:lit, 1))))))
3840
-
3841
- add_tests("splat_yield",
3842
- "Ruby" => "yield(*[1])",
3843
- "RawParseTree" => [:yield, [:splat, [:array, [:lit, 1]]]],
3844
- "ParseTree" => s(:yield, s(:splat, s(:array, s(:lit, 1)))))
3845
-
3846
- add_tests("splat_yield_array",
3847
- "Ruby" => "yield([*[1]])",
3848
- "RawParseTree" => [:yield, [:splat, [:array, [:lit, 1]]], true],
3849
- "ParseTree" => s(:yield, s(:array, s(:splat, s(:array, s(:lit, 1))))))
3850
-
3851
- add_tests("str",
3852
- "Ruby" => '"x"',
3853
- "RawParseTree" => [:str, "x"],
3854
- "ParseTree" => s(:str, "x"))
3855
-
3856
- add_tests("str_concat_newline", # FIX? make prettier? possible?
3857
- "Ruby" => '"before" \\
3858
- " after"',
3859
- "RawParseTree" => [:str, "before after"],
3860
- "ParseTree" => s(:str, "before after"),
3861
- "Ruby2Ruby" => '"before after"')
3862
-
3863
- add_tests("str_concat_space",
3864
- "Ruby" => '"before" " after"',
3865
- "RawParseTree" => [:str, "before after"],
3866
- "ParseTree" => s(:str, "before after"),
3867
- "Ruby2Ruby" => '"before after"')
3868
-
3869
- add_tests("str_heredoc",
3870
- "Ruby" => "<<'EOM'\n blah\nblah\nEOM",
3871
- "RawParseTree" => [:str, " blah\nblah\n"],
3872
- "ParseTree" => s(:str, " blah\nblah\n"),
3873
- "Ruby2Ruby" => "\" blah\\nblah\\n\"")
3874
-
3875
- add_tests("str_heredoc_call",
3876
- "Ruby" => "<<'EOM'.strip\n blah\nblah\nEOM",
3877
- "RawParseTree" => [:call, [:str, " blah\nblah\n"], :strip],
3878
- "ParseTree" => s(:call, s(:str, " blah\nblah\n"),
3879
- :strip, s(:arglist)),
3880
- "Ruby2Ruby" => "\" blah\\nblah\\n\".strip")
3881
-
3882
- add_tests("str_heredoc_double",
3883
- "Ruby" => "a += <<-H1 + b + <<-H2\n first\nH1\n second\nH2",
3884
- "RawParseTree" => [:lasgn, :a,
3885
- [:call,
3886
- [:lvar, :a],
3887
- :+,
3888
- [:array,
3889
- [:call,
3890
- [:call, [:str, " first\n"], :+,
3891
- [:array, [:vcall, :b]]],
3892
- :+,
3893
- [:array, [:str, " second\n"]]]]]],
3894
- "ParseTree" => s(:lasgn, :a,
3895
- s(:call,
3896
- s(:lvar, :a),
3897
- :+,
3898
- s(:arglist,
3899
- s(:call,
3900
- s(:call, s(:str, " first\n"), :+,
3901
- s(:arglist,
3902
- s(:call, nil, :b, s(:arglist)))),
3903
- :+,
3904
- s(:arglist, s(:str, " second\n")))))),
3905
- "Ruby2Ruby" => "a = (a + ((\" first\\n\" + b) + \" second\\n\"))")
3906
-
3907
- add_tests("str_heredoc_empty", # yes... tarded
3908
- "Ruby" => "<<'EOM'\nEOM",
3909
- "RawParseTree" => [:str, ""],
3910
- "ParseTree" => s(:str, ""),
3911
- "Ruby2Ruby" => '""')
3912
-
3913
- add_tests("str_heredoc_indent",
3914
- "Ruby" => "<<-EOM\n blah\nblah\n\n EOM",
3915
- "RawParseTree" => [:str, " blah\nblah\n\n"],
3916
- "ParseTree" => s(:str, " blah\nblah\n\n"),
3917
- "Ruby2Ruby" => "\" blah\\nblah\\n\\n\"")
3918
-
3919
- add_tests("str_interp_file",
3920
- "Ruby" => '"file = #{__FILE__}\n"',
3921
- "RawParseTree" => [:str, "file = (string)\n"],
3922
- "ParseTree" => s(:str, "file = (string)\n"),
3923
- "Ruby2Ruby" => '"file = (string)\\n"')
3924
-
3925
- add_tests("structure_extra_block_for_dvar_scoping",
3926
- "Ruby" => "a.b do |c, d|\n unless e.f(c) then\n g = false\n d.h { |x, i| g = true }\n end\nend",
3927
- "RawParseTree" => [:iter,
3928
- [:call, [:vcall, :a], :b],
3929
- [:masgn, [:array,
3930
- [:dasgn_curr, :c],
3931
- [:dasgn_curr, :d]], nil, nil],
3932
- [:if,
3933
- [:call, [:vcall, :e], :f,
3934
- [:array, [:dvar, :c]]],
3935
- nil,
3936
- [:block,
3937
- [:dasgn_curr, :g, [:false]],
3938
- [:iter,
3939
- [:call, [:dvar, :d], :h],
3940
- [:masgn, [:array,
3941
- [:dasgn_curr, :x],
3942
- [:dasgn_curr, :i]], nil, nil],
3943
- [:dasgn, :g, [:true]]]]]],
3944
- "ParseTree" => s(:iter,
3945
- s(:call,
3946
- s(:call, nil, :a, s(:arglist)),
3947
- :b, s(:arglist)),
3948
- s(:masgn, s(:array,
3949
- s(:lasgn, :c),
3950
- s(:lasgn, :d))),
3951
- s(:if,
3952
- s(:call, s(:call, nil, :e, s(:arglist)), :f,
3953
- s(:arglist, s(:lvar, :c))),
3954
- nil,
3955
- s(:block,
3956
- s(:lasgn, :g, s(:false)),
3957
- s(:iter,
3958
- s(:call, s(:lvar, :d), :h, s(:arglist)),
3959
- s(:masgn, s(:array,
3960
- s(:lasgn, :x),
3961
- s(:lasgn, :i))),
3962
- s(:lasgn, :g, s(:true)))))))
3963
-
3964
- add_tests("structure_remove_begin_1",
3965
- "Ruby" => "a << begin\n b\n rescue\n c\n end",
3966
- "RawParseTree" => [:call, [:vcall, :a], :<<,
3967
- [:array, [:rescue, [:vcall, :b],
3968
- [:resbody, nil, [:vcall, :c]]]]],
3969
- "ParseTree" => s(:call, s(:call, nil, :a, s(:arglist)), :<<,
3970
- s(:arglist,
3971
- s(:rescue,
3972
- s(:call, nil, :b, s(:arglist)),
3973
- s(:resbody, s(:array),
3974
- s(:call, nil, :c, s(:arglist)))))),
3975
- "Ruby2Ruby" => "(a << b rescue c)")
3976
-
3977
- add_tests("structure_remove_begin_2",
3978
- "Ruby" => "a = if c\n begin\n b\n rescue\n nil\n end\n end\na",
3979
- "RawParseTree" => [:block,
3980
- [:lasgn,
3981
- :a,
3982
- [:if, [:vcall, :c],
3983
- [:rescue,
3984
- [:vcall, :b],
3985
- [:resbody, nil, [:nil]]],
3986
- nil]],
3987
- [:lvar, :a]],
3988
- "ParseTree" => s(:block,
3989
- s(:lasgn,
3990
- :a,
3991
- s(:if, s(:call, nil, :c, s(:arglist)),
3992
- s(:rescue, s(:call, nil, :b, s(:arglist)),
3993
- s(:resbody,
3994
- s(:array), s(:nil))),
3995
- nil)),
3996
- s(:lvar, :a)),
3997
- "Ruby2Ruby" => "a = b rescue nil if c\na\n") # OMG that's awesome
3998
-
3999
- add_tests("structure_unused_literal_wwtt",
4000
- "Ruby" => "\"prevent the above from infecting rdoc\"\n\nmodule Graffle\nend",
4001
- "RawParseTree" => [:module, :Graffle, [:scope]],
4002
- "ParseTree" => s(:module, :Graffle, s(:scope)),
4003
- "Ruby2Ruby" => "module Graffle\nend")
4004
-
4005
- add_tests("super_0",
4006
- "Ruby" => "def x\n super()\nend",
4007
- "RawParseTree" => [:defn, :x,
4008
- [:scope,
4009
- [:block, [:args], [:super]]]],
4010
- "ParseTree" => s(:defn, :x,
4011
- s(:args),
4012
- s(:scope, s(:block, s(:super)))))
4013
-
4014
- add_tests("super_1",
4015
- "Ruby" => "def x\n super(4)\nend",
4016
- "RawParseTree" => [:defn, :x,
4017
- [:scope,
4018
- [:block,
4019
- [:args],
4020
- [:super, [:array, [:lit, 4]]]]]],
4021
- "ParseTree" => s(:defn, :x,
4022
- s(:args),
4023
- s(:scope,
4024
- s(:block,
4025
- s(:super, s(:lit, 4))))))
4026
-
4027
- add_tests("super_1_array",
4028
- "Ruby" => "def x\n super([24, 42])\nend",
4029
- "RawParseTree" => [:defn, :x,
4030
- [:scope,
4031
- [:block,
4032
- [:args],
4033
- [:super,
4034
- [:array,
4035
- [:array, [:lit, 24], [:lit, 42]]]]]]],
4036
- "ParseTree" => s(:defn, :x,
4037
- s(:args),
4038
- s(:scope,
4039
- s(:block,
4040
- s(:super, s(:array,
4041
- s(:lit, 24),
4042
- s(:lit, 42)))))))
4043
-
4044
- add_tests("super_block_pass",
4045
- "Ruby" => "super(a, &b)",
4046
- "RawParseTree" => [:block_pass,
4047
- [:vcall, :b], [:super, [:array, [:vcall, :a]]]],
4048
- "ParseTree" => s(:super,
4049
- s(:call, nil, :a, s(:arglist)),
4050
- s(:block_pass,
4051
- s(:call, nil, :b, s(:arglist)))))
4052
-
4053
- add_tests("super_block_splat",
4054
- "Ruby" => "super(a, *b)",
4055
- "RawParseTree" => [:super,
4056
- [:argscat,
4057
- [:array, [:vcall, :a]],
4058
- [:vcall, :b]]],
4059
- "ParseTree" => s(:super,
4060
- s(:call, nil, :a, s(:arglist)),
4061
- s(:splat, s(:call, nil, :b, s(:arglist)))))
4062
-
4063
- add_tests("super_n",
4064
- "Ruby" => "def x\n super(24, 42)\nend",
4065
- "RawParseTree" => [:defn, :x,
4066
- [:scope,
4067
- [:block,
4068
- [:args],
4069
- [:super, [:array, [:lit, 24], [:lit, 42]]]]]],
4070
- "ParseTree" => s(:defn, :x,
4071
- s(:args),
4072
- s(:scope,
4073
- s(:block,
4074
- s(:super, s(:lit, 24), s(:lit, 42))))))
4075
-
4076
- add_tests("svalue",
4077
- "Ruby" => "a = *b",
4078
- "RawParseTree" => [:lasgn, :a, [:svalue, [:splat, [:vcall, :b]]]],
4079
- "ParseTree" => s(:lasgn, :a,
4080
- s(:svalue,
4081
- s(:splat, s(:call, nil, :b, s(:arglist))))))
4082
-
4083
- add_tests("to_ary",
4084
- "Ruby" => "a, b = c",
4085
- "RawParseTree" => [:masgn,
4086
- [:array, [:lasgn, :a], [:lasgn, :b]], nil,
4087
- [:to_ary, [:vcall, :c]]],
4088
- "ParseTree" => s(:masgn,
4089
- s(:array, s(:lasgn, :a), s(:lasgn, :b)),
4090
- s(:to_ary, s(:call, nil, :c, s(:arglist)))))
4091
-
4092
- add_tests("true",
4093
- "Ruby" => "true",
4094
- "RawParseTree" => [:true],
4095
- "ParseTree" => s(:true))
4096
-
4097
- add_tests("undef",
4098
- "Ruby" => "undef :x",
4099
- "RawParseTree" => [:undef, [:lit, :x]],
4100
- "ParseTree" => s(:undef, s(:lit, :x)))
4101
-
4102
- add_tests("undef_2",
4103
- "Ruby" => "undef :x, :y",
4104
- "RawParseTree" => [:block,
4105
- [:undef, [:lit, :x]],
4106
- [:undef, [:lit, :y]]],
4107
- "ParseTree" => s(:block,
4108
- s(:undef, s(:lit, :x)),
4109
- s(:undef, s(:lit, :y))),
4110
- "Ruby2Ruby" => "undef :x\nundef :y\n")
4111
-
4112
- add_tests("undef_3",
4113
- "Ruby" => "undef :x, :y, :z",
4114
- "RawParseTree" => [:block,
4115
- [:undef, [:lit, :x]],
4116
- [:undef, [:lit, :y]],
4117
- [:undef, [:lit, :z]]],
4118
- "ParseTree" => s(:block,
4119
- s(:undef, s(:lit, :x)),
4120
- s(:undef, s(:lit, :y)),
4121
- s(:undef, s(:lit, :z))),
4122
- "Ruby2Ruby" => "undef :x\nundef :y\nundef :z\n")
4123
-
4124
- add_tests("undef_block_1",
4125
- "Ruby" => "f1\nundef :x\n", # TODO: don't like the extra return
4126
- "RawParseTree" => [:block,
4127
- [:vcall, :f1],
4128
- [:undef, [:lit, :x]]],
4129
- "ParseTree" => s(:block,
4130
- s(:call, nil, :f1, s(:arglist)),
4131
- s(:undef, s(:lit, :x))))
4132
-
4133
- add_tests("undef_block_2",
4134
- "Ruby" => "f1\nundef :x, :y",
4135
- "RawParseTree" => [:block,
4136
- [:vcall, :f1],
4137
- [:block,
4138
- [:undef, [:lit, :x]],
4139
- [:undef, [:lit, :y]],
4140
- ]],
4141
- "ParseTree" => s(:block,
4142
- s(:call, nil, :f1, s(:arglist)),
4143
- s(:block,
4144
- s(:undef, s(:lit, :x)),
4145
- s(:undef, s(:lit, :y)))),
4146
- "Ruby2Ruby" => "f1\n(undef :x\nundef :y)\n")
4147
-
4148
- add_tests("undef_block_3",
4149
- "Ruby" => "f1\nundef :x, :y, :z",
4150
- "RawParseTree" => [:block,
4151
- [:vcall, :f1],
4152
- [:block,
4153
- [:undef, [:lit, :x]],
4154
- [:undef, [:lit, :y]],
4155
- [:undef, [:lit, :z]],
4156
- ]],
4157
- "ParseTree" => s(:block,
4158
- s(:call, nil, :f1, s(:arglist)),
4159
- s(:block,
4160
- s(:undef, s(:lit, :x)),
4161
- s(:undef, s(:lit, :y)),
4162
- s(:undef, s(:lit, :z)))),
4163
- "Ruby2Ruby" => "f1\n(undef :x\nundef :y\nundef :z)\n")
4164
-
4165
- add_tests("undef_block_3_post",
4166
- "Ruby" => "undef :x, :y, :z\nf2",
4167
- "RawParseTree" => [:block,
4168
- [:undef, [:lit, :x]],
4169
- [:undef, [:lit, :y]],
4170
- [:undef, [:lit, :z]],
4171
- [:vcall, :f2]],
4172
- "ParseTree" => s(:block,
4173
- s(:undef, s(:lit, :x)),
4174
- s(:undef, s(:lit, :y)),
4175
- s(:undef, s(:lit, :z)),
4176
- s(:call, nil, :f2, s(:arglist))),
4177
- "Ruby2Ruby" => "undef :x\nundef :y\nundef :z\nf2\n")
4178
-
4179
- add_tests("undef_block_wtf",
4180
- "Ruby" => "f1\nundef :x, :y, :z\nf2",
4181
- "RawParseTree" => [:block,
4182
- [:vcall, :f1],
4183
- [:block,
4184
- [:undef, [:lit, :x]],
4185
- [:undef, [:lit, :y]],
4186
- [:undef, [:lit, :z]]],
4187
- [:vcall, :f2]],
4188
- "ParseTree" => s(:block,
4189
- s(:call, nil, :f1, s(:arglist)),
4190
- s(:block,
4191
- s(:undef, s(:lit, :x)),
4192
- s(:undef, s(:lit, :y)),
4193
- s(:undef, s(:lit, :z))),
4194
- s(:call, nil, :f2, s(:arglist))),
4195
- "Ruby2Ruby" => "f1\n(undef :x\nundef :y\nundef :z)\nf2\n")
4196
-
4197
-
4198
- add_tests("unless_post",
4199
- "Ruby" => "a unless b",
4200
- "RawParseTree" => [:if, [:vcall, :b], nil, [:vcall, :a]],
4201
- "ParseTree" => s(:if, s(:call, nil, :b, s(:arglist)), nil,
4202
- s(:call, nil, :a, s(:arglist))))
4203
-
4204
- add_tests("unless_post_not",
4205
- "Ruby" => "a unless not b",
4206
- "RawParseTree" => [:if, [:vcall, :b], [:vcall, :a], nil],
4207
- "ParseTree" => s(:if, s(:call, nil, :b, s(:arglist)),
4208
- s(:call, nil, :a, s(:arglist)), nil),
4209
- "Ruby2Ruby" => "a if b")
4210
-
4211
- add_tests("unless_pre",
4212
- "Ruby" => "unless b then a end",
4213
- "RawParseTree" => [:if, [:vcall, :b], nil, [:vcall, :a]],
4214
- "ParseTree" => s(:if, s(:call, nil, :b, s(:arglist)), nil,
4215
- s(:call, nil, :a, s(:arglist))),
4216
- "Ruby2Ruby" => "a unless b")
4217
-
4218
- add_tests("unless_pre_not",
4219
- "Ruby" => "unless not b then a end",
4220
- "RawParseTree" => [:if, [:vcall, :b], [:vcall, :a], nil],
4221
- "ParseTree" => s(:if, s(:call, nil, :b, s(:arglist)),
4222
- s(:call, nil, :a, s(:arglist)), nil),
4223
- "Ruby2Ruby" => "a if b")
4224
-
4225
- add_tests("until_post",
4226
- "Ruby" => "begin\n (1 + 1)\nend until false",
4227
- "RawParseTree" => [:until, [:false],
4228
- [:call, [:lit, 1], :+,
4229
- [:array, [:lit, 1]]], false],
4230
- "ParseTree" => s(:until, s(:false),
4231
- s(:call, s(:lit, 1), :+,
4232
- s(:arglist, s(:lit, 1))), false))
4233
-
4234
- add_tests("until_post_not",
4235
- "Ruby" => "begin\n (1 + 1)\nend until not true",
4236
- "RawParseTree" => [:while, [:true],
4237
- [:call, [:lit, 1], :+,
4238
- [:array, [:lit, 1]]], false],
4239
- "ParseTree" => s(:while, s(:true),
4240
- s(:call, s(:lit, 1), :+,
4241
- s(:arglist, s(:lit, 1))), false),
4242
- "Ruby2Ruby" => "begin\n (1 + 1)\nend while true")
4243
-
4244
- add_tests("until_pre",
4245
- "Ruby" => "until false do\n (1 + 1)\nend",
4246
- "RawParseTree" => [:until, [:false],
4247
- [:call, [:lit, 1], :+,
4248
- [:array, [:lit, 1]]], true],
4249
- "ParseTree" => s(:until, s(:false),
4250
- s(:call, s(:lit, 1), :+,
4251
- s(:arglist, s(:lit, 1))), true))
4252
-
4253
- add_tests("until_pre_mod",
4254
- "Ruby" => "(1 + 1) until false",
4255
- "RawParseTree" => [:until, [:false],
4256
- [:call, [:lit, 1], :+,
4257
- [:array, [:lit, 1]]], true],
4258
- "ParseTree" => s(:until, s(:false),
4259
- s(:call, s(:lit, 1), :+,
4260
- s(:arglist, s(:lit, 1))), true),
4261
- "Ruby2Ruby" => "until false do\n (1 + 1)\nend")
4262
-
4263
- add_tests("until_pre_not",
4264
- "Ruby" => "until not true do\n (1 + 1)\nend",
4265
- "RawParseTree" => [:while, [:true],
4266
- [:call, [:lit, 1], :+,
4267
- [:array, [:lit, 1]]], true],
4268
- "ParseTree" => s(:while, s(:true),
4269
- s(:call, s(:lit, 1), :+,
4270
- s(:arglist, s(:lit, 1))), true),
4271
- "Ruby2Ruby" => "while true do\n (1 + 1)\nend")
4272
-
4273
- add_tests("until_pre_not_mod",
4274
- "Ruby" => "(1 + 1) until not true",
4275
- "RawParseTree" => [:while, [:true],
4276
- [:call, [:lit, 1], :+,
4277
- [:array, [:lit, 1]]], true],
4278
- "ParseTree" => s(:while, s(:true),
4279
- s(:call, s(:lit, 1), :+,
4280
- s(:arglist, s(:lit, 1))), true),
4281
- "Ruby2Ruby" => "while true do\n (1 + 1)\nend")
4282
-
4283
- add_tests("valias",
4284
- "Ruby" => "alias $y $x",
4285
- "RawParseTree" => [:valias, :$y, :$x],
4286
- "ParseTree" => s(:valias, :$y, :$x))
4287
-
4288
- add_tests("vcall",
4289
- "Ruby" => "method",
4290
- "RawParseTree" => [:vcall, :method],
4291
- "ParseTree" => s(:call, nil, :method, s(:arglist)))
4292
-
4293
- add_tests("while_post",
4294
- "Ruby" => "begin\n (1 + 1)\nend while false",
4295
- "RawParseTree" => [:while, [:false],
4296
- [:call, [:lit, 1], :+,
4297
- [:array, [:lit, 1]]], false],
4298
- "ParseTree" => s(:while, s(:false),
4299
- s(:call, s(:lit, 1), :+,
4300
- s(:arglist, s(:lit, 1))), false))
4301
-
4302
- add_tests("while_post2",
4303
- "Ruby" => "begin\n (1 + 2)\n (3 + 4)\nend while false",
4304
- "RawParseTree" => [:while, [:false],
4305
- [:block,
4306
- [:call, [:lit, 1], :+, [:array, [:lit, 2]]],
4307
- [:call, [:lit, 3], :+, [:array, [:lit, 4]]]],
4308
- false],
4309
- "ParseTree" => s(:while, s(:false),
4310
- s(:block,
4311
- s(:call, s(:lit, 1), :+,
4312
- s(:arglist, s(:lit, 2))),
4313
- s(:call, s(:lit, 3), :+,
4314
- s(:arglist, s(:lit, 4)))),
4315
- false))
4316
-
4317
- add_tests("while_post_not",
4318
- "Ruby" => "begin\n (1 + 1)\nend while not true",
4319
- "RawParseTree" => [:until, [:true],
4320
- [:call, [:lit, 1], :+,
4321
- [:array, [:lit, 1]]], false],
4322
- "ParseTree" => s(:until, s(:true),
4323
- s(:call, s(:lit, 1), :+,
4324
- s(:arglist, s(:lit, 1))), false),
4325
- "Ruby2Ruby" => "begin\n (1 + 1)\nend until true")
4326
-
4327
- add_tests("while_pre",
4328
- "Ruby" => "while false do\n (1 + 1)\nend",
4329
- "RawParseTree" => [:while, [:false],
4330
- [:call, [:lit, 1], :+,
4331
- [:array, [:lit, 1]]], true],
4332
- "ParseTree" => s(:while, s(:false),
4333
- s(:call, s(:lit, 1), :+,
4334
- s(:arglist, s(:lit, 1))), true))
4335
-
4336
- add_tests("while_pre_mod",
4337
- "Ruby" => "(1 + 1) while false",
4338
- "RawParseTree" => [:while, [:false],
4339
- [:call, [:lit, 1], :+,
4340
- [:array, [:lit, 1]]], true],
4341
- "ParseTree" => s(:while, s(:false),
4342
- s(:call, s(:lit, 1), :+,
4343
- s(:arglist, s(:lit, 1))), true),
4344
- "Ruby2Ruby" => "while false do\n (1 + 1)\nend") # FIX can be one liner
4345
-
4346
- add_tests("while_pre_nil",
4347
- "Ruby" => "while false do\nend",
4348
- "RawParseTree" => [:while, [:false], nil, true],
4349
- "ParseTree" => s(:while, s(:false), nil, true))
4350
-
4351
- add_tests("while_pre_not",
4352
- "Ruby" => "while not true do\n (1 + 1)\nend",
4353
- "RawParseTree" => [:until, [:true],
4354
- [:call, [:lit, 1], :+,
4355
- [:array, [:lit, 1]]], true],
4356
- "ParseTree" => s(:until, s(:true),
4357
- s(:call, s(:lit, 1), :+,
4358
- s(:arglist, s(:lit, 1))), true),
4359
- "Ruby2Ruby" => "until true do\n (1 + 1)\nend")
4360
-
4361
- add_tests("while_pre_not_mod",
4362
- "Ruby" => "(1 + 1) while not true",
4363
- "RawParseTree" => [:until, [:true],
4364
- [:call, [:lit, 1], :+,
4365
- [:array, [:lit, 1]]], true],
4366
- "ParseTree" => s(:until, s(:true),
4367
- s(:call, s(:lit, 1), :+,
4368
- s(:arglist, s(:lit, 1))), true),
4369
- "Ruby2Ruby" => "until true do\n (1 + 1)\nend") # FIX
4370
-
4371
- add_tests("xstr",
4372
- "Ruby" => "`touch 5`",
4373
- "RawParseTree" => [:xstr, 'touch 5'],
4374
- "ParseTree" => s(:xstr, 'touch 5'))
4375
-
4376
- add_tests("yield_0",
4377
- "Ruby" => "yield",
4378
- "RawParseTree" => [:yield],
4379
- "ParseTree" => s(:yield))
4380
-
4381
- add_tests("yield_1",
4382
- "Ruby" => "yield(42)",
4383
- "RawParseTree" => [:yield, [:lit, 42]],
4384
- "ParseTree" => s(:yield, s(:lit, 42)))
4385
-
4386
- add_tests("yield_array_0",
4387
- "Ruby" => "yield([])",
4388
- "RawParseTree" => [:yield, [:zarray], true],
4389
- "ParseTree" => s(:yield, s(:array)))
4390
-
4391
- add_tests("yield_array_1",
4392
- "Ruby" => "yield([42])",
4393
- "RawParseTree" => [:yield, [:array, [:lit, 42]], true],
4394
- "ParseTree" => s(:yield, s(:array, s(:lit, 42))))
4395
-
4396
- add_tests("yield_array_n",
4397
- "Ruby" => "yield([42, 24])",
4398
- "RawParseTree" => [:yield, [:array, [:lit, 42], [:lit, 24]], true],
4399
- "ParseTree" => s(:yield, s(:array, s(:lit, 42), s(:lit, 24))))
4400
-
4401
- add_tests("yield_n",
4402
- "Ruby" => "yield(42, 24)",
4403
- "RawParseTree" => [:yield, [:array, [:lit, 42], [:lit, 24]]],
4404
- "ParseTree" => s(:yield, s(:lit, 42), s(:lit, 24)))
4405
-
4406
- add_tests("zarray",
4407
- "Ruby" => "a = []",
4408
- "RawParseTree" => [:lasgn, :a, [:zarray]],
4409
- "ParseTree" => s(:lasgn, :a, s(:array)))
4410
-
4411
- add_tests("zsuper",
4412
- "Ruby" => "def x\n super\nend",
4413
- "RawParseTree" => [:defn, :x,
4414
- [:scope, [:block, [:args], [:zsuper]]]],
4415
- "ParseTree" => s(:defn, :x, s(:args),
4416
- s(:scope, s(:block, s(:zsuper)))))
4417
- end