ParseTree 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +29 -0
- data/README.txt +5 -4
- data/Rakefile +12 -28
- data/bin/parse_tree_abc +0 -0
- data/bin/parse_tree_audit +0 -0
- data/bin/parse_tree_deps +0 -0
- data/bin/parse_tree_show +0 -0
- data/demo/printer.rb +0 -0
- data/lib/parse_tree.rb +63 -11
- data/lib/sexp.rb +6 -2
- data/lib/sexp_processor.rb +1 -1
- data/lib/unified_ruby.rb +4 -13
- data/test/pt_testcase.rb +210 -123
- data/test/test_all.rb +0 -0
- data/test/test_composite_sexp_processor.rb +0 -0
- data/test/test_parse_tree.rb +15 -6
- data/test/test_sexp.rb +16 -21
- data/test/test_sexp_processor.rb +10 -14
- data/test/test_unified_ruby.rb +9 -25
- data/validate.sh +0 -0
- metadata +9 -8
data/History.txt
CHANGED
@@ -1,3 +1,32 @@
|
|
1
|
+
=== 2.2.0 / 2008-06-09
|
2
|
+
|
3
|
+
* 18 minor enhancements:
|
4
|
+
|
5
|
+
* Added 1.9 and rubinius to multiruby skip list.
|
6
|
+
* Added 1.9 fixes for SexpProcessor.
|
7
|
+
* Added compatibility changes for regexp option values.
|
8
|
+
* Added custom compact since Array#compact is hostile to subclasses.
|
9
|
+
* Added some tests for wonky index edge cases. some commented out.
|
10
|
+
* Added test changes for 1.9 and r2r changes. Esp fixed regexp differences.
|
11
|
+
* Added tests for dasgn, proc arities,
|
12
|
+
* Added/updated some tests for ruby_parser.
|
13
|
+
* Changed tests to default to nil for verbose.
|
14
|
+
* Fixed all assertions deprecated in miniunit.
|
15
|
+
* Raises LoadError if incompatible ruby, allows fallback to ruby_parser.
|
16
|
+
* Removed Unified's rewrite_fbody and moved up into defn... not sure about that.
|
17
|
+
* Removed argscat rewriter from unified_ruby.rb
|
18
|
+
* Renamed shadowed variable name.
|
19
|
+
* Reworked parse_tree_for_(method|string) to take optional verbose arg.
|
20
|
+
* Started removing ending newlines from pt_testcase.rb.
|
21
|
+
* Uncommented all commented out tests. ruby_parser must not be a pansy.
|
22
|
+
* Updated rakefile for new hoe abilities.
|
23
|
+
|
24
|
+
* 3 bug fixes:
|
25
|
+
|
26
|
+
* Fixed 1.8.[45] wrt dasgn_curr declaration removal.
|
27
|
+
* Fixed pt_testcase bug.
|
28
|
+
* Fixes for colon2/3 in class/module/cdecls.
|
29
|
+
|
1
30
|
=== 2.1.1 / 2007-12-22
|
2
31
|
|
3
32
|
* 1 bug fix:
|
data/README.txt
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
ParseTree
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
= ParseTree
|
2
|
+
|
3
|
+
* http://rubyforge.org/projects/parsetree/
|
4
|
+
* http://www.zenspider.com/ZSS/Products/ParseTree/
|
5
|
+
* ryand-ruby@zenspider.com
|
5
6
|
|
6
7
|
== DESCRIPTION:
|
7
8
|
|
data/Rakefile
CHANGED
@@ -3,25 +3,23 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'hoe'
|
5
5
|
|
6
|
-
$: << "../../RubyInline/dev"
|
6
|
+
$: << "../../RubyInline/dev/lib"
|
7
7
|
require './lib/parse_tree.rb'
|
8
8
|
|
9
|
-
Hoe.new("ParseTree", ParseTree::VERSION) do |
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
p.spec_extras[:require_paths] = proc { |paths| paths << 'test' }
|
18
|
-
end
|
9
|
+
Hoe.new("ParseTree", ParseTree::VERSION) do |pt|
|
10
|
+
pt.rubyforge_name = "parsetree"
|
11
|
+
|
12
|
+
pt.developer('Ryan Davis', 'ryand-ruby@zenspider.com')
|
13
|
+
|
14
|
+
pt.clean_globs << File.expand_path("~/.ruby_inline")
|
15
|
+
pt.extra_deps << ['RubyInline', '>= 3.6.0']
|
16
|
+
pt.spec_extras[:require_paths] = proc { |paths| paths << 'test' }
|
19
17
|
|
20
|
-
|
21
|
-
task :test19 do
|
22
|
-
sh "~/.multiruby/install/1_9/bin/ruby -d #{Hoe::RUBY_FLAGS} test/test_all.rb #{Hoe::FILTER}"
|
18
|
+
pt.multiruby_skip << "1.9" << "rubinius"
|
23
19
|
end
|
24
20
|
|
21
|
+
Hoe::RUBY_FLAGS.sub! /-I/, '-I../../RubyInline/dev/lib:test:'
|
22
|
+
|
25
23
|
desc 'Run in gdb'
|
26
24
|
task :debug do
|
27
25
|
puts "RUN: r -d #{Hoe::RUBY_FLAGS} test/test_all.rb #{Hoe::FILTER}"
|
@@ -32,17 +30,3 @@ desc 'Run a very basic demo'
|
|
32
30
|
task :demo do
|
33
31
|
sh "echo 1+1 | ruby #{Hoe::RUBY_FLAGS} ./bin/parse_tree_show -f"
|
34
32
|
end
|
35
|
-
|
36
|
-
desc 'Show what tests are not sorted'
|
37
|
-
task :sort do
|
38
|
-
begin
|
39
|
-
sh "pgrep '^ \\\"(\\w+)' test/pt_testcase.rb | cut -f 2 -d\\\" > x"
|
40
|
-
sh "sort x > y"
|
41
|
-
sh "diff x y"
|
42
|
-
|
43
|
-
sh 'for f in lib/*.rb; do echo $f; grep "^ *def " $f | grep -v sort=skip > x; sort x > y; echo $f; echo; diff x y; done'
|
44
|
-
sh 'for f in test/test_*.rb; do echo $f; grep "^ *def.test_" $f > x; sort x > y; echo $f; echo; diff x y; done'
|
45
|
-
ensure
|
46
|
-
sh 'rm -f x y'
|
47
|
-
end
|
48
|
-
end
|
data/bin/parse_tree_abc
CHANGED
File without changes
|
data/bin/parse_tree_audit
CHANGED
File without changes
|
data/bin/parse_tree_deps
CHANGED
File without changes
|
data/bin/parse_tree_show
CHANGED
File without changes
|
data/demo/printer.rb
CHANGED
File without changes
|
data/lib/parse_tree.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
#!/usr/local/bin/ruby -w
|
2
2
|
|
3
|
-
|
3
|
+
raise LoadError, "ParseTree doesn't work with ruby #{RUBY_VERSION}" if
|
4
4
|
RUBY_VERSION >= "1.9"
|
5
|
+
raise LoadError, "ParseTree isn't needed with rubinius" if
|
6
|
+
defined? RUBY_ENGINE and RUBY_ENGINE == "rbx"
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
+
require 'rubygems'
|
8
9
|
require 'inline'
|
9
10
|
|
10
11
|
class Module
|
@@ -41,7 +42,7 @@ end
|
|
41
42
|
|
42
43
|
class ParseTree
|
43
44
|
|
44
|
-
VERSION = '2.
|
45
|
+
VERSION = '2.2.0'
|
45
46
|
|
46
47
|
##
|
47
48
|
# Front end translation method.
|
@@ -144,10 +145,13 @@ class ParseTree
|
|
144
145
|
#
|
145
146
|
# [:defn, :name, :body]
|
146
147
|
|
147
|
-
def parse_tree_for_method(klass, method, is_cls_meth=false)
|
148
|
+
def parse_tree_for_method(klass, method, is_cls_meth=false, verbose = true)
|
148
149
|
$stderr.puts "** parse_tree_for_method(#{klass}, #{method}):" if $DEBUG
|
150
|
+
old_verbose, $VERBOSE = $VERBOSE, verbose
|
149
151
|
r = parse_tree_for_meth(klass, method.to_sym, is_cls_meth)
|
150
152
|
r
|
153
|
+
ensure
|
154
|
+
$VERBOSE = old_verbose
|
151
155
|
end
|
152
156
|
|
153
157
|
##
|
@@ -157,8 +161,9 @@ class ParseTree
|
|
157
161
|
#
|
158
162
|
# [[sexps] ... ]
|
159
163
|
|
160
|
-
def parse_tree_for_string(source,
|
161
|
-
|
164
|
+
def parse_tree_for_string(source,
|
165
|
+
filename = '(string)', line = 1, verbose = true)
|
166
|
+
old_verbose, $VERBOSE = $VERBOSE, verbose
|
162
167
|
return parse_tree_for_str0(source, filename, line)
|
163
168
|
ensure
|
164
169
|
$VERBOSE = old_verbose
|
@@ -252,6 +257,11 @@ class ParseTree
|
|
252
257
|
builder.include '"st.h"'
|
253
258
|
builder.include '"env.h"'
|
254
259
|
|
260
|
+
if RUBY_VERSION < "1.8.6" then
|
261
|
+
builder.prefix '#define RARRAY_PTR(s) (RARRAY(s)->ptr)'
|
262
|
+
builder.prefix '#define RARRAY_LEN(s) (RARRAY(s)->len)'
|
263
|
+
end
|
264
|
+
|
255
265
|
if ENV['ANAL'] or ENV['DOMAIN'] =~ /zenspider/ then
|
256
266
|
builder.add_compile_flags "-Wall"
|
257
267
|
builder.add_compile_flags "-W"
|
@@ -337,6 +347,7 @@ void add_to_parse_tree(VALUE self, VALUE ary, NODE * n, ID * locals) {
|
|
337
347
|
VALUE current;
|
338
348
|
VALUE node_name;
|
339
349
|
static VALUE node_names = Qnil;
|
350
|
+
static int masgn_level = 0;
|
340
351
|
|
341
352
|
if (NIL_P(node_names)) {
|
342
353
|
node_names = rb_const_get_at(rb_path2class("ParseTree"),rb_intern("NODE_NAMES"));
|
@@ -371,6 +382,11 @@ again:
|
|
371
382
|
add_to_parse_tree(self, current, node->nd_head, locals);
|
372
383
|
node = node->nd_next;
|
373
384
|
}
|
385
|
+
if (!masgn_level && RARRAY_LEN(current) == 2) {
|
386
|
+
rb_ary_pop(ary);
|
387
|
+
rb_ary_push(ary, rb_ary_pop(current));
|
388
|
+
return;
|
389
|
+
}
|
374
390
|
}
|
375
391
|
break;
|
376
392
|
|
@@ -472,6 +488,7 @@ again:
|
|
472
488
|
case NODE_ITER:
|
473
489
|
case NODE_FOR:
|
474
490
|
add_to_parse_tree(self, current, node->nd_iter, locals);
|
491
|
+
masgn_level++;
|
475
492
|
if (node->nd_var != (NODE *)1
|
476
493
|
&& node->nd_var != (NODE *)2
|
477
494
|
&& node->nd_var != NULL) {
|
@@ -485,6 +502,7 @@ again:
|
|
485
502
|
rb_ary_push(current, INT2FIX(0));
|
486
503
|
}
|
487
504
|
}
|
505
|
+
masgn_level--;
|
488
506
|
add_to_parse_tree(self, current, node->nd_body, locals);
|
489
507
|
break;
|
490
508
|
|
@@ -571,10 +589,11 @@ again:
|
|
571
589
|
if (data->var == 0 || data->var == (NODE *)1 || data->var == (NODE *)2) {
|
572
590
|
rb_ary_push(current, Qnil);
|
573
591
|
} else {
|
592
|
+
masgn_level++;
|
574
593
|
add_to_parse_tree(self, current, data->var, locals);
|
594
|
+
masgn_level--;
|
575
595
|
}
|
576
596
|
add_to_parse_tree(self, current, data->body, locals);
|
577
|
-
break;
|
578
597
|
}
|
579
598
|
break;
|
580
599
|
|
@@ -645,6 +664,7 @@ again:
|
|
645
664
|
break;
|
646
665
|
|
647
666
|
case NODE_MASGN:
|
667
|
+
masgn_level++;
|
648
668
|
add_to_parse_tree(self, current, node->nd_head, locals);
|
649
669
|
if (node->nd_args) {
|
650
670
|
if (node->nd_args != (NODE *)-1) {
|
@@ -654,13 +674,12 @@ again:
|
|
654
674
|
}
|
655
675
|
}
|
656
676
|
add_to_parse_tree(self, current, node->nd_value, locals);
|
677
|
+
masgn_level--;
|
657
678
|
break;
|
658
679
|
|
659
680
|
case NODE_LASGN:
|
660
681
|
case NODE_IASGN:
|
661
682
|
case NODE_DASGN:
|
662
|
-
case NODE_DASGN_CURR:
|
663
|
-
case NODE_CDECL:
|
664
683
|
case NODE_CVASGN:
|
665
684
|
case NODE_CVDECL:
|
666
685
|
case NODE_GASGN:
|
@@ -668,6 +687,32 @@ again:
|
|
668
687
|
add_to_parse_tree(self, current, node->nd_value, locals);
|
669
688
|
break;
|
670
689
|
|
690
|
+
case NODE_CDECL:
|
691
|
+
if (node->nd_vid) {
|
692
|
+
rb_ary_push(current, ID2SYM(node->nd_vid));
|
693
|
+
} else {
|
694
|
+
add_to_parse_tree(self, current, node->nd_else, locals);
|
695
|
+
}
|
696
|
+
|
697
|
+
add_to_parse_tree(self, current, node->nd_value, locals);
|
698
|
+
break;
|
699
|
+
|
700
|
+
case NODE_DASGN_CURR:
|
701
|
+
rb_ary_push(current, ID2SYM(node->nd_vid));
|
702
|
+
if (node->nd_value) {
|
703
|
+
add_to_parse_tree(self, current, node->nd_value, locals);
|
704
|
+
if (!masgn_level && RARRAY_LEN(current) == 2) {
|
705
|
+
rb_ary_pop(ary);
|
706
|
+
return;
|
707
|
+
}
|
708
|
+
} else {
|
709
|
+
if (!masgn_level) {
|
710
|
+
rb_ary_pop(ary);
|
711
|
+
return;
|
712
|
+
}
|
713
|
+
}
|
714
|
+
break;
|
715
|
+
|
671
716
|
case NODE_VALIAS: /* u1 u2 (alias $global $global2) */
|
672
717
|
#if RUBY_VERSION_CODE < 185
|
673
718
|
rb_ary_push(current, ID2SYM(node->u2.id));
|
@@ -768,7 +813,12 @@ again:
|
|
768
813
|
|
769
814
|
case NODE_CLASS:
|
770
815
|
case NODE_MODULE:
|
771
|
-
|
816
|
+
if (nd_type(node->nd_cpath) == NODE_COLON2 && ! node->nd_cpath->nd_vid) {
|
817
|
+
rb_ary_push(current, ID2SYM((ID)node->nd_cpath->nd_mid));
|
818
|
+
} else {
|
819
|
+
add_to_parse_tree(self, current, node->nd_cpath, locals);
|
820
|
+
}
|
821
|
+
|
772
822
|
if (nd_type(node) == NODE_CLASS) {
|
773
823
|
if (node->nd_super) {
|
774
824
|
add_to_parse_tree(self, current, node->nd_super, locals);
|
@@ -794,6 +844,7 @@ again:
|
|
794
844
|
}
|
795
845
|
|
796
846
|
/* look for optional arguments */
|
847
|
+
masgn_level++;
|
797
848
|
optnode = node->nd_opt;
|
798
849
|
while (optnode) {
|
799
850
|
rb_ary_push(current, ID2SYM(locals[i + 3]));
|
@@ -840,6 +891,7 @@ again:
|
|
840
891
|
if (optnode) {
|
841
892
|
add_to_parse_tree(self, current, node->nd_opt, locals);
|
842
893
|
}
|
894
|
+
masgn_level--;
|
843
895
|
} break;
|
844
896
|
|
845
897
|
case NODE_LVAR:
|
data/lib/sexp.rb
CHANGED
@@ -27,8 +27,8 @@ class Sexp < Array # ZenTest FULL
|
|
27
27
|
def self.for(klass, method = nil, walk_ancestors = false)
|
28
28
|
require 'parse_tree'
|
29
29
|
sexp = if walk_ancestors and method then
|
30
|
-
klass.ancestors.each do |
|
31
|
-
sexp = ParseTree.translate
|
30
|
+
klass.ancestors.each do |kls|
|
31
|
+
sexp = ParseTree.translate kls, method
|
32
32
|
break sexp unless sexp == [nil]
|
33
33
|
end
|
34
34
|
else
|
@@ -101,6 +101,10 @@ class Sexp < Array # ZenTest FULL
|
|
101
101
|
@@array_types.include? type
|
102
102
|
end
|
103
103
|
|
104
|
+
def compact # :nodoc:
|
105
|
+
self.delete_if { |o| o.nil? }
|
106
|
+
end
|
107
|
+
|
104
108
|
##
|
105
109
|
# Enumeratates the sexp yielding to +b+ when the node_type == +t+.
|
106
110
|
|
data/lib/sexp_processor.rb
CHANGED
@@ -194,7 +194,7 @@ class SexpProcessor
|
|
194
194
|
return nil if exp.nil?
|
195
195
|
|
196
196
|
unless @unsupported_checked then
|
197
|
-
m = public_methods.grep(/^process_/) { |o| o.sub(/^process_/, '').intern }
|
197
|
+
m = public_methods.grep(/^process_/) { |o| o.to_s.sub(/^process_/, '').intern }
|
198
198
|
supported = m - (m - @unsupported)
|
199
199
|
|
200
200
|
raise UnsupportedNodeError, "#{supported.inspect} shouldn't be in @unsupported" unless supported.empty?
|
data/lib/unified_ruby.rb
CHANGED
@@ -2,12 +2,6 @@
|
|
2
2
|
$TESTING ||= false
|
3
3
|
|
4
4
|
module UnifiedRuby
|
5
|
-
def rewrite_argscat(exp)
|
6
|
-
raise "unknown type #{exp.inspect}" unless exp[1][0] == :array
|
7
|
-
exp[1][0] = :arglist
|
8
|
-
exp
|
9
|
-
end
|
10
|
-
|
11
5
|
def rewrite_bmethod(exp)
|
12
6
|
exp[0] = :scope
|
13
7
|
|
@@ -45,7 +39,7 @@ module UnifiedRuby
|
|
45
39
|
when :argscat, :splat then
|
46
40
|
# do nothing
|
47
41
|
else
|
48
|
-
raise "unknown type in call #{args.first.inspect}"
|
42
|
+
raise "unknown type in call #{args.first.inspect} in #{exp.inspect}"
|
49
43
|
end
|
50
44
|
return exp
|
51
45
|
end
|
@@ -85,12 +79,13 @@ module UnifiedRuby
|
|
85
79
|
#
|
86
80
|
# s(:defn, :reader, s(:args), s(:ivar, :@name))
|
87
81
|
#
|
88
|
-
#
|
89
82
|
|
90
83
|
def rewrite_defn(exp)
|
91
84
|
weirdo = exp.ivar || exp.attrset
|
92
85
|
|
93
|
-
|
86
|
+
fbody = exp.fbody(true)
|
87
|
+
exp.push(fbody.scope) if fbody
|
88
|
+
|
94
89
|
args = exp.scope.block.args(true) unless weirdo
|
95
90
|
exp.insert 2, args if args
|
96
91
|
|
@@ -124,10 +119,6 @@ module UnifiedRuby
|
|
124
119
|
exp.shift # scope / block / body
|
125
120
|
end
|
126
121
|
|
127
|
-
def rewrite_fbody(exp)
|
128
|
-
return *exp.sexp_body
|
129
|
-
end
|
130
|
-
|
131
122
|
def rewrite_fcall(exp)
|
132
123
|
exp[0] = :call
|
133
124
|
exp.insert 1, nil
|
data/test/pt_testcase.rb
CHANGED
@@ -135,6 +135,15 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
135
135
|
"ParseTree" => [:attrasgn, [:vcall, :a], :[]=, [:array, [:lit, 42], [:lit, 24]]],
|
136
136
|
},
|
137
137
|
|
138
|
+
"attrasgn_index_equals_space" => {
|
139
|
+
"Ruby" => "a = []; a [42] = 24",
|
140
|
+
"ParseTree" => [:block,
|
141
|
+
[:lasgn, :a, [:zarray]],
|
142
|
+
[:attrasgn, [:lvar, :a], :[]=,
|
143
|
+
[:array, [:lit, 42], [:lit, 24]]]],
|
144
|
+
"Ruby2Ruby" => "a = []\na[42] = 24\n",
|
145
|
+
},
|
146
|
+
|
138
147
|
"attrset" => {
|
139
148
|
"Ruby" => [Examples, :writer=],
|
140
149
|
"ParseTree" => [:defn, :writer=, [:attrset, :@writer]],
|
@@ -145,8 +154,8 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
145
154
|
"Ruby" => "[$&, $`, $', $+]",
|
146
155
|
"ParseTree" => [:array,
|
147
156
|
[:back_ref, :&],
|
148
|
-
[:back_ref, "`"
|
149
|
-
[:back_ref, "'"
|
157
|
+
[:back_ref, :"`"],
|
158
|
+
[:back_ref, :"'"],
|
150
159
|
[:back_ref, :+]],
|
151
160
|
},
|
152
161
|
|
@@ -191,22 +200,20 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
191
200
|
},
|
192
201
|
|
193
202
|
"block_mystery_block" => { # FIX: I don't like that extra return
|
194
|
-
"Ruby" => "a(b) do\n if b then\n true\n else\n c = false\n d { |x| c = true }\n c\n
|
203
|
+
"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",
|
195
204
|
"ParseTree" => [:iter,
|
196
205
|
[:fcall, :a, [:array, [:vcall, :b]]],
|
197
206
|
nil,
|
198
|
-
[:
|
199
|
-
[:
|
200
|
-
[:
|
201
|
-
|
202
|
-
[:
|
203
|
-
[:
|
204
|
-
[:
|
205
|
-
[:
|
206
|
-
|
207
|
-
|
208
|
-
[:dasgn, :c, [:true]]],
|
209
|
-
[:dvar, :c]]]]],
|
207
|
+
[:if,
|
208
|
+
[:vcall, :b],
|
209
|
+
[:true],
|
210
|
+
[:block,
|
211
|
+
[:dasgn_curr, :c, [:false]],
|
212
|
+
[:iter,
|
213
|
+
[:fcall, :d],
|
214
|
+
[:dasgn_curr, :x],
|
215
|
+
[:dasgn, :c, [:true]]],
|
216
|
+
[:dvar, :c]]]],
|
210
217
|
},
|
211
218
|
|
212
219
|
"block_pass_args_and_splat" => {
|
@@ -214,7 +221,7 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
214
221
|
"ParseTree" => [:defn, :blah,
|
215
222
|
[:scope,
|
216
223
|
[:block,
|
217
|
-
[:args, "*args"
|
224
|
+
[:args, :"*args"],
|
218
225
|
[:block_arg, :block],
|
219
226
|
[:block_pass,
|
220
227
|
[:lvar, :block],
|
@@ -278,7 +285,7 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
278
285
|
"ParseTree" => [:defn, :blah,
|
279
286
|
[:scope,
|
280
287
|
[:block,
|
281
|
-
[:args, "*args"
|
288
|
+
[:args, :"*args"],
|
282
289
|
[:block_arg, :block],
|
283
290
|
[:block_pass,
|
284
291
|
[:lvar, :block],
|
@@ -295,8 +302,7 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
295
302
|
|
296
303
|
"block_stmt_after" => {
|
297
304
|
"Ruby" => "def f\n begin\n b\n rescue\n c\n end\n\n d\nend",
|
298
|
-
"ParseTree" => [:defn,
|
299
|
-
:f,
|
305
|
+
"ParseTree" => [:defn, :f,
|
300
306
|
[:scope,
|
301
307
|
[:block,
|
302
308
|
[:args],
|
@@ -307,8 +313,7 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
307
313
|
|
308
314
|
"block_stmt_before" => {
|
309
315
|
"Ruby" => "def f\n a\n begin\n b\n rescue\n c\n end\nend",
|
310
|
-
"ParseTree" => [:defn,
|
311
|
-
:f,
|
316
|
+
"ParseTree" => [:defn, :f,
|
312
317
|
[:scope,
|
313
318
|
[:block,
|
314
319
|
[:args],
|
@@ -320,8 +325,7 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
320
325
|
|
321
326
|
"block_stmt_both" => {
|
322
327
|
"Ruby" => "def f\n a\n begin\n b\n rescue\n c\n end\n d\nend",
|
323
|
-
"ParseTree" => [:defn,
|
324
|
-
:f,
|
328
|
+
"ParseTree" => [:defn, :f,
|
325
329
|
[:scope,
|
326
330
|
[:block,
|
327
331
|
[:args],
|
@@ -333,8 +337,7 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
333
337
|
|
334
338
|
"bmethod" => {
|
335
339
|
"Ruby" => [Examples, :unsplatted],
|
336
|
-
"ParseTree" => [:defn,
|
337
|
-
:unsplatted,
|
340
|
+
"ParseTree" => [:defn, :unsplatted,
|
338
341
|
[:bmethod,
|
339
342
|
[:dasgn_curr, :x],
|
340
343
|
[:call, [:dvar, :x], :+, [:array, [:lit, 1]]]]],
|
@@ -343,11 +346,10 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
343
346
|
|
344
347
|
"bmethod_noargs" => {
|
345
348
|
"Ruby" => [Examples, :bmethod_noargs],
|
346
|
-
"ParseTree" => [:defn,
|
347
|
-
:bmethod_noargs,
|
349
|
+
"ParseTree" => [:defn, :bmethod_noargs,
|
348
350
|
[:bmethod,
|
349
351
|
nil,
|
350
|
-
[:call, [:vcall, :x], "+"
|
352
|
+
[:call, [:vcall, :x], :"+", [:array, [:lit, 1]]]]],
|
351
353
|
"Ruby2Ruby" => "def bmethod_noargs\n (x + 1)\nend"
|
352
354
|
},
|
353
355
|
|
@@ -426,9 +428,11 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
426
428
|
:zero?],
|
427
429
|
},
|
428
430
|
|
429
|
-
"call_index" => { # see attrasgn_index_equals
|
430
|
-
"Ruby" => "
|
431
|
-
"ParseTree" => [:
|
431
|
+
"call_index" => { # see attrasgn_index_equals and fcall_index_space
|
432
|
+
"Ruby" => "b = []\na[42]\n",
|
433
|
+
"ParseTree" => [:block,
|
434
|
+
[:lasgn, :b, [:zarray]],
|
435
|
+
[:call, [:vcall, :a], :[], [:array, [:lit, 42]]]],
|
432
436
|
},
|
433
437
|
|
434
438
|
"call_index_no_args" => {
|
@@ -436,6 +440,14 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
436
440
|
"ParseTree" => [:call, [:vcall, :a], :[]],
|
437
441
|
},
|
438
442
|
|
443
|
+
"call_index_space" => {
|
444
|
+
"Ruby" => "a = []\na [42]\n",
|
445
|
+
"ParseTree" => [:block,
|
446
|
+
[:lasgn, :a, [:zarray]],
|
447
|
+
[:call, [:lvar, :a], :[], [:array, [:lit, 42]]]],
|
448
|
+
"Ruby2Ruby" => "a = []\na[42]\n",
|
449
|
+
},
|
450
|
+
|
439
451
|
"call_unary_neg" => {
|
440
452
|
"Ruby" => "-2**31",
|
441
453
|
"ParseTree" => [:call,
|
@@ -544,14 +556,24 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
544
556
|
[:scope,
|
545
557
|
[:block,
|
546
558
|
[:fcall, :puts, [:array, [:call, [:lit, 1], :+, [:array, [:lit, 1]]]]],
|
547
|
-
[:defn,
|
548
|
-
:blah,
|
559
|
+
[:defn, :blah,
|
549
560
|
[:scope,
|
550
561
|
[:block,
|
551
562
|
[:args],
|
552
563
|
[:fcall, :puts, [:array, [:str, "hello"]]]]]]]]],
|
553
564
|
},
|
554
565
|
|
566
|
+
"class_scoped" => {
|
567
|
+
"Ruby" => "class X::Y\n c\nend",
|
568
|
+
"ParseTree" => [:class, [:colon2, [:const, :X], :Y], nil,
|
569
|
+
[:scope, [:vcall, :c]]],
|
570
|
+
},
|
571
|
+
|
572
|
+
"class_scoped3" => {
|
573
|
+
"Ruby" => "class ::Y\n c\nend",
|
574
|
+
"ParseTree" => [:class, [:colon3, :Y], nil, [:scope, [:vcall, :c]]],
|
575
|
+
},
|
576
|
+
|
555
577
|
"class_super_array" => {
|
556
578
|
"Ruby" => "class X < Array\nend",
|
557
579
|
"ParseTree" => [:class,
|
@@ -677,6 +699,21 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
677
699
|
"ParseTree" => [:const, :X],
|
678
700
|
},
|
679
701
|
|
702
|
+
"constX" => {
|
703
|
+
"Ruby" => "X = 1",
|
704
|
+
"ParseTree" => [:cdecl, :X, [:lit, 1]],
|
705
|
+
},
|
706
|
+
|
707
|
+
"constY" => {
|
708
|
+
"Ruby" => "::X = 1",
|
709
|
+
"ParseTree" => [:cdecl, [:colon3, :X], [:lit, 1]],
|
710
|
+
},
|
711
|
+
|
712
|
+
"constZ" => {
|
713
|
+
"Ruby" => "X::Y = 1",
|
714
|
+
"ParseTree" => [:cdecl, [:colon2, [:const, :X], :Y], [:lit, 1]],
|
715
|
+
},
|
716
|
+
|
680
717
|
"cvar" => {
|
681
718
|
"Ruby" => "@@x",
|
682
719
|
"ParseTree" => [:cvar, :@@x],
|
@@ -729,21 +766,30 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
729
766
|
},
|
730
767
|
|
731
768
|
"dasgn_2" => { # WITH mystery block / dasgn_curr
|
732
|
-
"Ruby" => "a.each do |x|\n if true then\n c = 0\n b.each { |y| c = (c + 1) }\n
|
769
|
+
"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!
|
733
770
|
"ParseTree" => [:iter,
|
734
771
|
[:call, [:vcall, :a], :each],
|
735
772
|
[:dasgn_curr, :x],
|
773
|
+
[:if, [:true],
|
774
|
+
[:block,
|
775
|
+
[:dasgn_curr, :c, [:lit, 0]],
|
776
|
+
[:iter,
|
777
|
+
[:call, [:vcall, :b], :each],
|
778
|
+
[:dasgn_curr, :y],
|
779
|
+
[:dasgn, :c,
|
780
|
+
[:call, [:dvar, :c], :+, [:array, [:lit, 1]]]]]],
|
781
|
+
nil]],
|
782
|
+
},
|
783
|
+
|
784
|
+
"dasgn_curr" => {
|
785
|
+
"Ruby" => "data.each do |x, y|\n a = 1\n b = a\n b = a = x\nend",
|
786
|
+
"ParseTree" => [:iter,
|
787
|
+
[:call, [:vcall, :data], :each],
|
788
|
+
[:masgn, [:array, [:dasgn_curr, :x], [:dasgn_curr, :y]]],
|
736
789
|
[:block,
|
737
|
-
[:dasgn_curr, :
|
738
|
-
[:
|
739
|
-
|
740
|
-
[:dasgn_curr, :c, [:lit, 0]],
|
741
|
-
[:iter,
|
742
|
-
[:call, [:vcall, :b], :each],
|
743
|
-
[:dasgn_curr, :y],
|
744
|
-
[:dasgn, :c,
|
745
|
-
[:call, [:dvar, :c], :+, [:array, [:lit, 1]]]]]],
|
746
|
-
nil]]],
|
790
|
+
[:dasgn_curr, :a, [:lit, 1]],
|
791
|
+
[:dasgn_curr, :b, [:dvar, :a]],
|
792
|
+
[:dasgn_curr, :b, [:dasgn_curr, :a, [:dvar, :x]]]]],
|
747
793
|
},
|
748
794
|
|
749
795
|
"dasgn_icky" => { # WITH mystery block / dasgn_curr
|
@@ -752,7 +798,6 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
752
798
|
[:fcall, :a],
|
753
799
|
nil,
|
754
800
|
[:block,
|
755
|
-
[:dasgn_curr, :v],
|
756
801
|
[:dasgn_curr, :v, [:nil]],
|
757
802
|
[:iter,
|
758
803
|
[:fcall, :assert_block,
|
@@ -766,17 +811,6 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
766
811
|
[:block, [:dasgn, :v, [:gvar, :$!]], [:break]]]]]]]],
|
767
812
|
},
|
768
813
|
|
769
|
-
"dasgn_curr" => {
|
770
|
-
"Ruby" => "data.each do |x, y|\n a = 1\n b = a\n b = a = x\nend",
|
771
|
-
"ParseTree" => [:iter,
|
772
|
-
[:call, [:vcall, :data], :each],
|
773
|
-
[:masgn, [:array, [:dasgn_curr, :x], [:dasgn_curr, :y]]],
|
774
|
-
[:block,
|
775
|
-
[:dasgn_curr, :a, [:lit, 1]],
|
776
|
-
[:dasgn_curr, :b, [:dvar, :a]],
|
777
|
-
[:dasgn_curr, :b, [:dasgn_curr, :a, [:dvar, :x]]]]],
|
778
|
-
},
|
779
|
-
|
780
814
|
"dasgn_mixed" => {
|
781
815
|
"Ruby" => "t = 0\nns.each { |n| t += n }\n",
|
782
816
|
"ParseTree" => [:block,
|
@@ -822,7 +856,7 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
822
856
|
"ParseTree" => [:defn, :x,
|
823
857
|
[:scope,
|
824
858
|
[:block,
|
825
|
-
[:args, :a, :b, "*c"
|
859
|
+
[:args, :a, :b, :"*c",
|
826
860
|
[:block, [:lasgn, :b, [:lit, 42]]]],
|
827
861
|
[:block_arg, :d],
|
828
862
|
[:fcall, :p,
|
@@ -900,7 +934,7 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
900
934
|
"ParseTree" => [:defn, :x,
|
901
935
|
[:scope,
|
902
936
|
[:block,
|
903
|
-
[:args, :a, "*args"
|
937
|
+
[:args, :a, :"*args"],
|
904
938
|
[:fcall, :p,
|
905
939
|
[:array, [:lvar, :a], [:lvar, :args]]]]]],
|
906
940
|
},
|
@@ -935,7 +969,7 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
935
969
|
"ParseTree" => [:defn, :x,
|
936
970
|
[:scope,
|
937
971
|
[:block,
|
938
|
-
[:args, :a, "*"
|
972
|
+
[:args, :a, :"*"],
|
939
973
|
[:fcall, :p,
|
940
974
|
[:array, [:lvar, :a]]]]]],
|
941
975
|
},
|
@@ -982,8 +1016,7 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
982
1016
|
|
983
1017
|
"dmethod" => {
|
984
1018
|
"Ruby" => [Examples, :dmethod_added],
|
985
|
-
"ParseTree" => [:defn,
|
986
|
-
:dmethod_added,
|
1019
|
+
"ParseTree" => [:defn, :dmethod_added,
|
987
1020
|
[:dmethod,
|
988
1021
|
:a_method,
|
989
1022
|
[:scope,
|
@@ -1016,7 +1049,7 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
1016
1049
|
|
1017
1050
|
"dregx_n" => {
|
1018
1051
|
"Ruby" => '/#{1}/n',
|
1019
|
-
"ParseTree" => [:dregx, '', [:evstr, [:lit, 1]],
|
1052
|
+
"ParseTree" => [:dregx, '', [:evstr, [:lit, 1]], /x/n.options],
|
1020
1053
|
"Ruby2Ruby" => "/#\{1}/", # HACK - need to support regexp flags
|
1021
1054
|
},
|
1022
1055
|
|
@@ -1028,7 +1061,7 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
1028
1061
|
|
1029
1062
|
"dregx_once_n_interp" => {
|
1030
1063
|
"Ruby" => "/#\{IAC}#\{SB}/no",
|
1031
|
-
"ParseTree" => [:dregx_once, '', [:evstr, [:const, :IAC]], [:evstr, [:const, :SB]],
|
1064
|
+
"ParseTree" => [:dregx_once, '', [:evstr, [:const, :IAC]], [:evstr, [:const, :SB]], /x/n.options],
|
1032
1065
|
"Ruby2Ruby" => "/#\{IAC}#\{SB}/o", # HACK
|
1033
1066
|
},
|
1034
1067
|
|
@@ -1076,6 +1109,23 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
1076
1109
|
"Ruby2Ruby" => '"#{22}aacd#{44}55#{66}"',
|
1077
1110
|
},
|
1078
1111
|
|
1112
|
+
"dstr_heredoc_expand" => {
|
1113
|
+
"Ruby" => "<<EOM\n blah\n#\{1 + 1}blah\nEOM\n",
|
1114
|
+
"ParseTree" => [:dstr, " blah\n",
|
1115
|
+
[:evstr, [:call, [:lit, 1], :+, [:array, [:lit, 1]]]],
|
1116
|
+
[:str, "blah\n"]],
|
1117
|
+
"Ruby2Ruby" => "\" blah\\n#\{(1 + 1)}blah\\n\"",
|
1118
|
+
},
|
1119
|
+
|
1120
|
+
"dstr_heredoc_windoze_sucks" => {
|
1121
|
+
"Ruby" => "<<-EOF\r\ndef test_#\{action}_valid_feed\r\n EOF\r\n",
|
1122
|
+
"ParseTree" => [:dstr,
|
1123
|
+
'def test_',
|
1124
|
+
[:evstr, [:vcall, :action]],
|
1125
|
+
[:str, "_valid_feed\n"]],
|
1126
|
+
"Ruby2Ruby" => "\"def test_#\{action}_valid_feed\\n\"",
|
1127
|
+
},
|
1128
|
+
|
1079
1129
|
"dstr_heredoc_yet_again" => {
|
1080
1130
|
"Ruby" => "<<-EOF\ns1 '#\{RUBY_PLATFORM}' s2\n#\{__FILE__}\n EOF\n",
|
1081
1131
|
"ParseTree" => [:dstr, "s1 '",
|
@@ -1204,6 +1254,12 @@ end",
|
|
1204
1254
|
[:lit, :c]],
|
1205
1255
|
},
|
1206
1256
|
|
1257
|
+
"fcall_index_space" => {
|
1258
|
+
"Ruby" => "a [42]",
|
1259
|
+
"ParseTree" => [:fcall, :a, [:array, [:array, [:lit, 42]]]],
|
1260
|
+
"Ruby2Ruby" => "a([42])",
|
1261
|
+
},
|
1262
|
+
|
1207
1263
|
"fcall_keyword" => {
|
1208
1264
|
"Ruby" => "42 if block_given?",
|
1209
1265
|
"ParseTree" => [:if, [:fcall, :block_given?], [:lit, 42], nil],
|
@@ -1374,13 +1430,13 @@ end",
|
|
1374
1430
|
"ParseTree" => [:block,
|
1375
1431
|
[:lasgn, :argl, [:lit, 10]],
|
1376
1432
|
[:while,
|
1377
|
-
[:call, [:lvar, :argl], ">="
|
1433
|
+
[:call, [:lvar, :argl], :">=", [:array, [:lit, 1]]],
|
1378
1434
|
[:block,
|
1379
1435
|
[:fcall, :puts, [:array, [:str, "hello"]]],
|
1380
1436
|
[:lasgn,
|
1381
1437
|
:argl,
|
1382
1438
|
[:call, [:lvar, :argl],
|
1383
|
-
"-"
|
1439
|
+
:"-", [:array, [:lit, 1]]]]], true]],
|
1384
1440
|
},
|
1385
1441
|
|
1386
1442
|
"iteration6" => {
|
@@ -1540,10 +1596,11 @@ end",
|
|
1540
1596
|
"Ruby" => 'str.split(//i)',
|
1541
1597
|
"ParseTree" => [:call, [:vcall, :str], :split, [:array, [:lit, //i]]],
|
1542
1598
|
},
|
1543
|
-
|
1599
|
+
|
1544
1600
|
"lit_regexp_n" => {
|
1545
1601
|
"Ruby" => "/x/n",
|
1546
1602
|
"ParseTree" => [:lit, /x/n],
|
1603
|
+
"Ruby2Ruby" => /x/n.inspect, # HACK differs on 1.9 - this is easiest
|
1547
1604
|
},
|
1548
1605
|
|
1549
1606
|
"lit_regexp_once" => {
|
@@ -1566,8 +1623,7 @@ end",
|
|
1566
1623
|
"Ruby" => "b = 42\ndef a\n c do\n begin\n rescue RuntimeError => b\n puts(b)\n end\n end\nend\n",
|
1567
1624
|
"ParseTree" => [:block,
|
1568
1625
|
[:lasgn, :b, [:lit, 42]],
|
1569
|
-
[:defn,
|
1570
|
-
:a,
|
1626
|
+
[:defn, :a,
|
1571
1627
|
[:scope,
|
1572
1628
|
[:block,
|
1573
1629
|
[:args],
|
@@ -1610,7 +1666,7 @@ end",
|
|
1610
1666
|
"masgn_iasgn" => {
|
1611
1667
|
"Ruby" => "a, @b = c, d",
|
1612
1668
|
"ParseTree" => [:masgn,
|
1613
|
-
[:array, [:lasgn, :a], [:iasgn, "@b"
|
1669
|
+
[:array, [:lasgn, :a], [:iasgn, :"@b"]],
|
1614
1670
|
[:array, [:vcall, :c], [:vcall, :d]]],
|
1615
1671
|
},
|
1616
1672
|
|
@@ -1697,6 +1753,17 @@ end",
|
|
1697
1753
|
[:defn, :y, [:scope, [:block, [:args], [:nil]]]]]],
|
1698
1754
|
},
|
1699
1755
|
|
1756
|
+
"module_scoped" => {
|
1757
|
+
"Ruby" => "module X::Y\n c\nend",
|
1758
|
+
"ParseTree" => [:module, [:colon2, [:const, :X], :Y],
|
1759
|
+
[:scope, [:vcall, :c]]],
|
1760
|
+
},
|
1761
|
+
|
1762
|
+
"module_scoped3" => {
|
1763
|
+
"Ruby" => "module ::Y\n c\nend",
|
1764
|
+
"ParseTree" => [:module, [:colon3, :Y], [:scope, [:vcall, :c]]],
|
1765
|
+
},
|
1766
|
+
|
1700
1767
|
"next" => {
|
1701
1768
|
"Ruby" => "loop { next if false }",
|
1702
1769
|
"ParseTree" => [:iter,
|
@@ -1728,13 +1795,25 @@ end",
|
|
1728
1795
|
"ParseTree" => [:block,
|
1729
1796
|
[:lasgn, :b, [:zarray]],
|
1730
1797
|
[:op_asgn1, [:lvar, :b],
|
1731
|
-
[:array, [:lit, 1]], "||"
|
1798
|
+
[:array, [:lit, 1]], :"||", [:lit, 10]],
|
1732
1799
|
[:op_asgn1, [:lvar, :b],
|
1733
|
-
[:array, [:lit, 2]], "&&"
|
1800
|
+
[:array, [:lit, 2]], :"&&", [:lit, 11]],
|
1734
1801
|
[:op_asgn1, [:lvar, :b],
|
1735
1802
|
[:array, [:lit, 3]], :+, [:lit, 12]]],
|
1736
1803
|
},
|
1737
1804
|
|
1805
|
+
"op_asgn1" => {
|
1806
|
+
"Ruby" => "@b = []\n@b[1] ||= 10\n@b[2] &&= 11\n@b[3] += 12\n",
|
1807
|
+
"ParseTree" => [:block,
|
1808
|
+
[:iasgn, :@b, [:zarray]],
|
1809
|
+
[:op_asgn1, [:ivar, :@b],
|
1810
|
+
[:array, [:lit, 1]], :"||", [:lit, 10]],
|
1811
|
+
[:op_asgn1, [:ivar, :@b],
|
1812
|
+
[:array, [:lit, 2]], :"&&", [:lit, 11]],
|
1813
|
+
[:op_asgn1, [:ivar, :@b],
|
1814
|
+
[:array, [:lit, 3]], :+, [:lit, 12]]],
|
1815
|
+
},
|
1816
|
+
|
1738
1817
|
"op_asgn2" => {
|
1739
1818
|
"Ruby" => "s = Struct.new(:var)\nc = s.new(nil)\nc.var ||= 20\nc.var &&= 21\nc.var += 22\nc.d.e.f ||= 42\n",
|
1740
1819
|
"ParseTree" => [:block,
|
@@ -1744,15 +1823,15 @@ end",
|
|
1744
1823
|
[:lasgn, :c,
|
1745
1824
|
[:call, [:lvar, :s], :new, [:array, [:nil]]]],
|
1746
1825
|
|
1747
|
-
[:op_asgn2, [:lvar, :c], :var=, "||"
|
1826
|
+
[:op_asgn2, [:lvar, :c], :var=, :"||",
|
1748
1827
|
[:lit, 20]],
|
1749
|
-
[:op_asgn2, [:lvar, :c], :var=, "&&"
|
1828
|
+
[:op_asgn2, [:lvar, :c], :var=, :"&&",
|
1750
1829
|
[:lit, 21]],
|
1751
1830
|
[:op_asgn2, [:lvar, :c], :var=, :+, [:lit, 22]],
|
1752
1831
|
|
1753
1832
|
[:op_asgn2,
|
1754
1833
|
[:call,
|
1755
|
-
[:call, [:lvar, :c], :d], :e], :f=, "||"
|
1834
|
+
[:call, [:lvar, :c], :d], :e], :f=, :"||",
|
1756
1835
|
[:lit, 42]]],
|
1757
1836
|
},
|
1758
1837
|
|
@@ -1841,12 +1920,33 @@ end",
|
|
1841
1920
|
"Ruby2Ruby" => "((a or b) or (c and d))",
|
1842
1921
|
},
|
1843
1922
|
|
1923
|
+
"parse_floats_as_args" => {
|
1924
|
+
"Ruby" => "def x(a=0.0,b=0.0)\n a+b\nend",
|
1925
|
+
"ParseTree" => [:defn, :x,
|
1926
|
+
[:scope,
|
1927
|
+
[:block,
|
1928
|
+
[:args, :a, :b,
|
1929
|
+
[:block,
|
1930
|
+
[:lasgn, :a, [:lit, 0.0]],
|
1931
|
+
[:lasgn, :b, [:lit, 0.0]]]],
|
1932
|
+
[:call, [:lvar, :a], :+, [:array, [:lvar, :b]]]]]],
|
1933
|
+
"Ruby2Ruby" => "def x(a = 0.0, b = 0.0)\n (a + b)\nend",
|
1934
|
+
},
|
1935
|
+
|
1844
1936
|
"postexe" => {
|
1845
1937
|
"Ruby" => "END { 1 }",
|
1846
1938
|
"ParseTree" => [:iter, [:postexe], nil, [:lit, 1]],
|
1847
1939
|
},
|
1848
1940
|
|
1849
|
-
"
|
1941
|
+
"proc_args_0" => {
|
1942
|
+
"Ruby" => "proc { || (x + 1) }",
|
1943
|
+
"ParseTree" => [:iter,
|
1944
|
+
[:fcall, :proc],
|
1945
|
+
0,
|
1946
|
+
[:call, [:vcall, :x], :+, [:array, [:lit, 1]]]],
|
1947
|
+
},
|
1948
|
+
|
1949
|
+
"proc_args_1" => {
|
1850
1950
|
"Ruby" => "proc { |x| (x + 1) }",
|
1851
1951
|
"ParseTree" => [:iter,
|
1852
1952
|
[:fcall, :proc],
|
@@ -1854,19 +1954,19 @@ end",
|
|
1854
1954
|
[:call, [:dvar, :x], :+, [:array, [:lit, 1]]]],
|
1855
1955
|
},
|
1856
1956
|
|
1857
|
-
"
|
1858
|
-
"Ruby" => "proc { (x +
|
1957
|
+
"proc_args_2" => {
|
1958
|
+
"Ruby" => "proc { |x, y| (x + y) }",
|
1859
1959
|
"ParseTree" => [:iter,
|
1860
1960
|
[:fcall, :proc],
|
1861
|
-
|
1862
|
-
[:call, [:
|
1961
|
+
[:masgn, [:array, [:dasgn_curr, :x], [:dasgn_curr, :y]]],
|
1962
|
+
[:call, [:dvar, :x], :+, [:array, [:dvar, :y]]]],
|
1863
1963
|
},
|
1864
1964
|
|
1865
|
-
"
|
1866
|
-
"Ruby" => "proc {
|
1965
|
+
"proc_args_no" => {
|
1966
|
+
"Ruby" => "proc { (x + 1) }",
|
1867
1967
|
"ParseTree" => [:iter,
|
1868
1968
|
[:fcall, :proc],
|
1869
|
-
|
1969
|
+
nil,
|
1870
1970
|
[:call, [:vcall, :x], :+, [:array, [:lit, 1]]]],
|
1871
1971
|
},
|
1872
1972
|
|
@@ -1971,19 +2071,19 @@ end",
|
|
1971
2071
|
},
|
1972
2072
|
|
1973
2073
|
"str_heredoc" => {
|
1974
|
-
"Ruby" => "<<'EOM'\n blah\nblah\nEOM
|
2074
|
+
"Ruby" => "<<'EOM'\n blah\nblah\nEOM",
|
1975
2075
|
"ParseTree" => [:str, " blah\nblah\n"],
|
1976
2076
|
"Ruby2Ruby" => "\" blah\\nblah\\n\"",
|
1977
2077
|
},
|
1978
2078
|
|
1979
2079
|
"str_heredoc_call" => {
|
1980
|
-
"Ruby" => "<<'EOM'.strip\n blah\nblah\nEOM
|
2080
|
+
"Ruby" => "<<'EOM'.strip\n blah\nblah\nEOM",
|
1981
2081
|
"ParseTree" => [:call, [:str, " blah\nblah\n"], :strip],
|
1982
2082
|
"Ruby2Ruby" => "\" blah\\nblah\\n\".strip",
|
1983
2083
|
},
|
1984
2084
|
|
1985
2085
|
"str_heredoc_double" => {
|
1986
|
-
"Ruby" => "a += <<-
|
2086
|
+
"Ruby" => "a += <<-H1 + b + <<-H2\n first\nH1\n second\nH2",
|
1987
2087
|
"ParseTree" => [:lasgn, :a,
|
1988
2088
|
[:call,
|
1989
2089
|
[:lvar, :a],
|
@@ -1997,29 +2097,12 @@ end",
|
|
1997
2097
|
"Ruby2Ruby" => "a = (a + ((\" first\\n\" + b) + \" second\\n\"))",
|
1998
2098
|
},
|
1999
2099
|
|
2000
|
-
"dstr_heredoc_expand" => {
|
2001
|
-
"Ruby" => "<<EOM\n blah\n#\{1 + 1}blah\nEOM\n",
|
2002
|
-
"ParseTree" => [:dstr, " blah\n",
|
2003
|
-
[:evstr, [:call, [:lit, 1], :+, [:array, [:lit, 1]]]],
|
2004
|
-
[:str, "blah\n"]],
|
2005
|
-
"Ruby2Ruby" => "\" blah\\n#\{(1 + 1)}blah\\n\"",
|
2006
|
-
},
|
2007
|
-
|
2008
2100
|
"str_heredoc_indent" => {
|
2009
|
-
"Ruby" => "<<-EOM\n blah\nblah\n\n EOM
|
2101
|
+
"Ruby" => "<<-EOM\n blah\nblah\n\n EOM",
|
2010
2102
|
"ParseTree" => [:str, " blah\nblah\n\n"],
|
2011
2103
|
"Ruby2Ruby" => "\" blah\\nblah\\n\\n\"",
|
2012
2104
|
},
|
2013
2105
|
|
2014
|
-
"dstr_heredoc_windoze_sucks" => {
|
2015
|
-
"Ruby" => "<<-EOF\r\ndef test_#\{action}_valid_feed\r\n EOF\r\n",
|
2016
|
-
"ParseTree" => [:dstr,
|
2017
|
-
'def test_',
|
2018
|
-
[:evstr, [:vcall, :action]],
|
2019
|
-
[:str, "_valid_feed\n"]],
|
2020
|
-
"Ruby2Ruby" => "\"def test_#\{action}_valid_feed\\n\"",
|
2021
|
-
},
|
2022
|
-
|
2023
2106
|
"str_interp_file" => {
|
2024
2107
|
"Ruby" => '"file = #{__FILE__}
|
2025
2108
|
"',
|
@@ -2028,21 +2111,19 @@ end",
|
|
2028
2111
|
},
|
2029
2112
|
|
2030
2113
|
"structure_extra_block_for_dvar_scoping" => {
|
2031
|
-
"Ruby" => "a.b do |c, d|\n unless e.f(c) then\n g = false\n d.h { |x, i| g = true }\n
|
2114
|
+
"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", # FIX: don't like the extra return
|
2032
2115
|
"ParseTree" => [:iter,
|
2033
2116
|
[:call, [:vcall, :a], :b],
|
2034
2117
|
[:masgn, [:array, [:dasgn_curr, :c], [:dasgn_curr, :d]]],
|
2035
|
-
[:
|
2036
|
-
[:
|
2037
|
-
|
2038
|
-
|
2039
|
-
|
2040
|
-
[:
|
2041
|
-
[:
|
2042
|
-
[:
|
2043
|
-
|
2044
|
-
[:masgn, [:array, [:dasgn_curr, :x], [:dasgn_curr, :i]]],
|
2045
|
-
[:dasgn, :g, [:true]]]]]]],
|
2118
|
+
[:if,
|
2119
|
+
[:call, [:vcall, :e], :f, [:array, [:dvar, :c]]],
|
2120
|
+
nil,
|
2121
|
+
[:block,
|
2122
|
+
[:dasgn_curr, :g, [:false]],
|
2123
|
+
[:iter,
|
2124
|
+
[:call, [:dvar, :d], :h],
|
2125
|
+
[:masgn, [:array, [:dasgn_curr, :x], [:dasgn_curr, :i]]],
|
2126
|
+
[:dasgn, :g, [:true]]]]]],
|
2046
2127
|
},
|
2047
2128
|
|
2048
2129
|
"structure_remove_begin_1" => {
|
@@ -2331,6 +2412,8 @@ end",
|
|
2331
2412
|
end
|
2332
2413
|
|
2333
2414
|
def self.inherited(c)
|
2415
|
+
super
|
2416
|
+
|
2334
2417
|
output_name = c.name.to_s.sub(/^Test/, '')
|
2335
2418
|
raise "Unknown class #{c} in @@testcase_order" unless
|
2336
2419
|
@@testcase_order.include? output_name
|
@@ -2341,13 +2424,14 @@ end",
|
|
2341
2424
|
next if [:skip, :unsupported].include? data[input_name]
|
2342
2425
|
next if data[output_name] == :skip
|
2343
2426
|
|
2344
|
-
c.send(:define_method, "test_#{node}"
|
2427
|
+
c.send(:define_method, :"test_#{node}") do
|
2345
2428
|
flunk "Processor is nil" if processor.nil?
|
2346
2429
|
assert data.has_key?(input_name), "Unknown input data"
|
2347
2430
|
unless data.has_key?(output_name) then
|
2348
2431
|
$stderr.puts "add_test(#{node.inspect}, :same)"
|
2349
2432
|
end
|
2350
|
-
assert
|
2433
|
+
assert(data.has_key?(output_name),
|
2434
|
+
"Missing test data: #{self.class} #{node}")
|
2351
2435
|
input = data[input_name].deep_clone
|
2352
2436
|
|
2353
2437
|
expected = if data[output_name] == :same then
|
@@ -2365,14 +2449,17 @@ end",
|
|
2365
2449
|
extra_expected = []
|
2366
2450
|
extra_input = []
|
2367
2451
|
|
2368
|
-
_, expected, extra_expected = *expected if
|
2369
|
-
|
2452
|
+
_, expected, extra_expected = *expected if
|
2453
|
+
Array === expected and expected.first == :defx
|
2454
|
+
_, input, extra_input = *input if
|
2455
|
+
Array === input and input.first == :defx
|
2370
2456
|
|
2371
2457
|
debug = input.deep_clone
|
2372
|
-
|
2373
|
-
|
2374
|
-
|
2375
|
-
|
2458
|
+
assert_equal(expected, processor.process(input),
|
2459
|
+
"failed on input: #{debug.inspect}")
|
2460
|
+
extra_input.each do |extra|
|
2461
|
+
processor.process(extra)
|
2462
|
+
end
|
2376
2463
|
extra = processor.extra_methods rescue []
|
2377
2464
|
assert_equal extra_expected, extra
|
2378
2465
|
end
|