jruby-parser 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/jruby-parser.jar +0 -0
- data/lib/jruby-parser/util/coercer.rb +22 -16
- data/lib/jruby-parser/version.rb +1 -1
- data/spec/ast/node/array_spec.rb +24 -0
- data/spec/ast/node/break_spec.rb +19 -0
- data/spec/ast/node/comments_spec.rb +59 -0
- data/spec/{jruby-parser → ast/node}/find_scopes_spec.rb +4 -7
- data/spec/ast/node/get_declaration_spec.rb +50 -0
- data/spec/ast/node/get_defined_scope_spec.rb +89 -0
- data/spec/{jruby-parser → ast/node}/get_node_at_spec.rb +3 -7
- data/spec/ast/node/get_occurences_spec.rb +87 -0
- data/spec/{jruby-parser → ast/node}/is_block_parameter_spec.rb +4 -8
- data/spec/{jruby-parser → ast/node}/is_method_parameter_spec.rb +4 -8
- data/spec/ast/node/next_spec.rb +19 -0
- data/spec/ast/node/op_element_asgn_and_spec.rb +11 -0
- data/spec/ast/node/op_element_asgn_or_spec.rb +11 -0
- data/spec/ast/node/op_element_asgn_spec.rb +11 -0
- data/spec/ast/node/return_spec.rb +19 -0
- data/spec/ast/node_path.rb +1 -5
- data/spec/helpers.rb +4 -0
- data/spec/helpers/node_helpers.rb +17 -6
- data/spec/helpers/parser_helpers.rb +84 -8
- data/spec/jruby-parser/find_spec.rb +2 -6
- data/spec/jruby-parser/parse_spec.rb +17 -0
- data/spec/jruby-parser/rewriting_spec.rb +27 -12
- data/spec/jruby-parser/static_analysis_spec.rb +51 -48
- data/spec/parser/alias_spec.rb +2 -6
- data/spec/parser/broken_spec.rb +2 -6
- data/spec/parser/calls_spec.rb +100 -0
- data/spec/positions/alias_spec.rb +23 -0
- data/spec/positions/arg_spec.rb +2 -6
- data/spec/positions/attr_asgn_spec.rb +2 -6
- data/spec/positions/call_spec.rb +2 -10
- data/spec/positions/conditionals_spec.rb +2 -6
- data/spec/positions/hash_spec.rb +2 -6
- data/spec/positions/heredoc_spec.rb +2 -6
- data/spec/positions/name_spec.rb +56 -0
- data/spec/positions/op_asgn_or_spec.rb +15 -0
- data/spec/positions/str_spec.rb +2 -6
- metadata +51 -21
@@ -1,11 +1,7 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + "/../helpers"
|
3
|
-
require 'java'
|
4
|
-
require 'jruby-parser'
|
5
|
-
require 'parser_helpers'
|
1
|
+
require_relative '../../helpers'
|
6
2
|
|
7
|
-
describe
|
8
|
-
|
3
|
+
describe org.jrubyparser.ast.Node do
|
4
|
+
VERSIONS.each do |v|
|
9
5
|
it "finds parameter via is_block_parameter [#{v}]" do
|
10
6
|
caret_parse("proc { |^a| }", v).tap do |root, caret_node|
|
11
7
|
caret_node.block_parameter?.should == true
|
@@ -23,7 +19,7 @@ describe JRubyParser do
|
|
23
19
|
caret_node.block_parameter?.should == true
|
24
20
|
end
|
25
21
|
|
26
|
-
if v
|
22
|
+
if v != 1.8
|
27
23
|
caret_parse("proc { |a, ^b=1| }", v).tap do |root, caret_node|
|
28
24
|
caret_node.block_parameter?.should == true
|
29
25
|
end
|
@@ -1,11 +1,7 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + "/../helpers"
|
3
|
-
require 'java'
|
4
|
-
require 'jruby-parser'
|
5
|
-
require 'parser_helpers'
|
1
|
+
require_relative '../../helpers'
|
6
2
|
|
7
|
-
describe
|
8
|
-
|
3
|
+
describe org.jrubyparser.ast.Node do
|
4
|
+
VERSIONS.each do |v|
|
9
5
|
it "finds parameter via is_method_parameter [#{v}]" do
|
10
6
|
caret_parse("def foo(^a); end", v).tap do |root, caret_node|
|
11
7
|
caret_node.method_parameter?.should == true
|
@@ -22,7 +18,7 @@ describe JRubyParser do
|
|
22
18
|
caret_parse("def foo(a, ^b=1); end", v).tap do |root, caret_node|
|
23
19
|
caret_node.method_parameter?.should == true
|
24
20
|
end
|
25
|
-
if v
|
21
|
+
if v != 1.8
|
26
22
|
caret_parse("def foo(a, (b, ^c)); end", v).tap do |root, caret_node|
|
27
23
|
caret_node.method_parameter?.should == true
|
28
24
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../../helpers'
|
2
|
+
|
3
|
+
describe org.jrubyparser.ast.NextNode do
|
4
|
+
VERSIONS.each do |v|
|
5
|
+
it "can accept a single value [#{v}]" do
|
6
|
+
rparse("next true", v).find_node(:next).tap do |b|
|
7
|
+
b.should have_position(0, 0, 0, 9)
|
8
|
+
b.value_node.class.should == org.jrubyparser.ast.TrueNode
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "can accept no value [#{v}]" do
|
13
|
+
rparse("next", v).find_node(:next).tap do |b|
|
14
|
+
b.should have_position(0, 0, 0, 4)
|
15
|
+
b.value_node.should == nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require_relative '../../helpers'
|
2
|
+
|
3
|
+
describe org.jrubyparser.ast.OpElementAsgnAndNode do
|
4
|
+
VERSIONS.each do |v|
|
5
|
+
it "can parse simple expr [#{v}]" do
|
6
|
+
parse("a[1] &&= 2", v).find_node(:opelementasgnand).tap do |op|
|
7
|
+
op.should have_position(0, 0, 0, 10)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require_relative '../../helpers'
|
2
|
+
|
3
|
+
describe org.jrubyparser.ast.OpElementAsgnOrNode do
|
4
|
+
VERSIONS.each do |v|
|
5
|
+
it "can parse simple expr [#{v}]" do
|
6
|
+
parse("a[1] ||= 2", v).find_node(:opelementasgnor).tap do |op|
|
7
|
+
op.should have_position(0, 0, 0, 10)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require_relative '../../helpers'
|
2
|
+
|
3
|
+
describe org.jrubyparser.ast.OpElementAsgnNode do
|
4
|
+
VERSIONS.each do |v|
|
5
|
+
it "can parse simple expr [#{v}]" do
|
6
|
+
parse("a[1] += 2", v).find_node(:opelementasgn).tap do |op|
|
7
|
+
op.should have_position(0, 0, 0, 9)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../../helpers'
|
2
|
+
|
3
|
+
describe org.jrubyparser.ast.ReturnNode do
|
4
|
+
VERSIONS.each do |v|
|
5
|
+
it "can accept a single value [#{v}]" do
|
6
|
+
rparse("return true", v).find_node(:return).tap do |b|
|
7
|
+
b.should have_position(0, 0, 0, 11)
|
8
|
+
b.value_node.class.should == org.jrubyparser.ast.TrueNode
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "can accept no value [#{v}]" do
|
13
|
+
rparse("return", v).find_node(:return).tap do |b|
|
14
|
+
b.should have_position(0, 0, 0, 6)
|
15
|
+
b.value_node.should == nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/ast/node_path.rb
CHANGED
@@ -1,8 +1,4 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + "/../../lib"
|
3
|
-
require 'jruby-parser'
|
4
|
-
require 'parser_helpers'
|
5
|
-
require 'node_helpers'
|
1
|
+
require_relative '../../helpers'
|
6
2
|
|
7
3
|
describe Parser do
|
8
4
|
it "should parse alias with quotationmarks" do
|
data/spec/helpers.rb
ADDED
@@ -12,27 +12,37 @@ end
|
|
12
12
|
###########
|
13
13
|
|
14
14
|
class AstPositionMatcher
|
15
|
-
def initialize(*args)
|
16
|
-
@position = args
|
15
|
+
def initialize(method, *args)
|
16
|
+
@method, @position = method, args
|
17
|
+
end
|
18
|
+
|
19
|
+
def position
|
20
|
+
@actual.__send__(@method).to_a
|
17
21
|
end
|
18
22
|
|
19
23
|
def matches?(actual)
|
20
24
|
@actual = actual
|
21
|
-
|
25
|
+
position == @position
|
22
26
|
end
|
23
27
|
|
24
28
|
def failure_message
|
25
|
-
return %[expected #{
|
29
|
+
return %[expected #{position.inspect} to have position #{@position.inspect}]
|
26
30
|
end
|
27
31
|
|
28
32
|
def negative_failure_message
|
29
|
-
return %[expected #{
|
33
|
+
return %[expected #{position.inspect} to not have position #{@position.inspect}]
|
30
34
|
end
|
31
35
|
end
|
32
36
|
|
33
37
|
module HavePosition
|
34
38
|
def have_position(*args)
|
35
|
-
AstPositionMatcher.new(*args)
|
39
|
+
AstPositionMatcher.new(:position, *args)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module HaveNamePosition
|
44
|
+
def have_name_position(*args)
|
45
|
+
AstPositionMatcher.new(:name_position, *args)
|
36
46
|
end
|
37
47
|
end
|
38
48
|
|
@@ -224,6 +234,7 @@ end
|
|
224
234
|
#module Spec::Example::ExampleMethods
|
225
235
|
class Object
|
226
236
|
include HavePosition
|
237
|
+
include HaveNamePosition
|
227
238
|
include HaveName
|
228
239
|
include HaveNameAndPosition
|
229
240
|
include HaveArgCounts
|
@@ -1,13 +1,23 @@
|
|
1
1
|
require 'java'
|
2
2
|
|
3
3
|
import java.io.StringReader
|
4
|
+
import org.jrubyparser.CompatVersion
|
4
5
|
import org.jrubyparser.Parser
|
6
|
+
import org.jrubyparser.LocalStaticScope
|
5
7
|
import org.jrubyparser.parser.ParserConfiguration
|
6
|
-
import org.jrubyparser.CompatVersion
|
7
8
|
|
8
9
|
PARSER = Parser.new
|
9
|
-
|
10
|
-
|
10
|
+
VERSIONS_MAP = {
|
11
|
+
1.8 => CompatVersion::RUBY1_8,
|
12
|
+
1.9 => CompatVersion::RUBY1_9,
|
13
|
+
2.0 => CompatVersion::RUBY2_0
|
14
|
+
}
|
15
|
+
VERSIONS = [1.8, 1.9, 2.0]
|
16
|
+
|
17
|
+
SYNTAX_MAP = {
|
18
|
+
nil => ParserConfiguration::SyntaxGathering::NONE,
|
19
|
+
:all => ParserConfiguration::SyntaxGathering::ALL
|
20
|
+
}
|
11
21
|
|
12
22
|
class Object
|
13
23
|
# Wrap the code in what the JRubyParser expects
|
@@ -15,10 +25,53 @@ class Object
|
|
15
25
|
StringReader.new code.to_s
|
16
26
|
end
|
17
27
|
|
28
|
+
def config(version, scope=nil, syntax=nil)
|
29
|
+
ParserConfiguration.new(0, VERSIONS_MAP[version], scope).tap do |c|
|
30
|
+
c.syntax = SYNTAX_MAP[syntax]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Create a static scope that we can pass to the parser that has
|
35
|
+
# defined all strings local var names defined within it.
|
36
|
+
def scope(*vars)
|
37
|
+
position = org.jrubyparser.SourcePosition.new("(eval)", 0, 0)
|
38
|
+
LocalStaticScope.new(nil).tap do |scope|
|
39
|
+
vars.each { |e| scope.assign(position, e, nil) }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
18
43
|
# Parse the provided code into an AST
|
19
|
-
def parse(code, version=1.8)
|
20
|
-
|
21
|
-
|
44
|
+
def parse(code, version=1.8, scope=nil)
|
45
|
+
PARSER.parse "<code>", source(code), config(version, scope)
|
46
|
+
end
|
47
|
+
|
48
|
+
# def node_value(node)
|
49
|
+
# name = node.getClass.name
|
50
|
+
|
51
|
+
# value = node.value if node.respond_to?(:value)
|
52
|
+
# value = node.name if node.respond_to?(:name)
|
53
|
+
|
54
|
+
# name + (value ? ("(" + value.to_s + ")" ) : "")
|
55
|
+
# end
|
56
|
+
|
57
|
+
# def node_position(node)
|
58
|
+
# node.position
|
59
|
+
# end
|
60
|
+
|
61
|
+
# def display(node, indent="")
|
62
|
+
# puts "#{indent}#{node_value(node)}: #{node_position(node)}"
|
63
|
+
# node.child_nodes.each do |child|
|
64
|
+
# display(child, indent + " ")
|
65
|
+
# end
|
66
|
+
# end
|
67
|
+
|
68
|
+
|
69
|
+
# Parse the provided code into an AST with full syntax collection.
|
70
|
+
# The 'r' is for rewriting...
|
71
|
+
def rparse(code, version=1.8, scope=nil)
|
72
|
+
root = PARSER.parse "<code>", source(code), config(version, scope, :all)
|
73
|
+
# display(root)
|
74
|
+
root
|
22
75
|
end
|
23
76
|
|
24
77
|
##
|
@@ -26,11 +79,34 @@ class Object
|
|
26
79
|
# that offset represents. If you are testing source which contains
|
27
80
|
# a caret already you can substitute the value with a delimeter which
|
28
81
|
# will work.
|
29
|
-
def caret_parse(code, version=1.8, caret='^')
|
82
|
+
def caret_parse(code, version=1.8, caret='^', scope=nil)
|
30
83
|
caret_index = code.index(caret)
|
31
84
|
raise ArgumentError.new("Caret '^' missing: #{code}") unless caret_index
|
32
85
|
|
33
|
-
root = parse
|
86
|
+
root = parse code.sub(caret, ''), version, scope
|
34
87
|
[root, root.node_at(caret_index)]
|
35
88
|
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# parse code but record all '^' found in source and return a list of all
|
92
|
+
# nodes found at those carets.
|
93
|
+
def carets_parse(code, version=1.8, caret='^', scope=nil)
|
94
|
+
deloused_code, caret_indices = remove_carets(code, caret)
|
95
|
+
root = parse deloused_code, version, scope
|
96
|
+
[root, caret_indices.map { |e| root.node_at(e)}]
|
97
|
+
end
|
98
|
+
|
99
|
+
# Pretty naive impl :)
|
100
|
+
def remove_carets(code, caret)
|
101
|
+
indices = []
|
102
|
+
index = code.index(caret)
|
103
|
+
|
104
|
+
while index
|
105
|
+
indices << index
|
106
|
+
code.sub!(caret, '')
|
107
|
+
index = code.index(caret)
|
108
|
+
end
|
109
|
+
|
110
|
+
[code, indices]
|
111
|
+
end
|
36
112
|
end
|
@@ -1,11 +1,7 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + "/../helpers"
|
3
|
-
require 'java'
|
4
|
-
require 'jruby-parser'
|
5
|
-
require 'parser_helpers'
|
1
|
+
require_relative '../helpers'
|
6
2
|
|
7
3
|
describe JRubyParser do
|
8
|
-
|
4
|
+
VERSIONS.each do |v|
|
9
5
|
it "finds fcall via simple symbol search [#{v}]" do
|
10
6
|
parse("b = foo(1)").tap do |root|
|
11
7
|
fcall = root.find_type(:fcall)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative '../helpers'
|
2
|
+
|
3
|
+
describe JRubyParser do
|
4
|
+
VERSIONS.each do |v|
|
5
|
+
it "passes in a static scope with defined var [#{v}]" do
|
6
|
+
parse("b = a", v, scope('a')).tap do |root|
|
7
|
+
root.find_type(:localvar).should_not == nil # a
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "parses hash literal with trailing = at end of key name" do
|
12
|
+
parse("{:a==>1}").tap do |root|
|
13
|
+
root.find_type(:symbol).name.should == "a="
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,10 +1,9 @@
|
|
1
|
-
|
2
|
-
require 'jruby-parser'
|
1
|
+
require_relative '../helpers'
|
3
2
|
|
4
3
|
describe JRubyParser do
|
5
|
-
|
4
|
+
VERSIONS.each do |v|
|
6
5
|
it "rewrites method name from foo to bar [#{v}]" do
|
7
|
-
|
6
|
+
rparse("b = foo(1)").tap do |root|
|
8
7
|
fcall = root.find_node(:fcall)
|
9
8
|
fcall.name = 'bar'
|
10
9
|
end.to_source.should == "b = bar(1)"
|
@@ -15,14 +14,14 @@ describe JRubyParser do
|
|
15
14
|
end.to_source.should == "b = bar 1"
|
16
15
|
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
17
|
+
it "rewrites between different coercible ruby types [#{v}]" do
|
18
|
+
[1, 1.0, true, false, nil, "a"].each do |replace|
|
19
|
+
parse("foo 1").tap do |root|
|
20
|
+
fcall = root.find_node(:fcall)
|
21
|
+
fcall.args[0] = replace
|
22
|
+
end.to_source.should == "foo #{replace.inspect}"
|
23
|
+
end
|
24
|
+
end
|
26
25
|
|
27
26
|
it "rewrites receiver of a call [#{v}]" do
|
28
27
|
parse("1.to_f(1)").tap do |root|
|
@@ -53,5 +52,21 @@ describe JRubyParser do
|
|
53
52
|
op.value = 3
|
54
53
|
end.to_source.should == "1[2] += 3"
|
55
54
|
end
|
55
|
+
|
56
|
+
it "rewrites an alias of barewords [#{v}]" do
|
57
|
+
parse("alias foo bar").to_source.should == "alias foo bar"
|
58
|
+
end
|
59
|
+
|
60
|
+
if v != 1.8
|
61
|
+
it "rewrites stabby lambda [#{v}]" do
|
62
|
+
str = "->(a) {puts a}"
|
63
|
+
parse(str, v).to_source.should == str
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# it "rewrites a comment on first line [#{v}]" do
|
68
|
+
# code = "# comment 1\nfoo(1)\n"
|
69
|
+
# rparse(code).to_source.should == code
|
70
|
+
# end
|
56
71
|
end
|
57
72
|
end
|
@@ -1,66 +1,69 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + "/../../lib"
|
3
|
-
require 'jruby-parser'
|
4
|
-
require 'parser_helpers'
|
5
|
-
require 'node_helpers'
|
1
|
+
require_relative '../helpers'
|
6
2
|
|
7
3
|
describe Parser do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
VERSIONS.each do |v|
|
5
|
+
if v == 2.0
|
6
|
+
it "test 2.0" do
|
7
|
+
parse("def foo(a:1); p a; end", v)
|
12
8
|
end
|
13
9
|
end
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
parse("a,b,*c = 1,2,3,4", v).find_node(:multipleasgn19).tap do |masgn|
|
20
|
-
masgn.should have_static_assignments([[:a, 1], [:b, 2], [:c, [3,4]]])
|
10
|
+
if v != 1.8
|
11
|
+
it "parses a simple multiple assignment [#{v}]" do
|
12
|
+
parse("a,b,c = 1,2,3", v).find_node(:multipleasgn).tap do |masgn|
|
13
|
+
masgn.should have_static_assignments([[:a, 1], [:b, 2], [:c, 3]])
|
14
|
+
end
|
21
15
|
end
|
22
|
-
end
|
23
16
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
17
|
+
it "parses a simple lhs splat multiple assignment [#{v}]" do
|
18
|
+
parse("a,*b = 1,2,3", v).find_node(:multipleasgn).tap do |masgn|
|
19
|
+
masgn.should have_static_assignments([[:a, 1], [:b, [2, 3]]])
|
20
|
+
end
|
21
|
+
parse("a,b,*c = 1,2,3,4", v).find_node(:multipleasgn).tap do |masgn|
|
22
|
+
masgn.should have_static_assignments([[:a, 1], [:b, 2], [:c, [3,4]]])
|
23
|
+
end
|
30
24
|
end
|
31
|
-
end
|
32
25
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
26
|
+
it "parses a simple lhs splat multiple assignment [#{v}]" do
|
27
|
+
parse("*a,b = 1,2,3", v).find_node(:multipleasgn).tap do |masgn|
|
28
|
+
masgn.should have_static_assignments([[:a, [1, 2]], [:b, 3]])
|
29
|
+
end
|
30
|
+
parse("*a,b,c = 1,2,3,4", v).find_node(:multipleasgn).tap do |masgn|
|
31
|
+
masgn.should have_static_assignments([[:a, [1, 2]], [:b, 3], [:c, 4]])
|
32
|
+
end
|
39
33
|
end
|
40
|
-
|
41
|
-
|
34
|
+
|
35
|
+
it "parses a simple lhs splat multiple assignment [#{v}]" do
|
36
|
+
parse("a,*b, c = 1,2,3,4", v).find_node(:multipleasgn).tap do |masgn|
|
37
|
+
masgn.should have_static_assignments([[:a, 1], [:b, [2, 3]], [:c, 4]])
|
38
|
+
end
|
39
|
+
parse("a, b, *c, d = 1,2,3,4,5", v).find_node(:multipleasgn).tap do |masgn|
|
40
|
+
masgn.should have_static_assignments([[:a, 1], [:b, 2], [:c, [3, 4]], [:d, 5]])
|
41
|
+
end
|
42
|
+
parse("a, *b, c, d = 1,2,3,4,5", v).find_node(:multipleasgn).tap do |masgn|
|
43
|
+
masgn.should have_static_assignments([[:a, 1], [:b, [2, 3]], [:c, 4], [:d, 5]])
|
44
|
+
end
|
42
45
|
end
|
43
|
-
end
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
|
47
|
+
it "parses a simple lhs splat multiple assignment [#{v}]" do
|
48
|
+
parse("a,*b,c,d = 1,2,3", v).find_node(:multipleasgn).tap do |masgn|
|
49
|
+
masgn.should have_static_assignments([[:a, 1], [:b, []], [:c, 2], [:d, 3]])
|
50
|
+
end
|
48
51
|
end
|
49
|
-
end
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
it "parses a simple rhs splat multiple assignment [#{v}]" do
|
54
|
+
ast = parse("a,*b = 1,*foo", v)
|
55
|
+
foo = ast.find_node(:vcall)
|
56
|
+
ast.find_node(:multipleasgn).tap do |masgn|
|
57
|
+
masgn.should have_static_assignments([[:a, 1], [:b, foo]])
|
58
|
+
end
|
56
59
|
end
|
57
|
-
end
|
58
60
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
it "parses a simple rhs splat multiple assignment [#{v}]" do
|
62
|
+
ast = parse("*a,b = *foo,1", v)
|
63
|
+
splatted_foo = ast.find_node(:splat)
|
64
|
+
ast.find_node(:multipleasgn).tap do |masgn|
|
65
|
+
masgn.should have_static_assignments([[:a, splatted_foo], [:b, 1]])
|
66
|
+
end
|
64
67
|
end
|
65
68
|
end
|
66
69
|
|