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,405 +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 boolean operators" do
8
- it "handles :and" do
9
- _("foo and bar")
10
- .must_be_parsed_as s(:and,
11
- s(:call, nil, :foo),
12
- s(:call, nil, :bar))
13
- end
14
-
15
- it "handles double :and" do
16
- _("foo and bar and baz")
17
- .must_be_parsed_as s(:and,
18
- s(:call, nil, :foo),
19
- s(:and,
20
- s(:call, nil, :bar),
21
- s(:call, nil, :baz)))
22
- end
23
-
24
- it "handles :or" do
25
- _("foo or bar")
26
- .must_be_parsed_as s(:or,
27
- s(:call, nil, :foo),
28
- s(:call, nil, :bar))
29
- end
30
-
31
- it "handles double :or" do
32
- _("foo or bar or baz")
33
- .must_be_parsed_as s(:or,
34
- s(:call, nil, :foo),
35
- s(:or,
36
- s(:call, nil, :bar),
37
- s(:call, nil, :baz)))
38
- end
39
-
40
- it "handles :or after :and" do
41
- _("foo and bar or baz")
42
- .must_be_parsed_as s(:or,
43
- s(:and,
44
- s(:call, nil, :foo),
45
- s(:call, nil, :bar)),
46
- s(:call, nil, :baz))
47
- end
48
-
49
- it "handles :and after :or" do
50
- _("foo or bar and baz")
51
- .must_be_parsed_as s(:and,
52
- s(:or,
53
- s(:call, nil, :foo),
54
- s(:call, nil, :bar)),
55
- s(:call, nil, :baz))
56
- end
57
-
58
- it "converts :&& to :and" do
59
- _("foo && bar")
60
- .must_be_parsed_as s(:and,
61
- s(:call, nil, :foo),
62
- s(:call, nil, :bar))
63
- end
64
-
65
- it "handles :|| after :&&" do
66
- _("foo && bar || baz")
67
- .must_be_parsed_as s(:or,
68
- s(:and,
69
- s(:call, nil, :foo),
70
- s(:call, nil, :bar)),
71
- s(:call, nil, :baz))
72
- end
73
-
74
- it "handles :&& after :||" do
75
- _("foo || bar && baz")
76
- .must_be_parsed_as s(:or,
77
- s(:call, nil, :foo),
78
- s(:and,
79
- s(:call, nil, :bar),
80
- s(:call, nil, :baz)))
81
- end
82
-
83
- it "handles :|| with parentheses" do
84
- _("(foo || bar) || baz")
85
- .must_be_parsed_as s(:or,
86
- s(:or,
87
- s(:call, nil, :foo),
88
- s(:call, nil, :bar)),
89
- s(:call, nil, :baz))
90
- end
91
-
92
- it "handles nested :|| with parentheses" do
93
- _("foo || (bar || baz) || qux")
94
- .must_be_parsed_as s(:or,
95
- s(:call, nil, :foo),
96
- s(:or,
97
- s(:or, s(:call, nil, :bar), s(:call, nil, :baz)),
98
- s(:call, nil, :qux)))
99
- end
100
-
101
- it "converts :|| to :or" do
102
- _("foo || bar")
103
- .must_be_parsed_as s(:or,
104
- s(:call, nil, :foo),
105
- s(:call, nil, :bar))
106
- end
107
-
108
- it "handles triple :and" do
109
- _("foo and bar and baz and qux")
110
- .must_be_parsed_as s(:and,
111
- s(:call, nil, :foo),
112
- s(:and,
113
- s(:call, nil, :bar),
114
- s(:and,
115
- s(:call, nil, :baz),
116
- s(:call, nil, :qux))))
117
- end
118
-
119
- it "handles triple :&&" do
120
- _("foo && bar && baz && qux")
121
- .must_be_parsed_as s(:and,
122
- s(:call, nil, :foo),
123
- s(:and,
124
- s(:call, nil, :bar),
125
- s(:and,
126
- s(:call, nil, :baz),
127
- s(:call, nil, :qux))))
128
- end
129
-
130
- it "handles :!=" do
131
- _("foo != bar")
132
- .must_be_parsed_as s(:call,
133
- s(:call, nil, :foo),
134
- :!=,
135
- s(:call, nil, :bar))
136
- end
137
-
138
- it "keeps :begin for the first argument of a binary operator" do
139
- _("begin; bar; end + foo")
140
- .must_be_parsed_as s(:call,
141
- s(:begin, s(:call, nil, :bar)),
142
- :+,
143
- s(:call, nil, :foo))
144
- end
145
-
146
- it "keeps :begin for the second argument of a binary operator" do
147
- _("foo + begin; bar; end")
148
- .must_be_parsed_as s(:call,
149
- s(:call, nil, :foo),
150
- :+,
151
- s(:begin, s(:call, nil, :bar)))
152
- end
153
-
154
- it "does not keep :begin for the first argument of a boolean operator" do
155
- _("begin; bar; end and foo")
156
- .must_be_parsed_as s(:and,
157
- s(:call, nil, :bar),
158
- s(:call, nil, :foo))
159
- end
160
-
161
- it "keeps :begin for the second argument of a boolean operator" do
162
- _("foo and begin; bar; end")
163
- .must_be_parsed_as s(:and,
164
- s(:call, nil, :foo),
165
- s(:begin, s(:call, nil, :bar)))
166
- end
167
-
168
- it "does not keep :begin for the first argument of a shift operator" do
169
- _("begin; bar; end << foo")
170
- .must_be_parsed_as s(:call,
171
- s(:call, nil, :bar),
172
- :<<,
173
- s(:call, nil, :foo))
174
- end
175
-
176
- it "does not keep :begin for the second argument of a shift operator" do
177
- _("foo >> begin; bar; end")
178
- .must_be_parsed_as s(:call,
179
- s(:call, nil, :foo),
180
- :>>,
181
- s(:call, nil, :bar))
182
- end
183
- end
184
-
185
- describe "for the range operator" do
186
- it "handles positive number literals" do
187
- _("1..2")
188
- .must_be_parsed_as s(:lit, 1..2)
189
- end
190
-
191
- it "handles negative number literals" do
192
- _("-1..-2")
193
- .must_be_parsed_as s(:lit, -1..-2)
194
- end
195
-
196
- it "handles float literals" do
197
- _("1.0..2.0")
198
- .must_be_parsed_as s(:dot2,
199
- s(:lit, 1.0),
200
- s(:lit, 2.0))
201
- end
202
-
203
- it "handles string literals" do
204
- _("'a'..'z'")
205
- .must_be_parsed_as s(:dot2,
206
- s(:str, "a"),
207
- s(:str, "z"))
208
- end
209
-
210
- it "handles non-literal begin" do
211
- _("foo..3")
212
- .must_be_parsed_as s(:dot2,
213
- s(:call, nil, :foo),
214
- s(:lit, 3))
215
- end
216
-
217
- it "handles non-literal end" do
218
- _("3..foo")
219
- .must_be_parsed_as s(:dot2,
220
- s(:lit, 3),
221
- s(:call, nil, :foo))
222
- end
223
-
224
- it "handles non-literals" do
225
- _("foo..bar")
226
- .must_be_parsed_as s(:dot2,
227
- s(:call, nil, :foo),
228
- s(:call, nil, :bar))
229
- end
230
-
231
- it "handles endless range literals" do
232
- skip "This Ruby version does not support endless ranges" if RUBY_VERSION < "2.6.0"
233
- _("1..")
234
- .must_be_parsed_as s(:dot2, s(:lit, 1), nil)
235
- end
236
- end
237
-
238
- describe "for the exclusive range operator" do
239
- it "handles positive number literals" do
240
- _("1...2")
241
- .must_be_parsed_as s(:lit, 1...2)
242
- end
243
-
244
- it "handles negative number literals" do
245
- _("-1...-2")
246
- .must_be_parsed_as s(:lit, -1...-2)
247
- end
248
-
249
- it "handles float literals" do
250
- _("1.0...2.0")
251
- .must_be_parsed_as s(:dot3,
252
- s(:lit, 1.0),
253
- s(:lit, 2.0))
254
- end
255
-
256
- it "handles string literals" do
257
- _("'a'...'z'")
258
- .must_be_parsed_as s(:dot3,
259
- s(:str, "a"),
260
- s(:str, "z"))
261
- end
262
-
263
- it "handles non-literal begin" do
264
- _("foo...3")
265
- .must_be_parsed_as s(:dot3,
266
- s(:call, nil, :foo),
267
- s(:lit, 3))
268
- end
269
-
270
- it "handles non-literal end" do
271
- _("3...foo")
272
- .must_be_parsed_as s(:dot3,
273
- s(:lit, 3),
274
- s(:call, nil, :foo))
275
- end
276
-
277
- it "handles two non-literals" do
278
- _("foo...bar")
279
- .must_be_parsed_as s(:dot3,
280
- s(:call, nil, :foo),
281
- s(:call, nil, :bar))
282
- end
283
- end
284
-
285
- describe "for unary operators" do
286
- it "handles unary minus with an integer literal" do
287
- _("- 1").must_be_parsed_as s(:call, s(:lit, 1), :-@)
288
- end
289
-
290
- it "handles unary minus with a float literal" do
291
- _("- 3.14").must_be_parsed_as s(:call, s(:lit, 3.14), :-@)
292
- end
293
-
294
- it "handles unary minus with a non-literal" do
295
- _("-foo")
296
- .must_be_parsed_as s(:call,
297
- s(:call, nil, :foo),
298
- :-@)
299
- end
300
-
301
- it "handles unary minus with a negative number literal" do
302
- _("- -1").must_be_parsed_as s(:call, s(:lit, -1), :-@)
303
- end
304
-
305
- it "handles unary plus with a number literal" do
306
- _("+ 1").must_be_parsed_as s(:call, s(:lit, 1), :+@)
307
- end
308
-
309
- it "handles unary plus with a non-literal" do
310
- _("+foo")
311
- .must_be_parsed_as s(:call,
312
- s(:call, nil, :foo),
313
- :+@)
314
- end
315
-
316
- it "handles unary !" do
317
- _("!foo")
318
- .must_be_parsed_as s(:call, s(:call, nil, :foo), :!)
319
- end
320
-
321
- it "converts :not to :!" do
322
- _("not foo")
323
- .must_be_parsed_as s(:call, s(:call, nil, :foo), :!)
324
- end
325
-
326
- it "handles unary ! with a number literal" do
327
- _("!1")
328
- .must_be_parsed_as s(:call, s(:lit, 1), :!)
329
- end
330
-
331
- it "keeps :begin for the argument" do
332
- _("- begin; foo; end")
333
- .must_be_parsed_as s(:call,
334
- s(:begin, s(:call, nil, :foo)),
335
- :-@)
336
- end
337
- end
338
-
339
- describe "for the ternary operater" do
340
- it "works in the simple case" do
341
- _("foo ? bar : baz")
342
- .must_be_parsed_as s(:if,
343
- s(:call, nil, :foo),
344
- s(:call, nil, :bar),
345
- s(:call, nil, :baz))
346
- end
347
-
348
- it "keeps :begin for the first argument" do
349
- _("begin; foo; end ? bar : baz")
350
- .must_be_parsed_as s(:if,
351
- s(:begin, s(:call, nil, :foo)),
352
- s(:call, nil, :bar),
353
- s(:call, nil, :baz))
354
- end
355
-
356
- it "keeps :begin for the second argument" do
357
- _("foo ? begin; bar; end : baz")
358
- .must_be_parsed_as s(:if,
359
- s(:call, nil, :foo),
360
- s(:begin, s(:call, nil, :bar)),
361
- s(:call, nil, :baz))
362
- end
363
-
364
- it "keeps :begin for the third argument" do
365
- _("foo ? bar : begin; baz; end")
366
- .must_be_parsed_as s(:if,
367
- s(:call, nil, :foo),
368
- s(:call, nil, :bar),
369
- s(:begin, s(:call, nil, :baz)))
370
- end
371
- end
372
-
373
- describe "for match operators" do
374
- it "handles :=~ with two non-literals" do
375
- _("foo =~ bar")
376
- .must_be_parsed_as s(:call,
377
- s(:call, nil, :foo),
378
- :=~,
379
- s(:call, nil, :bar))
380
- end
381
-
382
- it "handles :=~ with literal regexp on the left hand side" do
383
- _("/foo/ =~ bar")
384
- .must_be_parsed_as s(:match2,
385
- s(:lit, /foo/),
386
- s(:call, nil, :bar))
387
- end
388
-
389
- it "handles :=~ with literal regexp on the right hand side" do
390
- _("foo =~ /bar/")
391
- .must_be_parsed_as s(:match3,
392
- s(:lit, /bar/),
393
- s(:call, nil, :foo))
394
- end
395
-
396
- it "handles negated match operators" do
397
- _("foo !~ bar").must_be_parsed_as s(:not,
398
- s(:call,
399
- s(:call, nil, :foo),
400
- :=~,
401
- s(:call, nil, :bar)))
402
- end
403
- end
404
- end
405
- end