ripper_ruby_parser 1.7.2 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +28 -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/blocks.rb +33 -54
  6. data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +17 -19
  7. data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +34 -1
  8. data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +1 -1
  9. data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +12 -15
  10. data/lib/ripper_ruby_parser/sexp_handlers/string_literals.rb +21 -15
  11. data/lib/ripper_ruby_parser/sexp_processor.rb +4 -17
  12. data/lib/ripper_ruby_parser/unescape.rb +36 -12
  13. data/lib/ripper_ruby_parser/version.rb +1 -1
  14. metadata +110 -78
  15. data/Rakefile +0 -33
  16. data/test/end_to_end/comments_test.rb +0 -59
  17. data/test/end_to_end/comparison_test.rb +0 -104
  18. data/test/end_to_end/lib_comparison_test.rb +0 -18
  19. data/test/end_to_end/line_numbering_test.rb +0 -31
  20. data/test/end_to_end/samples_comparison_test.rb +0 -13
  21. data/test/end_to_end/test_comparison_test.rb +0 -18
  22. data/test/pt_testcase/pt_test.rb +0 -44
  23. data/test/ripper_ruby_parser/commenting_ripper_parser_test.rb +0 -200
  24. data/test/ripper_ruby_parser/parser_test.rb +0 -576
  25. data/test/ripper_ruby_parser/sexp_handlers/assignment_test.rb +0 -597
  26. data/test/ripper_ruby_parser/sexp_handlers/blocks_test.rb +0 -717
  27. data/test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb +0 -536
  28. data/test/ripper_ruby_parser/sexp_handlers/literals_test.rb +0 -165
  29. data/test/ripper_ruby_parser/sexp_handlers/loops_test.rb +0 -209
  30. data/test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb +0 -237
  31. data/test/ripper_ruby_parser/sexp_handlers/methods_test.rb +0 -429
  32. data/test/ripper_ruby_parser/sexp_handlers/operators_test.rb +0 -405
  33. data/test/ripper_ruby_parser/sexp_handlers/string_literals_test.rb +0 -973
  34. data/test/ripper_ruby_parser/sexp_processor_test.rb +0 -327
  35. data/test/ripper_ruby_parser/version_test.rb +0 -7
  36. data/test/samples/assignment.rb +0 -22
  37. data/test/samples/comments.rb +0 -13
  38. data/test/samples/conditionals.rb +0 -23
  39. data/test/samples/lambdas.rb +0 -5
  40. data/test/samples/loops.rb +0 -36
  41. data/test/samples/misc.rb +0 -285
  42. data/test/samples/number.rb +0 -9
  43. data/test/samples/operators.rb +0 -18
  44. data/test/samples/strings.rb +0 -147
  45. data/test/test_helper.rb +0 -111
@@ -1,165 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require File.expand_path("../../test_helper.rb", File.dirname(__FILE__))
4
-
5
- describe RipperRubyParser::Parser do
6
- let(:parser) { RipperRubyParser::Parser.new }
7
-
8
- describe "#parse" do
9
- describe "for character literals" do
10
- it "works for simple character literals" do
11
- _("?a")
12
- .must_be_parsed_as s(:str, "a")
13
- end
14
-
15
- it "works for escaped character literals" do
16
- _('?\\n')
17
- .must_be_parsed_as s(:str, "\n")
18
- end
19
-
20
- it "works for escaped character literals with ctrl" do
21
- _('?\\C-a')
22
- .must_be_parsed_as s(:str, "\u0001")
23
- end
24
-
25
- it "works for escaped character literals with meta" do
26
- _('?\\M-a')
27
- .must_be_parsed_as s(:str, (+"\xE1").force_encoding("ascii-8bit"))
28
- end
29
-
30
- it "works for escaped character literals with meta plus shorthand ctrl" do
31
- _('?\\M-\\ca')
32
- .must_be_parsed_as s(:str, (+"\x81").force_encoding("ascii-8bit"))
33
- end
34
-
35
- it "works for escaped character literals with shorthand ctrl plus meta" do
36
- _('?\\c\\M-a')
37
- .must_be_parsed_as s(:str, (+"\x81").force_encoding("ascii-8bit"))
38
- end
39
-
40
- it "works for escaped character literals with meta plus ctrl" do
41
- _('?\\M-\\C-a')
42
- .must_be_parsed_as s(:str, (+"\x81").force_encoding("ascii-8bit"))
43
- end
44
-
45
- it "works for escaped character literals with ctrl plus meta" do
46
- _('?\\C-\\M-a')
47
- .must_be_parsed_as s(:str, (+"\x81").force_encoding("ascii-8bit"))
48
- end
49
- end
50
-
51
- describe "for array literals" do
52
- it "works for an empty array" do
53
- _("[]")
54
- .must_be_parsed_as s(:array)
55
- end
56
-
57
- it "works for a simple case with splat" do
58
- _("[*foo]")
59
- .must_be_parsed_as s(:array,
60
- s(:splat, s(:call, nil, :foo)))
61
- end
62
-
63
- it "works for a multi-element case with splat" do
64
- _("[foo, *bar]")
65
- .must_be_parsed_as s(:array,
66
- s(:call, nil, :foo),
67
- s(:splat, s(:call, nil, :bar)))
68
- end
69
- end
70
-
71
- describe "for hash literals" do
72
- it "works for an empty hash" do
73
- _("{}")
74
- .must_be_parsed_as s(:hash)
75
- end
76
-
77
- it "works for a hash with one pair" do
78
- _("{foo => bar}")
79
- .must_be_parsed_as s(:hash,
80
- s(:call, nil, :foo),
81
- s(:call, nil, :bar))
82
- end
83
-
84
- it "works for a hash with multiple pairs" do
85
- _("{foo => bar, baz => qux}")
86
- .must_be_parsed_as s(:hash,
87
- s(:call, nil, :foo),
88
- s(:call, nil, :bar),
89
- s(:call, nil, :baz),
90
- s(:call, nil, :qux))
91
- end
92
-
93
- it "works for a hash with label keys" do
94
- _("{foo: bar, baz: qux}")
95
- .must_be_parsed_as s(:hash,
96
- s(:lit, :foo),
97
- s(:call, nil, :bar),
98
- s(:lit, :baz),
99
- s(:call, nil, :qux))
100
- end
101
-
102
- it "works for a hash with dynamic label keys" do
103
- _("{'foo': bar}")
104
- .must_be_parsed_as s(:hash,
105
- s(:lit, :foo),
106
- s(:call, nil, :bar))
107
- end
108
-
109
- it "works for a hash with splat" do
110
- _("{foo: bar, baz: qux, **quux}")
111
- .must_be_parsed_as s(:hash,
112
- s(:lit, :foo), s(:call, nil, :bar),
113
- s(:lit, :baz), s(:call, nil, :qux),
114
- s(:kwsplat, s(:call, nil, :quux)))
115
- end
116
- end
117
-
118
- describe "for number literals" do
119
- it "works for floats" do
120
- _("3.14")
121
- .must_be_parsed_as s(:lit, 3.14)
122
- end
123
-
124
- it "works for octal integer literals" do
125
- _("0700")
126
- .must_be_parsed_as s(:lit, 448)
127
- end
128
-
129
- it "handles negative sign for integers" do
130
- _("-1")
131
- .must_be_parsed_as s(:lit, -1)
132
- end
133
-
134
- it "handles space after negative sign for integers" do
135
- _("-1 ")
136
- .must_be_parsed_as s(:lit, -1)
137
- end
138
-
139
- it "handles negative sign for floats" do
140
- _("-3.14")
141
- .must_be_parsed_as s(:lit, -3.14)
142
- end
143
-
144
- it "handles space after negative sign for floats" do
145
- _("-3.14 ")
146
- .must_be_parsed_as s(:lit, -3.14)
147
- end
148
-
149
- it "handles positive sign" do
150
- _("+1")
151
- .must_be_parsed_as s(:lit, 1)
152
- end
153
-
154
- it "works for rationals" do
155
- _("1000r")
156
- .must_be_parsed_as s(:lit, 1000r)
157
- end
158
-
159
- it "works for imaginary numbers" do
160
- _("1i")
161
- .must_be_parsed_as s(:lit, 1i)
162
- end
163
- end
164
- end
165
- end
@@ -1,209 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require File.expand_path("../../test_helper.rb", File.dirname(__FILE__))
4
-
5
- describe RipperRubyParser::Parser do
6
- describe "#parse" do
7
- describe "for the while statement" do
8
- it "works with do" do
9
- _("while foo do; bar; end")
10
- .must_be_parsed_as s(:while,
11
- s(:call, nil, :foo),
12
- s(:call, nil, :bar), true)
13
- end
14
-
15
- it "works without do" do
16
- _("while foo; bar; end")
17
- .must_be_parsed_as s(:while,
18
- s(:call, nil, :foo),
19
- s(:call, nil, :bar), true)
20
- end
21
-
22
- it "works in the single-line postfix case" do
23
- _("foo while bar")
24
- .must_be_parsed_as s(:while,
25
- s(:call, nil, :bar),
26
- s(:call, nil, :foo), true)
27
- end
28
-
29
- it "works in the block postfix case" do
30
- _("begin; foo; end while bar")
31
- .must_be_parsed_as s(:while,
32
- s(:call, nil, :bar),
33
- s(:call, nil, :foo), false)
34
- end
35
-
36
- it "handles a negative condition" do
37
- _("while not foo; bar; end")
38
- .must_be_parsed_as s(:while,
39
- s(:call, s(:call, nil, :foo), :!),
40
- s(:call, nil, :bar), true)
41
- end
42
-
43
- it "handles a negative condition in the postfix case" do
44
- _("foo while not bar")
45
- .must_be_parsed_as s(:while,
46
- s(:call, s(:call, nil, :bar), :!),
47
- s(:call, nil, :foo), true)
48
- end
49
-
50
- it "converts a negated match condition to :until" do
51
- _("while foo !~ bar; baz; end")
52
- .must_be_parsed_as s(:until,
53
- s(:call, s(:call, nil, :foo), :=~, s(:call, nil, :bar)),
54
- s(:call, nil, :baz), true)
55
- end
56
-
57
- it "converts a negated match condition to :until in the postfix case" do
58
- _("baz while foo !~ bar")
59
- .must_be_parsed_as s(:until,
60
- s(:call, s(:call, nil, :foo), :=~, s(:call, nil, :bar)),
61
- s(:call, nil, :baz), true)
62
- end
63
-
64
- it "cleans up begin..end block in condition" do
65
- _("while begin foo end; bar; end")
66
- .must_be_parsed_as s(:while,
67
- s(:call, nil, :foo),
68
- s(:call, nil, :bar), true)
69
- end
70
-
71
- it "cleans up begin..end block in condition in the postfix case" do
72
- _("foo while begin bar end")
73
- .must_be_parsed_as s(:while,
74
- s(:call, nil, :bar),
75
- s(:call, nil, :foo), true)
76
- end
77
-
78
- it "works with do and an empty body" do
79
- _("while foo do; end")
80
- .must_be_parsed_as s(:while,
81
- s(:call, nil, :foo),
82
- nil, true)
83
- end
84
-
85
- it "works without do and with an empty body" do
86
- _("while foo; end")
87
- .must_be_parsed_as s(:while,
88
- s(:call, nil, :foo),
89
- nil, true)
90
- end
91
- end
92
-
93
- describe "for the until statement" do
94
- it "works in the prefix block case with do" do
95
- _("until foo do; bar; end")
96
- .must_be_parsed_as s(:until,
97
- s(:call, nil, :foo),
98
- s(:call, nil, :bar), true)
99
- end
100
-
101
- it "works in the prefix block case without do" do
102
- _("until foo; bar; end")
103
- .must_be_parsed_as s(:until,
104
- s(:call, nil, :foo),
105
- s(:call, nil, :bar), true)
106
- end
107
-
108
- it "works in the single-line postfix case" do
109
- _("foo until bar")
110
- .must_be_parsed_as s(:until,
111
- s(:call, nil, :bar),
112
- s(:call, nil, :foo), true)
113
- end
114
-
115
- it "works in the block postfix case" do
116
- _("begin; foo; end until bar")
117
- .must_be_parsed_as s(:until,
118
- s(:call, nil, :bar),
119
- s(:call, nil, :foo), false)
120
- end
121
-
122
- it "handles a negative condition" do
123
- _("until not foo; bar; end")
124
- .must_be_parsed_as s(:until,
125
- s(:call, s(:call, nil, :foo), :!),
126
- s(:call, nil, :bar), true)
127
- end
128
-
129
- it "handles a negative condition in the postfix case" do
130
- _("foo until not bar")
131
- .must_be_parsed_as s(:until,
132
- s(:call, s(:call, nil, :bar), :!),
133
- s(:call, nil, :foo), true)
134
- end
135
-
136
- it "converts a negated match condition to :while" do
137
- _("until foo !~ bar; baz; end")
138
- .must_be_parsed_as s(:while,
139
- s(:call, s(:call, nil, :foo), :=~, s(:call, nil, :bar)),
140
- s(:call, nil, :baz), true)
141
- end
142
-
143
- it "converts a negated match condition to :while in the postfix case" do
144
- _("baz until foo !~ bar")
145
- .must_be_parsed_as s(:while,
146
- s(:call, s(:call, nil, :foo), :=~, s(:call, nil, :bar)),
147
- s(:call, nil, :baz), true)
148
- end
149
-
150
- it "cleans up begin..end block in condition" do
151
- _("until begin foo end; bar; end")
152
- .must_be_parsed_as s(:until,
153
- s(:call, nil, :foo),
154
- s(:call, nil, :bar), true)
155
- end
156
-
157
- it "cleans up begin..end block in condition in the postfix case" do
158
- _("foo until begin bar end")
159
- .must_be_parsed_as s(:until,
160
- s(:call, nil, :bar),
161
- s(:call, nil, :foo), true)
162
- end
163
- end
164
-
165
- describe "for the for statement" do
166
- it "works with do" do
167
- _("for foo in bar do; baz; end")
168
- .must_be_parsed_as s(:for,
169
- s(:call, nil, :bar),
170
- s(:lasgn, :foo),
171
- s(:call, nil, :baz))
172
- end
173
-
174
- it "works without do" do
175
- _("for foo in bar; baz; end")
176
- .must_be_parsed_as s(:for,
177
- s(:call, nil, :bar),
178
- s(:lasgn, :foo),
179
- s(:call, nil, :baz))
180
- end
181
-
182
- it "works with an empty body" do
183
- _("for foo in bar; end")
184
- .must_be_parsed_as s(:for,
185
- s(:call, nil, :bar),
186
- s(:lasgn, :foo))
187
- end
188
-
189
- it "works with explicit multiple assignment" do
190
- _("for foo, bar in baz; end")
191
- .must_be_parsed_as s(:for,
192
- s(:call, nil, :baz),
193
- s(:masgn,
194
- s(:array,
195
- s(:lasgn, :foo),
196
- s(:lasgn, :bar))))
197
- end
198
-
199
- it "works with multiple assignment with trailing comma" do
200
- _("for foo, in bar; end")
201
- .must_be_parsed_as s(:for,
202
- s(:call, nil, :bar),
203
- s(:masgn,
204
- s(:array,
205
- s(:lasgn, :foo))))
206
- end
207
- end
208
- end
209
- end
@@ -1,237 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require File.expand_path("../../test_helper.rb", File.dirname(__FILE__))
4
-
5
- describe RipperRubyParser::SexpHandlers::MethodCalls do
6
- describe "when parsing with RipperRubyParser::Parser#parse" do
7
- describe "for method calls" do
8
- describe "without a receiver" do
9
- it "works without parentheses" do
10
- _("foo bar")
11
- .must_be_parsed_as s(:call, nil, :foo,
12
- s(:call, nil, :bar))
13
- end
14
-
15
- it "works with parentheses" do
16
- _("foo(bar)")
17
- .must_be_parsed_as s(:call, nil, :foo,
18
- s(:call, nil, :bar))
19
- end
20
-
21
- it "works with an empty parameter list and no parentheses" do
22
- _("foo")
23
- .must_be_parsed_as s(:call, nil, :foo)
24
- end
25
-
26
- it "works with parentheses around an empty parameter list" do
27
- _("foo()")
28
- .must_be_parsed_as s(:call, nil, :foo)
29
- end
30
-
31
- it "works for methods ending in a question mark" do
32
- _("foo?")
33
- .must_be_parsed_as s(:call, nil, :foo?)
34
- end
35
-
36
- it "works with nested calls without parentheses" do
37
- _("foo bar baz")
38
- .must_be_parsed_as s(:call, nil, :foo,
39
- s(:call, nil, :bar,
40
- s(:call, nil, :baz)))
41
- end
42
-
43
- it "works with a non-final splat argument" do
44
- _("foo(bar, *baz, qux)")
45
- .must_be_parsed_as s(:call,
46
- nil,
47
- :foo,
48
- s(:call, nil, :bar),
49
- s(:splat, s(:call, nil, :baz)),
50
- s(:call, nil, :qux))
51
- end
52
-
53
- it "works with a splat argument followed by several regular arguments" do
54
- _("foo(bar, *baz, qux, quuz)")
55
- .must_be_parsed_as s(:call,
56
- nil,
57
- :foo,
58
- s(:call, nil, :bar),
59
- s(:splat, s(:call, nil, :baz)),
60
- s(:call, nil, :qux),
61
- s(:call, nil, :quuz))
62
- end
63
-
64
- it "works with a named argument" do
65
- _("foo(bar, baz: qux)")
66
- .must_be_parsed_as s(:call,
67
- nil,
68
- :foo,
69
- s(:call, nil, :bar),
70
- s(:hash, s(:lit, :baz), s(:call, nil, :qux)))
71
- end
72
-
73
- it "works with several named arguments" do
74
- _("foo(bar, baz: qux, quux: quuz)")
75
- .must_be_parsed_as s(:call,
76
- nil,
77
- :foo,
78
- s(:call, nil, :bar),
79
- s(:hash,
80
- s(:lit, :baz), s(:call, nil, :qux),
81
- s(:lit, :quux), s(:call, nil, :quuz)))
82
- end
83
-
84
- it "works with a double splat argument" do
85
- _("foo(bar, **baz)")
86
- .must_be_parsed_as s(:call,
87
- nil,
88
- :foo,
89
- s(:call, nil, :bar),
90
- s(:hash,
91
- s(:kwsplat, s(:call, nil, :baz))))
92
- end
93
-
94
- it "works with a named argument followed by a double splat argument" do
95
- _("foo(bar, baz: qux, **quuz)")
96
- .must_be_parsed_as s(:call,
97
- nil,
98
- :foo,
99
- s(:call, nil, :bar),
100
- s(:hash,
101
- s(:lit, :baz), s(:call, nil, :qux),
102
- s(:kwsplat, s(:call, nil, :quuz))))
103
- end
104
- end
105
-
106
- describe "with a receiver" do
107
- it "works without parentheses" do
108
- _("foo.bar baz")
109
- .must_be_parsed_as s(:call,
110
- s(:call, nil, :foo),
111
- :bar,
112
- s(:call, nil, :baz))
113
- end
114
-
115
- it "works with parentheses" do
116
- _("foo.bar(baz)")
117
- .must_be_parsed_as s(:call,
118
- s(:call, nil, :foo),
119
- :bar,
120
- s(:call, nil, :baz))
121
- end
122
-
123
- it "works with parentheses around a call with no parentheses" do
124
- _("foo.bar(baz qux)")
125
- .must_be_parsed_as s(:call,
126
- s(:call, nil, :foo),
127
- :bar,
128
- s(:call, nil, :baz,
129
- s(:call, nil, :qux)))
130
- end
131
-
132
- it "works with nested calls without parentheses" do
133
- _("foo.bar baz qux")
134
- .must_be_parsed_as s(:call,
135
- s(:call, nil, :foo),
136
- :bar,
137
- s(:call, nil, :baz,
138
- s(:call, nil, :qux)))
139
- end
140
-
141
- it "does not keep :begin around a method receiver" do
142
- _("begin; foo; end.bar")
143
- .must_be_parsed_as s(:call, s(:call, nil, :foo), :bar)
144
- end
145
- end
146
-
147
- describe "for collection indexing" do
148
- it "works in the simple case" do
149
- _("foo[bar]")
150
- .must_be_parsed_as s(:call,
151
- s(:call, nil, :foo),
152
- :[],
153
- s(:call, nil, :bar))
154
- end
155
-
156
- it "works without any indexes" do
157
- _("foo[]").must_be_parsed_as s(:call, s(:call, nil, :foo),
158
- :[])
159
- end
160
-
161
- it "works with self[]" do
162
- _("self[foo]").must_be_parsed_as s(:call, s(:self), :[],
163
- s(:call, nil, :foo))
164
- end
165
- end
166
-
167
- describe "safe call" do
168
- it "works without arguments" do
169
- _("foo&.bar").must_be_parsed_as s(:safe_call, s(:call, nil, :foo), :bar)
170
- end
171
-
172
- it "works with arguments" do
173
- _("foo&.bar baz")
174
- .must_be_parsed_as s(:safe_call,
175
- s(:call, nil, :foo),
176
- :bar,
177
- s(:call, nil, :baz))
178
- end
179
- end
180
-
181
- describe "with blocks" do
182
- it "works for a do block" do
183
- _("foo.bar do baz; end")
184
- .must_be_parsed_as s(:iter,
185
- s(:call,
186
- s(:call, nil, :foo),
187
- :bar),
188
- 0,
189
- s(:call, nil, :baz))
190
- end
191
-
192
- it "works for a do block with several statements" do
193
- _("foo.bar do baz; qux; end")
194
- .must_be_parsed_as s(:iter,
195
- s(:call,
196
- s(:call, nil, :foo),
197
- :bar),
198
- 0,
199
- s(:block,
200
- s(:call, nil, :baz),
201
- s(:call, nil, :qux)))
202
- end
203
- end
204
- end
205
-
206
- describe "for calls to super" do
207
- specify { _("super").must_be_parsed_as s(:zsuper) }
208
- specify do
209
- _("super foo").must_be_parsed_as s(:super,
210
- s(:call, nil, :foo))
211
- end
212
- specify do
213
- _("super foo, bar").must_be_parsed_as s(:super,
214
- s(:call, nil, :foo),
215
- s(:call, nil, :bar))
216
- end
217
- specify do
218
- _("super foo, *bar").must_be_parsed_as s(:super,
219
- s(:call, nil, :foo),
220
- s(:splat,
221
- s(:call, nil, :bar)))
222
- end
223
- specify do
224
- _("super foo, *bar, &baz")
225
- .must_be_parsed_as s(:super,
226
- s(:call, nil, :foo),
227
- s(:splat, s(:call, nil, :bar)),
228
- s(:block_pass, s(:call, nil, :baz)))
229
- end
230
- end
231
-
232
- it "handles calling a proc" do
233
- _("foo.()")
234
- .must_be_parsed_as s(:call, s(:call, nil, :foo), :call)
235
- end
236
- end
237
- end