ripper_ruby_parser 1.1.1 → 1.1.2
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 +4 -4
- data/CHANGELOG.md +19 -0
- data/Rakefile +2 -2
- data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +55 -4
- data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +20 -13
- data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +27 -12
- data/lib/ripper_ruby_parser/sexp_handlers/hashes.rb +25 -12
- data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +4 -2
- data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +19 -15
- data/lib/ripper_ruby_parser/sexp_handlers/loops.rb +25 -11
- data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +12 -4
- data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +8 -4
- data/lib/ripper_ruby_parser/sexp_handlers/operators.rb +1 -5
- data/lib/ripper_ruby_parser/version.rb +1 -1
- data/lib/ripper_ruby_parser.rb +2 -2
- data/test/end_to_end/comments_test.rb +4 -4
- data/test/end_to_end/comparison_test.rb +15 -15
- data/test/end_to_end/error_conditions_test.rb +16 -16
- data/test/end_to_end/lib_comparison_test.rb +3 -3
- data/test/end_to_end/line_numbering_test.rb +4 -4
- data/test/end_to_end/samples_comparison_test.rb +4 -4
- data/test/end_to_end/test_comparison_test.rb +3 -3
- data/test/pt_testcase/pt_test.rb +4 -4
- data/test/test_helper.rb +1 -1
- data/test/unit/commenting_ripper_parser_test.rb +33 -33
- data/test/unit/parser_assignment_test.rb +30 -30
- data/test/unit/parser_blocks_test.rb +83 -65
- data/test/unit/parser_conditionals_test.rb +96 -64
- data/test/unit/parser_literals_test.rb +308 -212
- data/test/unit/parser_loops_test.rb +85 -15
- data/test/unit/parser_method_calls_test.rb +100 -41
- data/test/unit/parser_operators_test.rb +60 -28
- data/test/unit/parser_test.rb +435 -410
- data/test/unit/sexp_processor_test.rb +82 -82
- data/test/unit/version_test.rb +1 -1
- metadata +2 -2
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
|
2
2
|
require 'ruby_parser'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe 'Using RipperRubyParser and RubyParser' do
|
5
5
|
let :newparser do
|
6
6
|
RipperRubyParser::Parser.new
|
7
7
|
end
|
@@ -10,12 +10,12 @@ describe "Using RipperRubyParser and RubyParser" do
|
|
10
10
|
RubyParser.new
|
11
11
|
end
|
12
12
|
|
13
|
-
describe
|
13
|
+
describe 'for a simple well known program' do
|
14
14
|
let :program do
|
15
15
|
"puts 'Hello World'"
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'gives the same result' do
|
19
19
|
original = oldparser.parse program
|
20
20
|
imitation = newparser.parse program
|
21
21
|
|
@@ -23,7 +23,7 @@ describe "Using RipperRubyParser and RubyParser" do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
describe
|
26
|
+
describe 'for a more complex program' do
|
27
27
|
let :program do
|
28
28
|
<<-END
|
29
29
|
module Quux
|
@@ -44,7 +44,7 @@ describe "Using RipperRubyParser and RubyParser" do
|
|
44
44
|
END
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
47
|
+
it 'gives the same result' do
|
48
48
|
original = oldparser.parse program
|
49
49
|
imitation = newparser.parse program
|
50
50
|
|
@@ -52,12 +52,12 @@ describe "Using RipperRubyParser and RubyParser" do
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
describe
|
55
|
+
describe 'for an example with yield from Reek' do
|
56
56
|
let :program do
|
57
57
|
'def fred() yield(3) if block_given?; end'
|
58
58
|
end
|
59
59
|
|
60
|
-
it
|
60
|
+
it 'gives the same result' do
|
61
61
|
original = oldparser.parse program
|
62
62
|
imitation = newparser.parse program
|
63
63
|
|
@@ -65,7 +65,7 @@ describe "Using RipperRubyParser and RubyParser" do
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
describe
|
68
|
+
describe 'for an example with floats from Reek' do
|
69
69
|
let :program do
|
70
70
|
<<-END
|
71
71
|
def total_envy
|
@@ -78,7 +78,7 @@ describe "Using RipperRubyParser and RubyParser" do
|
|
78
78
|
END
|
79
79
|
end
|
80
80
|
|
81
|
-
it
|
81
|
+
it 'gives the same result' do
|
82
82
|
original = oldparser.parse program
|
83
83
|
imitation = newparser.parse program
|
84
84
|
|
@@ -86,7 +86,7 @@ describe "Using RipperRubyParser and RubyParser" do
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
-
describe
|
89
|
+
describe 'for an example with operators and explicit block parameter from Reek' do
|
90
90
|
let :program do
|
91
91
|
<<-END
|
92
92
|
def parse(arg, argv, &error)
|
@@ -105,7 +105,7 @@ describe "Using RipperRubyParser and RubyParser" do
|
|
105
105
|
END
|
106
106
|
end
|
107
107
|
|
108
|
-
it
|
108
|
+
it 'gives the same result' do
|
109
109
|
original = oldparser.parse program
|
110
110
|
imitation = newparser.parse program
|
111
111
|
|
@@ -113,12 +113,12 @@ describe "Using RipperRubyParser and RubyParser" do
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
-
describe
|
116
|
+
describe 'for an example of a complex regular expression from Reek' do
|
117
117
|
let :program do
|
118
118
|
"/(\#{@types})\\s*(\\w+)\\s*\\(([^)]*)\\)/"
|
119
119
|
end
|
120
120
|
|
121
|
-
it
|
121
|
+
it 'gives the same result' do
|
122
122
|
original = oldparser.parse program
|
123
123
|
imitation = newparser.parse program
|
124
124
|
|
@@ -126,8 +126,8 @@ describe "Using RipperRubyParser and RubyParser" do
|
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
|
-
describe
|
130
|
-
it
|
129
|
+
describe 'for an example with regular expressions with different encoding flags' do
|
130
|
+
it 'gives the same result' do
|
131
131
|
program = <<-END
|
132
132
|
regular = /foo/
|
133
133
|
noenc = /foo/n
|
@@ -1,50 +1,50 @@
|
|
1
1
|
require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
|
2
2
|
|
3
|
-
describe
|
4
|
-
describe
|
3
|
+
describe 'Handling errors' do
|
4
|
+
describe 'RipperRubyParser::Parser#parse' do
|
5
5
|
let :newparser do
|
6
6
|
RipperRubyParser::Parser.new
|
7
7
|
end
|
8
8
|
|
9
|
-
it
|
9
|
+
it 'raises an error for an incomplete source' do
|
10
10
|
proc {
|
11
|
-
newparser.parse
|
11
|
+
newparser.parse 'def foo'
|
12
12
|
}.must_raise RipperRubyParser::SyntaxError
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it 'raises an error for an invalid class name' do
|
16
16
|
proc {
|
17
|
-
newparser.parse(
|
17
|
+
newparser.parse('class foo; end')
|
18
18
|
}.must_raise RipperRubyParser::SyntaxError
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
21
|
+
it 'raises an error aliasing $1 as foo' do
|
22
22
|
proc {
|
23
|
-
newparser.parse
|
23
|
+
newparser.parse 'alias foo $1'
|
24
24
|
}.must_raise RipperRubyParser::SyntaxError
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
27
|
+
it 'raises an error aliasing foo as $1' do
|
28
28
|
proc {
|
29
|
-
newparser.parse
|
29
|
+
newparser.parse 'alias $1 foo'
|
30
30
|
}.must_raise RipperRubyParser::SyntaxError
|
31
31
|
end
|
32
32
|
|
33
|
-
it
|
33
|
+
it 'raises an error aliasing $2 as $1' do
|
34
34
|
proc {
|
35
|
-
newparser.parse
|
35
|
+
newparser.parse 'alias $1 $2'
|
36
36
|
}.must_raise RipperRubyParser::SyntaxError
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
39
|
+
it 'raises an error assigning to $1' do
|
40
40
|
proc {
|
41
|
-
newparser.parse
|
41
|
+
newparser.parse '$1 = foo'
|
42
42
|
}.must_raise RipperRubyParser::SyntaxError
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
45
|
+
it 'raises an error using an invalid parameter name' do
|
46
46
|
proc {
|
47
|
-
newparser.parse
|
47
|
+
newparser.parse 'def foo(BAR); end'
|
48
48
|
}.must_raise RipperRubyParser::SyntaxError
|
49
49
|
end
|
50
50
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
|
2
2
|
require 'ruby_parser'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe 'Using RipperRubyParser and RubyParser' do
|
5
5
|
let :newparser do
|
6
6
|
RipperRubyParser::Parser.new
|
7
7
|
end
|
@@ -10,13 +10,13 @@ describe "Using RipperRubyParser and RubyParser" do
|
|
10
10
|
RubyParser.new
|
11
11
|
end
|
12
12
|
|
13
|
-
Dir.glob(
|
13
|
+
Dir.glob('lib/**/*.rb').each do |file|
|
14
14
|
describe "for #{file}" do
|
15
15
|
let :program do
|
16
16
|
File.read file
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'gives the same result' do
|
20
20
|
original = oldparser.parse program
|
21
21
|
imitation = newparser.parse program
|
22
22
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
|
2
2
|
require 'ruby_parser'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe 'Using RipperRubyParser and RubyParser' do
|
5
5
|
def to_line_numbers exp
|
6
6
|
exp.map! do |sub_exp|
|
7
7
|
if sub_exp.is_a? Sexp
|
@@ -26,7 +26,7 @@ describe "Using RipperRubyParser and RubyParser" do
|
|
26
26
|
RubyParser.new
|
27
27
|
end
|
28
28
|
|
29
|
-
describe
|
29
|
+
describe 'for a multi-line program' do
|
30
30
|
let :program do
|
31
31
|
<<-END
|
32
32
|
class Foo
|
@@ -50,11 +50,11 @@ describe "Using RipperRubyParser and RubyParser" do
|
|
50
50
|
newparser.parse program
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
53
|
+
it 'gives the same result' do
|
54
54
|
imitation.must_equal original
|
55
55
|
end
|
56
56
|
|
57
|
-
it
|
57
|
+
it 'gives the same result with line numbers' do
|
58
58
|
formatted(to_line_numbers(imitation)).
|
59
59
|
must_equal formatted(to_line_numbers(original))
|
60
60
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
|
2
2
|
require 'ruby_parser'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe 'Using RipperRubyParser and RubyParser' do
|
5
5
|
let :newparser do
|
6
6
|
RipperRubyParser::Parser.new
|
7
7
|
end
|
@@ -10,7 +10,7 @@ describe "Using RipperRubyParser and RubyParser" do
|
|
10
10
|
RubyParser.new
|
11
11
|
end
|
12
12
|
|
13
|
-
Dir.glob(File.expand_path(
|
13
|
+
Dir.glob(File.expand_path('../samples/*.rb', File.dirname(__FILE__))).each do |file|
|
14
14
|
describe "for #{file}" do
|
15
15
|
let :program do
|
16
16
|
File.read file
|
@@ -25,11 +25,11 @@ describe "Using RipperRubyParser and RubyParser" do
|
|
25
25
|
newparser.parse program
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
28
|
+
it 'gives the same result' do
|
29
29
|
formatted(imitation).must_equal formatted(original)
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
32
|
+
it 'gives the same result with comments' do
|
33
33
|
formatted(to_comments(imitation)).
|
34
34
|
must_equal formatted(to_comments(original))
|
35
35
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
|
2
2
|
require 'ruby_parser'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe 'Using RipperRubyParser and RubyParser' do
|
5
5
|
let :newparser do
|
6
6
|
RipperRubyParser::Parser.new
|
7
7
|
end
|
@@ -10,13 +10,13 @@ describe "Using RipperRubyParser and RubyParser" do
|
|
10
10
|
RubyParser.new
|
11
11
|
end
|
12
12
|
|
13
|
-
Dir.glob(
|
13
|
+
Dir.glob('test/**/*.rb').each do |file|
|
14
14
|
describe "for #{file}" do
|
15
15
|
let :program do
|
16
16
|
File.read file
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'gives the same result' do
|
20
20
|
# Clone string because ruby_parser destroys it when there's a heredoc
|
21
21
|
# inside.
|
22
22
|
copy = program.clone
|
data/test/pt_testcase/pt_test.rb
CHANGED
@@ -7,17 +7,17 @@ class TestParser < RipperRubyParser::Parser
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
SKIPPED_TESTS = [
|
10
|
+
SKIPPED_TESTS = ['dstr_heredoc_windoze_sucks'].freeze
|
11
11
|
|
12
12
|
class RubyParserTestCase < ParseTreeTestCase
|
13
13
|
def self.previous _key
|
14
|
-
|
14
|
+
'Ruby'
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.generate_test klass, node, data, input_name, output_name
|
18
18
|
if data['Ruby'].is_a? Array
|
19
19
|
klass.send :define_method, "test_#{node}" do
|
20
|
-
skip
|
20
|
+
skip 'Not a parser test'
|
21
21
|
end
|
22
22
|
return
|
23
23
|
end
|
@@ -29,7 +29,7 @@ class RubyParserTestCase < ParseTreeTestCase
|
|
29
29
|
return
|
30
30
|
end
|
31
31
|
|
32
|
-
output_name =
|
32
|
+
output_name = 'ParseTree'
|
33
33
|
|
34
34
|
super
|
35
35
|
end
|
data/test/test_helper.rb
CHANGED
@@ -8,110 +8,110 @@ describe RipperRubyParser::CommentingRipperParser do
|
|
8
8
|
|
9
9
|
def empty_params_list
|
10
10
|
@empty_params_list ||= begin
|
11
|
-
num_params = RUBY_VERSION <
|
11
|
+
num_params = RUBY_VERSION < '2.0.0' ? 5 : 7
|
12
12
|
s(:params, *([nil] * num_params))
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
describe
|
17
|
-
it
|
16
|
+
describe 'handling comments' do
|
17
|
+
it 'produces a comment node surrounding a commented def' do
|
18
18
|
result = parse_with_builder "# Foo\ndef foo; end"
|
19
19
|
result.must_equal s(:program,
|
20
20
|
s(s(:comment,
|
21
21
|
"# Foo\n",
|
22
22
|
s(:def,
|
23
|
-
s(:@ident,
|
23
|
+
s(:@ident, 'foo', s(2, 4)),
|
24
24
|
empty_params_list,
|
25
25
|
s(:bodystmt, s(s(:void_stmt)), nil, nil, nil)))))
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
29
|
-
result = parse_with_builder
|
28
|
+
it 'produces a blank comment node surrounding a def that has no comment' do
|
29
|
+
result = parse_with_builder 'def foo; end'
|
30
30
|
result.must_equal s(:program,
|
31
31
|
s(s(:comment,
|
32
|
-
|
32
|
+
'',
|
33
33
|
s(:def,
|
34
|
-
s(:@ident,
|
34
|
+
s(:@ident, 'foo', s(1, 4)),
|
35
35
|
empty_params_list,
|
36
36
|
s(:bodystmt, s(s(:void_stmt)), nil, nil, nil)))))
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
39
|
+
it 'produces a comment node surrounding a commented class' do
|
40
40
|
result = parse_with_builder "# Foo\nclass Foo; end"
|
41
41
|
result.must_equal s(:program,
|
42
42
|
s(s(:comment,
|
43
43
|
"# Foo\n",
|
44
44
|
s(:class,
|
45
|
-
s(:const_ref, s(:@const,
|
45
|
+
s(:const_ref, s(:@const, 'Foo', s(2, 6))),
|
46
46
|
nil,
|
47
47
|
s(:bodystmt, s(s(:void_stmt)), nil, nil, nil)))))
|
48
48
|
end
|
49
49
|
|
50
|
-
it
|
51
|
-
result = parse_with_builder
|
50
|
+
it 'produce a blank comment node surrounding a class that has no comment' do
|
51
|
+
result = parse_with_builder 'class Foo; end'
|
52
52
|
result.must_equal s(:program,
|
53
53
|
s(s(:comment,
|
54
|
-
|
54
|
+
'',
|
55
55
|
s(:class,
|
56
|
-
s(:const_ref, s(:@const,
|
56
|
+
s(:const_ref, s(:@const, 'Foo', s(1, 6))),
|
57
57
|
nil,
|
58
58
|
s(:bodystmt, s(s(:void_stmt)), nil, nil, nil)))))
|
59
59
|
end
|
60
60
|
|
61
|
-
it
|
61
|
+
it 'produces a comment node surrounding a commented module' do
|
62
62
|
result = parse_with_builder "# Foo\nmodule Foo; end"
|
63
63
|
result.must_equal s(:program,
|
64
64
|
s(s(:comment,
|
65
65
|
"# Foo\n",
|
66
66
|
s(:module,
|
67
|
-
s(:const_ref, s(:@const,
|
67
|
+
s(:const_ref, s(:@const, 'Foo', s(2, 7))),
|
68
68
|
s(:bodystmt, s(s(:void_stmt)), nil, nil, nil)))))
|
69
69
|
end
|
70
70
|
|
71
|
-
it
|
72
|
-
result = parse_with_builder
|
71
|
+
it 'produces a blank comment node surrounding a module that has no comment' do
|
72
|
+
result = parse_with_builder 'module Foo; end'
|
73
73
|
result.must_equal s(:program,
|
74
74
|
s(s(:comment,
|
75
|
-
|
75
|
+
'',
|
76
76
|
s(:module,
|
77
|
-
s(:const_ref, s(:@const,
|
77
|
+
s(:const_ref, s(:@const, 'Foo', s(1, 7))),
|
78
78
|
s(:bodystmt, s(s(:void_stmt)), nil, nil, nil)))))
|
79
79
|
end
|
80
80
|
|
81
|
-
it
|
82
|
-
result = parse_with_builder
|
81
|
+
it 'is not confused by a symbol containing a keyword' do
|
82
|
+
result = parse_with_builder ':class; def foo; end'
|
83
83
|
result.must_equal s(:program,
|
84
|
-
s(s(:symbol_literal, s(:symbol, s(:@kw,
|
84
|
+
s(s(:symbol_literal, s(:symbol, s(:@kw, 'class', s(1, 1)))),
|
85
85
|
s(:comment,
|
86
|
-
|
86
|
+
'',
|
87
87
|
s(:def,
|
88
|
-
s(:@ident,
|
88
|
+
s(:@ident, 'foo', s(1, 12)),
|
89
89
|
empty_params_list,
|
90
90
|
s(:bodystmt, s(s(:void_stmt)), nil, nil, nil)))))
|
91
91
|
end
|
92
92
|
|
93
|
-
it
|
93
|
+
it 'is not confused by a dynamic symbol' do
|
94
94
|
result = parse_with_builder ":'foo'; def bar; end"
|
95
95
|
result.must_equal s(:program,
|
96
|
-
s(s(:dyna_symbol, s(s(:@tstring_content,
|
96
|
+
s(s(:dyna_symbol, s(s(:@tstring_content, 'foo', s(1, 2)))),
|
97
97
|
s(:comment,
|
98
|
-
|
98
|
+
'',
|
99
99
|
s(:def,
|
100
|
-
s(:@ident,
|
100
|
+
s(:@ident, 'bar', s(1, 12)),
|
101
101
|
empty_params_list,
|
102
102
|
s(:bodystmt, s(s(:void_stmt)), nil, nil, nil)))))
|
103
103
|
end
|
104
104
|
|
105
|
-
it
|
105
|
+
it 'is not confused by a dynamic symbol containing a class definition' do
|
106
106
|
result = parse_with_builder ":\"foo\#{class Bar;end}\""
|
107
107
|
result.must_equal s(:program,
|
108
108
|
s(s(:dyna_symbol,
|
109
|
-
s(s(:@tstring_content,
|
109
|
+
s(s(:@tstring_content, 'foo', s(1, 2)),
|
110
110
|
s(:string_embexpr,
|
111
111
|
s(s(:comment,
|
112
|
-
|
112
|
+
'',
|
113
113
|
s(:class,
|
114
|
-
s(:const_ref, s(:@const,
|
114
|
+
s(:const_ref, s(:@const, 'Bar', s(1, 13))),
|
115
115
|
nil,
|
116
116
|
s(:bodystmt, s(s(:void_stmt)), nil, nil, nil)))))))))
|
117
117
|
end
|
@@ -1,25 +1,25 @@
|
|
1
1
|
require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
|
2
2
|
|
3
3
|
describe RipperRubyParser::Parser do
|
4
|
-
describe
|
5
|
-
describe
|
6
|
-
it
|
7
|
-
|
4
|
+
describe '#parse' do
|
5
|
+
describe 'for single assignment' do
|
6
|
+
it 'works when assigning to a namespaced constant' do
|
7
|
+
'Foo::Bar = baz'.
|
8
8
|
must_be_parsed_as s(:cdecl,
|
9
9
|
s(:colon2, s(:const, :Foo), :Bar),
|
10
10
|
s(:call, nil, :baz))
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
14
|
-
|
13
|
+
it 'works when assigning to constant in the root namespace' do
|
14
|
+
'::Foo = bar'.
|
15
15
|
must_be_parsed_as s(:cdecl,
|
16
16
|
s(:colon3, :Foo),
|
17
17
|
s(:call, nil, :bar))
|
18
18
|
end
|
19
19
|
|
20
|
-
describe
|
20
|
+
describe 'with a right-hand splat' do
|
21
21
|
specify do
|
22
|
-
|
22
|
+
'foo = *bar'.
|
23
23
|
must_be_parsed_as s(:lasgn, :foo,
|
24
24
|
s(:svalue,
|
25
25
|
s(:splat,
|
@@ -27,7 +27,7 @@ describe RipperRubyParser::Parser do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
specify do
|
30
|
-
|
30
|
+
'foo = bar, *baz'.
|
31
31
|
must_be_parsed_as s(:lasgn, :foo,
|
32
32
|
s(:svalue,
|
33
33
|
s(:array,
|
@@ -37,9 +37,9 @@ describe RipperRubyParser::Parser do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
describe
|
40
|
+
describe 'with several items on the right hand side' do
|
41
41
|
specify do
|
42
|
-
|
42
|
+
'foo = bar, baz'.
|
43
43
|
must_be_parsed_as s(:lasgn, :foo,
|
44
44
|
s(:svalue,
|
45
45
|
s(:array,
|
@@ -48,9 +48,9 @@ describe RipperRubyParser::Parser do
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
describe
|
51
|
+
describe 'with an array literal on the right hand side' do
|
52
52
|
specify do
|
53
|
-
|
53
|
+
'foo = [bar, baz]'.
|
54
54
|
must_be_parsed_as s(:lasgn, :foo,
|
55
55
|
s(:array,
|
56
56
|
s(:call, nil, :bar),
|
@@ -59,16 +59,16 @@ describe RipperRubyParser::Parser do
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
describe
|
62
|
+
describe 'for multiple assignment' do
|
63
63
|
specify do
|
64
|
-
|
64
|
+
'foo, * = bar'.
|
65
65
|
must_be_parsed_as s(:masgn,
|
66
66
|
s(:array, s(:lasgn, :foo), s(:splat)),
|
67
67
|
s(:to_ary, s(:call, nil, :bar)))
|
68
68
|
end
|
69
69
|
|
70
70
|
specify do
|
71
|
-
|
71
|
+
'(foo, *bar) = baz'.
|
72
72
|
must_be_parsed_as s(:masgn,
|
73
73
|
s(:array,
|
74
74
|
s(:lasgn, :foo),
|
@@ -77,7 +77,7 @@ describe RipperRubyParser::Parser do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
specify do
|
80
|
-
|
80
|
+
'*foo, bar = baz'.
|
81
81
|
must_be_parsed_as s(:masgn,
|
82
82
|
s(:array,
|
83
83
|
s(:splat, s(:lasgn, :foo)),
|
@@ -86,9 +86,9 @@ describe RipperRubyParser::Parser do
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
-
describe
|
90
|
-
it
|
91
|
-
|
89
|
+
describe 'for assignment to a collection element' do
|
90
|
+
it 'handles multiple indices' do
|
91
|
+
'foo[bar, baz] = qux'.
|
92
92
|
must_be_parsed_as s(:attrasgn,
|
93
93
|
s(:call, nil, :foo),
|
94
94
|
:[]=,
|
@@ -98,10 +98,10 @@ describe RipperRubyParser::Parser do
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
-
describe
|
102
|
-
describe
|
103
|
-
it
|
104
|
-
|
101
|
+
describe 'for operator assignment' do
|
102
|
+
describe 'assigning to a collection element' do
|
103
|
+
it 'handles multiple indices' do
|
104
|
+
'foo[bar, baz] += qux'.
|
105
105
|
must_be_parsed_as s(:op_asgn1,
|
106
106
|
s(:call, nil, :foo),
|
107
107
|
s(:arglist,
|
@@ -111,24 +111,24 @@ describe RipperRubyParser::Parser do
|
|
111
111
|
s(:call, nil, :qux))
|
112
112
|
end
|
113
113
|
|
114
|
-
it
|
115
|
-
|
114
|
+
it 'works with &&=' do
|
115
|
+
'foo &&= bar'.
|
116
116
|
must_be_parsed_as s(:op_asgn_and,
|
117
117
|
s(:lvar, :foo), s(:lasgn, :foo, s(:call, nil, :bar)))
|
118
118
|
end
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
-
describe
|
123
|
-
describe
|
122
|
+
describe 'for multiple assignment' do
|
123
|
+
describe 'with a right-hand splat' do
|
124
124
|
specify do
|
125
|
-
|
125
|
+
'foo, bar = *baz'.
|
126
126
|
must_be_parsed_as s(:masgn,
|
127
127
|
s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
|
128
128
|
s(:splat, s(:call, nil, :baz)))
|
129
129
|
end
|
130
130
|
specify do
|
131
|
-
|
131
|
+
'foo, bar = baz, *qux'.
|
132
132
|
must_be_parsed_as s(:masgn,
|
133
133
|
s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
|
134
134
|
s(:array,
|