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,429 +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 instance method definitions" do
8
- it "treats kwrest argument as a local variable" do
9
- _("def foo(**bar); bar; end")
10
- .must_be_parsed_as s(:defn,
11
- :foo,
12
- s(:args, :"**bar"),
13
- s(:lvar, :bar))
14
- end
15
-
16
- it "treats kwrest argument as a local variable when other arguments are present" do
17
- _("def foo(bar, **baz); baz; end")
18
- .must_be_parsed_as s(:defn,
19
- :foo,
20
- s(:args, :bar, :"**baz"),
21
- s(:lvar, :baz))
22
- end
23
-
24
- it "treats kwrest argument as a local variable when an explicit block is present" do
25
- _("def foo(**bar, &baz); bar; end")
26
- .must_be_parsed_as s(:defn,
27
- :foo,
28
- s(:args, :"**bar", :"&baz"),
29
- s(:lvar, :bar))
30
- end
31
-
32
- it "treats block kwrest argument as an lvar" do
33
- _("def foo(**bar); baz { |**qux| bar; qux }; end")
34
- .must_be_parsed_as s(:defn, :foo,
35
- s(:args, :"**bar"),
36
- s(:iter,
37
- s(:call, nil, :baz),
38
- s(:args, :"**qux"),
39
- s(:block,
40
- s(:lvar, :bar),
41
- s(:lvar, :qux))))
42
- end
43
-
44
- it "works with a method argument with a default value" do
45
- _("def foo bar=nil; end")
46
- .must_be_parsed_as s(:defn,
47
- :foo,
48
- s(:args, s(:lasgn, :bar, s(:nil))),
49
- s(:nil))
50
- end
51
-
52
- it "works with several method arguments with default values" do
53
- _("def foo bar=1, baz=2; end")
54
- .must_be_parsed_as s(:defn,
55
- :foo,
56
- s(:args,
57
- s(:lasgn, :bar, s(:lit, 1)),
58
- s(:lasgn, :baz, s(:lit, 2))),
59
- s(:nil))
60
- end
61
-
62
- it "works with parentheses around the parameter list" do
63
- _("def foo(bar); end")
64
- .must_be_parsed_as s(:defn, :foo, s(:args, :bar), s(:nil))
65
- end
66
-
67
- it "works with a simple splat" do
68
- _("def foo *bar; end")
69
- .must_be_parsed_as s(:defn, :foo, s(:args, :"*bar"), s(:nil))
70
- end
71
-
72
- it "works with a regular argument plus splat" do
73
- _("def foo bar, *baz; end")
74
- .must_be_parsed_as s(:defn, :foo, s(:args, :bar, :"*baz"), s(:nil))
75
- end
76
-
77
- it "works with a nameless splat" do
78
- _("def foo *; end")
79
- .must_be_parsed_as s(:defn,
80
- :foo,
81
- s(:args, :"*"),
82
- s(:nil))
83
- end
84
-
85
- it "works with a nameless kwrest argument" do
86
- _("def foo **; end")
87
- .must_be_parsed_as s(:defn,
88
- :foo,
89
- s(:args, :"**"),
90
- s(:nil))
91
- end
92
-
93
- it "works for a simple case with explicit block parameter" do
94
- _("def foo &bar; end")
95
- .must_be_parsed_as s(:defn,
96
- :foo,
97
- s(:args, :"&bar"),
98
- s(:nil))
99
- end
100
-
101
- it "works with a regular argument plus explicit block parameter" do
102
- _("def foo bar, &baz; end")
103
- .must_be_parsed_as s(:defn,
104
- :foo,
105
- s(:args, :bar, :"&baz"),
106
- s(:nil))
107
- end
108
-
109
- it "works with a default value plus explicit block parameter" do
110
- _("def foo bar=1, &baz; end")
111
- .must_be_parsed_as s(:defn,
112
- :foo,
113
- s(:args,
114
- s(:lasgn, :bar, s(:lit, 1)),
115
- :"&baz"),
116
- s(:nil))
117
- end
118
-
119
- it "works with a default value plus mandatory argument" do
120
- _("def foo bar=1, baz; end")
121
- .must_be_parsed_as s(:defn,
122
- :foo,
123
- s(:args,
124
- s(:lasgn, :bar, s(:lit, 1)),
125
- :baz),
126
- s(:nil))
127
- end
128
-
129
- it "works with a splat plus explicit block parameter" do
130
- _("def foo *bar, &baz; end")
131
- .must_be_parsed_as s(:defn,
132
- :foo,
133
- s(:args, :"*bar", :"&baz"),
134
- s(:nil))
135
- end
136
-
137
- it "works with a default value plus splat" do
138
- _("def foo bar=1, *baz; end")
139
- .must_be_parsed_as s(:defn,
140
- :foo,
141
- s(:args,
142
- s(:lasgn, :bar, s(:lit, 1)),
143
- :"*baz"),
144
- s(:nil))
145
- end
146
-
147
- it "works with a default value, splat, plus final mandatory arguments" do
148
- _("def foo bar=1, *baz, qux, quuz; end")
149
- .must_be_parsed_as s(:defn,
150
- :foo,
151
- s(:args,
152
- s(:lasgn, :bar, s(:lit, 1)),
153
- :"*baz", :qux, :quuz),
154
- s(:nil))
155
- end
156
-
157
- it "works with a named argument with a default value" do
158
- _("def foo bar: 1; end")
159
- .must_be_parsed_as s(:defn,
160
- :foo,
161
- s(:args,
162
- s(:kwarg, :bar, s(:lit, 1))),
163
- s(:nil))
164
- end
165
-
166
- it "works with a named argument with no default value" do
167
- _("def foo bar:; end")
168
- .must_be_parsed_as s(:defn,
169
- :foo,
170
- s(:args,
171
- s(:kwarg, :bar)),
172
- s(:nil))
173
- end
174
-
175
- it "works with a double splat" do
176
- _("def foo **bar; end")
177
- .must_be_parsed_as s(:defn,
178
- :foo,
179
- s(:args, :'**bar'),
180
- s(:nil))
181
- end
182
-
183
- it "works with argument destructuring" do
184
- _("def foo((bar, baz)); end")
185
- .must_be_parsed_as s(:defn, :foo,
186
- s(:args, s(:masgn, :bar, :baz)),
187
- s(:nil))
188
- end
189
-
190
- it "works with argument destructuring including splat" do
191
- _("def foo((bar, *baz)); end")
192
- .must_be_parsed_as s(:defn, :foo,
193
- s(:args, s(:masgn, :bar, :'*baz')),
194
- s(:nil))
195
- end
196
-
197
- it "works with nested argument destructuring" do
198
- _("def foo((bar, (baz, qux))); end")
199
- .must_be_parsed_as s(:defn, :foo,
200
- s(:args, s(:masgn, :bar, s(:masgn, :baz, :qux))),
201
- s(:nil))
202
- end
203
-
204
- it "works when the method name is an operator" do
205
- _("def +; end")
206
- .must_be_parsed_as s(:defn, :+, s(:args),
207
- s(:nil))
208
- end
209
-
210
- it "works when the method name is a keyword" do
211
- _("def for; end")
212
- .must_be_parsed_as s(:defn, :for, s(:args),
213
- s(:nil))
214
- end
215
-
216
- it "assigns correct line numbers when the body is empty" do
217
- _("def bar\nend")
218
- .must_be_parsed_as s(:defn,
219
- :bar,
220
- s(:args).line(1),
221
- s(:nil).line(2)).line(1),
222
- with_line_numbers: true
223
- end
224
- end
225
-
226
- describe "for singleton method definitions" do
227
- it "works with empty body" do
228
- _("def foo.bar; end")
229
- .must_be_parsed_as s(:defs,
230
- s(:call, nil, :foo),
231
- :bar,
232
- s(:args),
233
- s(:nil))
234
- end
235
-
236
- it "works with a body with multiple statements" do
237
- _("def foo.bar; baz; qux; end")
238
- .must_be_parsed_as s(:defs,
239
- s(:call, nil, :foo),
240
- :bar,
241
- s(:args),
242
- s(:call, nil, :baz),
243
- s(:call, nil, :qux))
244
- end
245
-
246
- it "works with a simple splat" do
247
- _("def foo.bar *baz; end")
248
- .must_be_parsed_as s(:defs,
249
- s(:call, nil, :foo),
250
- :bar,
251
- s(:args, :"*baz"),
252
- s(:nil))
253
- end
254
-
255
- it "works when the method name is a keyword" do
256
- _("def foo.for; end")
257
- .must_be_parsed_as s(:defs,
258
- s(:call, nil, :foo),
259
- :for, s(:args),
260
- s(:nil))
261
- end
262
- end
263
-
264
- describe "for the alias statement" do
265
- it "works with regular barewords" do
266
- _("alias foo bar")
267
- .must_be_parsed_as s(:alias,
268
- s(:lit, :foo), s(:lit, :bar))
269
- end
270
-
271
- it "works with symbols" do
272
- _("alias :foo :bar")
273
- .must_be_parsed_as s(:alias,
274
- s(:lit, :foo), s(:lit, :bar))
275
- end
276
-
277
- it "works with operator barewords" do
278
- _("alias + -")
279
- .must_be_parsed_as s(:alias,
280
- s(:lit, :+), s(:lit, :-))
281
- end
282
-
283
- it "treats keywords as symbols" do
284
- _("alias next foo")
285
- .must_be_parsed_as s(:alias, s(:lit, :next), s(:lit, :foo))
286
- end
287
-
288
- it "works with global variables" do
289
- _("alias $foo $bar")
290
- .must_be_parsed_as s(:valias, :$foo, :$bar)
291
- end
292
- end
293
-
294
- describe "for the undef statement" do
295
- it "works with a single bareword identifier" do
296
- _("undef foo")
297
- .must_be_parsed_as s(:undef, s(:lit, :foo))
298
- end
299
-
300
- it "works with a single symbol" do
301
- _("undef :foo")
302
- .must_be_parsed_as s(:undef, s(:lit, :foo))
303
- end
304
-
305
- it "works with multiple bareword identifiers" do
306
- _("undef foo, bar")
307
- .must_be_parsed_as s(:block,
308
- s(:undef, s(:lit, :foo)),
309
- s(:undef, s(:lit, :bar)))
310
- end
311
-
312
- it "works with multiple bareword symbols" do
313
- _("undef :foo, :bar")
314
- .must_be_parsed_as s(:block,
315
- s(:undef, s(:lit, :foo)),
316
- s(:undef, s(:lit, :bar)))
317
- end
318
- end
319
-
320
- describe "for the return statement" do
321
- it "works with no arguments" do
322
- _("return")
323
- .must_be_parsed_as s(:return)
324
- end
325
-
326
- it "works with one argument" do
327
- _("return foo")
328
- .must_be_parsed_as s(:return,
329
- s(:call, nil, :foo))
330
- end
331
-
332
- it "works with a splat argument" do
333
- _("return *foo")
334
- .must_be_parsed_as s(:return,
335
- s(:svalue,
336
- s(:splat,
337
- s(:call, nil, :foo))))
338
- end
339
-
340
- it "works with multiple arguments" do
341
- _("return foo, bar")
342
- .must_be_parsed_as s(:return,
343
- s(:array,
344
- s(:call, nil, :foo),
345
- s(:call, nil, :bar)))
346
- end
347
-
348
- it "works with a regular argument and a splat argument" do
349
- _("return foo, *bar")
350
- .must_be_parsed_as s(:return,
351
- s(:array,
352
- s(:call, nil, :foo),
353
- s(:splat,
354
- s(:call, nil, :bar))))
355
- end
356
-
357
- it "works with a function call with parentheses" do
358
- _("return foo(bar)")
359
- .must_be_parsed_as s(:return,
360
- s(:call, nil, :foo,
361
- s(:call, nil, :bar)))
362
- end
363
-
364
- it "works with a function call without parentheses" do
365
- _("return foo bar")
366
- .must_be_parsed_as s(:return,
367
- s(:call, nil, :foo,
368
- s(:call, nil, :bar)))
369
- end
370
- end
371
-
372
- describe "for yield" do
373
- it "works with no arguments and no parentheses" do
374
- _("yield")
375
- .must_be_parsed_as s(:yield)
376
- end
377
-
378
- it "works with parentheses but no arguments" do
379
- _("yield()")
380
- .must_be_parsed_as s(:yield)
381
- end
382
-
383
- it "works with one argument and no parentheses" do
384
- _("yield foo")
385
- .must_be_parsed_as s(:yield, s(:call, nil, :foo))
386
- end
387
-
388
- it "works with one argument and parentheses" do
389
- _("yield(foo)")
390
- .must_be_parsed_as s(:yield, s(:call, nil, :foo))
391
- end
392
-
393
- it "works with multiple arguments and no parentheses" do
394
- _("yield foo, bar")
395
- .must_be_parsed_as s(:yield,
396
- s(:call, nil, :foo),
397
- s(:call, nil, :bar))
398
- end
399
-
400
- it "works with multiple arguments and parentheses" do
401
- _("yield(foo, bar)")
402
- .must_be_parsed_as s(:yield,
403
- s(:call, nil, :foo),
404
- s(:call, nil, :bar))
405
- end
406
-
407
- it "works with splat" do
408
- _("yield foo, *bar")
409
- .must_be_parsed_as s(:yield,
410
- s(:call, nil, :foo),
411
- s(:splat, s(:call, nil, :bar)))
412
- end
413
-
414
- it "works with a function call with parentheses" do
415
- _("yield foo(bar)")
416
- .must_be_parsed_as s(:yield,
417
- s(:call, nil, :foo,
418
- s(:call, nil, :bar)))
419
- end
420
-
421
- it "works with a function call without parentheses" do
422
- _("yield foo bar")
423
- .must_be_parsed_as s(:yield,
424
- s(:call, nil, :foo,
425
- s(:call, nil, :bar)))
426
- end
427
- end
428
- end
429
- end