ripper_ruby_parser 1.7.2 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -0
  3. data/README.md +4 -4
  4. data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +24 -12
  5. data/lib/ripper_ruby_parser/sexp_handlers/assignment.rb +2 -2
  6. data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +47 -53
  7. data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +17 -19
  8. data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +34 -1
  9. data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +1 -1
  10. data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +9 -5
  11. data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +17 -15
  12. data/lib/ripper_ruby_parser/sexp_handlers/operators.rb +3 -3
  13. data/lib/ripper_ruby_parser/sexp_handlers/string_literals.rb +24 -28
  14. data/lib/ripper_ruby_parser/sexp_processor.rb +5 -18
  15. data/lib/ripper_ruby_parser/unescape.rb +63 -22
  16. data/lib/ripper_ruby_parser/version.rb +1 -1
  17. metadata +140 -79
  18. data/Rakefile +0 -33
  19. data/test/end_to_end/comments_test.rb +0 -59
  20. data/test/end_to_end/comparison_test.rb +0 -104
  21. data/test/end_to_end/lib_comparison_test.rb +0 -18
  22. data/test/end_to_end/line_numbering_test.rb +0 -31
  23. data/test/end_to_end/samples_comparison_test.rb +0 -13
  24. data/test/end_to_end/test_comparison_test.rb +0 -18
  25. data/test/pt_testcase/pt_test.rb +0 -44
  26. data/test/ripper_ruby_parser/commenting_ripper_parser_test.rb +0 -200
  27. data/test/ripper_ruby_parser/parser_test.rb +0 -576
  28. data/test/ripper_ruby_parser/sexp_handlers/assignment_test.rb +0 -597
  29. data/test/ripper_ruby_parser/sexp_handlers/blocks_test.rb +0 -717
  30. data/test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb +0 -536
  31. data/test/ripper_ruby_parser/sexp_handlers/literals_test.rb +0 -165
  32. data/test/ripper_ruby_parser/sexp_handlers/loops_test.rb +0 -209
  33. data/test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb +0 -237
  34. data/test/ripper_ruby_parser/sexp_handlers/methods_test.rb +0 -429
  35. data/test/ripper_ruby_parser/sexp_handlers/operators_test.rb +0 -405
  36. data/test/ripper_ruby_parser/sexp_handlers/string_literals_test.rb +0 -973
  37. data/test/ripper_ruby_parser/sexp_processor_test.rb +0 -327
  38. data/test/ripper_ruby_parser/version_test.rb +0 -7
  39. data/test/samples/assignment.rb +0 -22
  40. data/test/samples/comments.rb +0 -13
  41. data/test/samples/conditionals.rb +0 -23
  42. data/test/samples/lambdas.rb +0 -5
  43. data/test/samples/loops.rb +0 -36
  44. data/test/samples/misc.rb +0 -285
  45. data/test/samples/number.rb +0 -9
  46. data/test/samples/operators.rb +0 -18
  47. data/test/samples/strings.rb +0 -147
  48. data/test/test_helper.rb +0 -111
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require File.expand_path("../test_helper.rb", File.dirname(__FILE__))
4
- require "ruby_parser"
5
-
6
- describe "Using RipperRubyParser and RubyParser" do
7
- Dir.glob("lib/**/*.rb").each do |file|
8
- describe "for #{file}" do
9
- let :program do
10
- File.read file
11
- end
12
-
13
- it "gives the same result" do
14
- _(program).must_be_parsed_as_before
15
- end
16
- end
17
- end
18
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require File.expand_path("../test_helper.rb", File.dirname(__FILE__))
4
- require "ruby_parser"
5
-
6
- describe "Using RipperRubyParser and RubyParser" do
7
- describe "for a multi-line program" do
8
- let :program do
9
- <<-RUBY
10
- class Foo
11
- def foo()
12
- bar()
13
- baz(qux)
14
- end
15
- end
16
-
17
- module Bar
18
- @@baz = {}
19
- end
20
- RUBY
21
- end
22
-
23
- it "gives the same result" do
24
- _(program).must_be_parsed_as_before
25
- end
26
-
27
- it "gives the same result with line numbers" do
28
- _(program).must_be_parsed_as_before with_line_numbers: true
29
- end
30
- end
31
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require File.expand_path("../test_helper.rb", File.dirname(__FILE__))
4
- require "ruby_parser"
5
-
6
- describe "Using RipperRubyParser and RubyParser" do
7
- Dir.glob(File.expand_path("../samples/*.rb", File.dirname(__FILE__))).each do |file|
8
- it "gives the same result for #{file}" do
9
- program = File.read file
10
- _(program).must_be_parsed_as_before
11
- end
12
- end
13
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require File.expand_path("../test_helper.rb", File.dirname(__FILE__))
4
- require "ruby_parser"
5
-
6
- describe "Using RipperRubyParser and RubyParser" do
7
- Dir.glob("test/ripper_ruby_parser/**/*.rb").each do |file|
8
- describe "for #{file}" do
9
- let :program do
10
- File.read file
11
- end
12
-
13
- it "gives the same result" do
14
- _(program).must_be_parsed_as_before
15
- end
16
- end
17
- end
18
- end
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require File.expand_path("../test_helper.rb", File.dirname(__FILE__))
4
- require "pt_testcase"
5
-
6
- class TestParser < RipperRubyParser::Parser
7
- def process(input)
8
- parse input
9
- end
10
- end
11
-
12
- SKIPPED_TESTS = ["dstr_heredoc_windoze_sucks"].freeze
13
-
14
- class RubyParserTestCase < ParseTreeTestCase
15
- def self.previous(_key)
16
- "Ruby"
17
- end
18
-
19
- def self.generate_test(klass, node, data, input_name, _output_name)
20
- if data["Ruby"].is_a? Array
21
- klass.send :define_method, "test_#{node}" do
22
- skip "Not a parser test"
23
- end
24
- return
25
- end
26
-
27
- if SKIPPED_TESTS.include? node
28
- klass.send :define_method, "test_#{node}" do
29
- skip "Can't or won't fix this difference"
30
- end
31
- return
32
- end
33
-
34
- super klass, node, data, input_name, "ParseTree"
35
- end
36
- end
37
-
38
- class TestRuby19Parser < RubyParserTestCase
39
- def setup
40
- super
41
-
42
- self.processor = TestParser.new
43
- end
44
- end
@@ -1,200 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require File.expand_path("../test_helper.rb", File.dirname(__FILE__))
4
-
5
- describe RipperRubyParser::CommentingRipperParser do
6
- def parse_with_builder(str)
7
- builder = RipperRubyParser::CommentingRipperParser.new str
8
- builder.parse
9
- end
10
-
11
- def empty_params_list
12
- @empty_params_list ||= s(:params, *([nil] * 7))
13
- end
14
-
15
- describe "handling comments" do
16
- # Handle different results for dynamic symbol strings. This was changed in
17
- # Ruby 2.6.3 and up. See https://bugs.ruby-lang.org/issues/15670
18
- let(:dsym_string_type) { RUBY_VERSION < "2.6.3" ? :xstring : :string_content }
19
-
20
- it "produces a comment node surrounding a commented def" do
21
- result = parse_with_builder "# Foo\ndef foo; end"
22
- _(result).must_equal s(:program,
23
- s(:stmts,
24
- s(:comment,
25
- "# Foo\n",
26
- s(:def,
27
- s(:@ident, "foo", s(2, 4)),
28
- empty_params_list,
29
- s(:bodystmt,
30
- s(:stmts, s(:void_stmt, s(2, 12))), nil, nil, nil),
31
- s(2, 0)))))
32
- end
33
-
34
- it "produces a blank comment node surrounding a def that has no comment" do
35
- result = parse_with_builder "def foo; end"
36
- _(result).must_equal s(:program,
37
- s(:stmts,
38
- s(:comment,
39
- "",
40
- s(:def,
41
- s(:@ident, "foo", s(1, 4)),
42
- empty_params_list,
43
- s(:bodystmt,
44
- s(:stmts, s(:void_stmt, s(1, 12))), nil, nil, nil),
45
- s(1, 0)))))
46
- end
47
-
48
- it "produces a comment node surrounding a commented class" do
49
- result = parse_with_builder "# Foo\nclass Foo; end"
50
- _(result).must_equal s(:program,
51
- s(:stmts,
52
- s(:comment,
53
- "# Foo\n",
54
- s(:class,
55
- s(:const_ref, s(:@const, "Foo", s(2, 6))),
56
- nil,
57
- s(:bodystmt,
58
- s(:stmts, s(:void_stmt, s(2, 10))), nil, nil, nil),
59
- s(2, 0)))))
60
- end
61
-
62
- it "produce a blank comment node surrounding a class that has no comment" do
63
- result = parse_with_builder "class Foo; end"
64
- _(result).must_equal s(:program,
65
- s(:stmts,
66
- s(:comment,
67
- "",
68
- s(:class,
69
- s(:const_ref, s(:@const, "Foo", s(1, 6))),
70
- nil,
71
- s(:bodystmt,
72
- s(:stmts, s(:void_stmt, s(1, 10))), nil, nil, nil),
73
- s(1, 0)))))
74
- end
75
-
76
- it "produces a comment node surrounding a commented module" do
77
- result = parse_with_builder "# Foo\nmodule Foo; end"
78
- _(result).must_equal s(:program,
79
- s(:stmts,
80
- s(:comment,
81
- "# Foo\n",
82
- s(:module,
83
- s(:const_ref, s(:@const, "Foo", s(2, 7))),
84
- s(:bodystmt,
85
- s(:stmts, s(:void_stmt, s(2, 11))), nil, nil, nil),
86
- s(2, 0)))))
87
- end
88
-
89
- it "produces a blank comment node surrounding a module that has no comment" do
90
- result = parse_with_builder "module Foo; end"
91
- _(result).must_equal s(:program,
92
- s(:stmts,
93
- s(:comment,
94
- "",
95
- s(:module,
96
- s(:const_ref, s(:@const, "Foo", s(1, 7))),
97
- s(:bodystmt,
98
- s(:stmts, s(:void_stmt, s(1, 11))), nil, nil, nil),
99
- s(1, 0)))))
100
- end
101
-
102
- it "is not confused by a symbol containing a keyword" do
103
- result = parse_with_builder ":class; def foo; end"
104
- _(result).must_equal s(:program,
105
- s(:stmts,
106
- s(:symbol_literal, s(:symbol, s(:@kw, "class", s(1, 1)))),
107
- s(:comment,
108
- "",
109
- s(:def,
110
- s(:@ident, "foo", s(1, 12)),
111
- empty_params_list,
112
- s(:bodystmt,
113
- s(:stmts, s(:void_stmt, s(1, 20))), nil, nil, nil),
114
- s(1, 8)))))
115
- end
116
-
117
- it "is not confused by a dynamic symbol" do
118
- result = parse_with_builder ":'foo'; def bar; end"
119
- _(result).must_equal s(:program,
120
- s(:stmts,
121
- s(:dyna_symbol,
122
- s(dsym_string_type,
123
- s(:@tstring_content, "foo", s(1, 2), ":'"))),
124
- s(:comment,
125
- "",
126
- s(:def,
127
- s(:@ident, "bar", s(1, 12)),
128
- empty_params_list,
129
- s(:bodystmt,
130
- s(:stmts, s(:void_stmt, s(1, 20))), nil, nil, nil),
131
- s(1, 8)))))
132
- end
133
-
134
- it "is not confused by a dynamic symbol containing a class definition" do
135
- result = parse_with_builder ":\"foo\#{class Bar;end}\""
136
- _(result).must_equal s(:program,
137
- s(:stmts,
138
- s(:dyna_symbol,
139
- s(dsym_string_type,
140
- s(:@tstring_content, "foo", s(1, 2), ':"'),
141
- s(:string_embexpr,
142
- s(:stmts,
143
- s(:comment,
144
- "",
145
- s(:class,
146
- s(:const_ref, s(:@const, "Bar", s(1, 13))),
147
- nil,
148
- s(:bodystmt,
149
- s(:stmts, s(:void_stmt, s(1, 17))),
150
- nil, nil, nil),
151
- s(1, 7)))))))))
152
- end
153
-
154
- it "turns an embedded document into a comment node" do
155
- result = parse_with_builder "=begin Hello\nthere\n=end\nclass Foo; end"
156
- _(result).must_equal s(:program,
157
- s(:stmts,
158
- s(:comment,
159
- "=begin Hello\nthere\n=end\n",
160
- s(:class,
161
- s(:const_ref, s(:@const, "Foo", s(4, 6))),
162
- nil,
163
- s(:bodystmt,
164
- s(:stmts, s(:void_stmt, s(4, 10))), nil, nil, nil),
165
- s(4, 0)))))
166
- end
167
- end
168
-
169
- describe "handling syntax errors" do
170
- it "raises an error for an incomplete source" do
171
- _(proc { parse_with_builder "def foo" }).must_raise RipperRubyParser::SyntaxError
172
- end
173
-
174
- it "raises an error for an invalid class name" do
175
- _(proc { parse_with_builder "class foo; end" })
176
- .must_raise RipperRubyParser::SyntaxError
177
- end
178
-
179
- it "raises an error aliasing $1 as foo" do
180
- _(proc { parse_with_builder "alias foo $1" }).must_raise RipperRubyParser::SyntaxError
181
- end
182
-
183
- it "raises an error aliasing foo as $1" do
184
- _(proc { parse_with_builder "alias $1 foo" }).must_raise RipperRubyParser::SyntaxError
185
- end
186
-
187
- it "raises an error aliasing $2 as $1" do
188
- _(proc { parse_with_builder "alias $1 $2" }).must_raise RipperRubyParser::SyntaxError
189
- end
190
-
191
- it "raises an error assigning to $1" do
192
- _(proc { parse_with_builder "$1 = foo" }).must_raise RipperRubyParser::SyntaxError
193
- end
194
-
195
- it "raises an error using an invalid parameter name" do
196
- _(proc { parse_with_builder "def foo(BAR); end" })
197
- .must_raise RipperRubyParser::SyntaxError
198
- end
199
- end
200
- end