ruby_parser 3.13.0 → 3.13.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,6 +30,25 @@ module TestRubyParserShared
30
30
 
31
31
  BLOCK_DUP_MSG = "Both block arg and actual block given."
32
32
 
33
+ def test_bug191
34
+ pt = s(:if, s(:call, nil, :a), s(:str, ""), s(:call, nil, :b))
35
+
36
+ rb = "a ? '': b"
37
+ assert_parse rb, pt
38
+
39
+ rb = "a ? \"\": b"
40
+ assert_parse rb, pt
41
+ end
42
+
43
+ def test_bug202
44
+ rb = "$测试 = 1\n测试 = 1"
45
+ pt = s(:block,
46
+ s(:gasgn, :$测试, s(:lit, 1)),
47
+ s(:lasgn, :测试, s(:lit, 1)))
48
+
49
+ assert_parse rb, pt
50
+ end
51
+
33
52
  def test_double_block_error_01
34
53
  assert_syntax_error "a(1, &b) { }", BLOCK_DUP_MSG
35
54
  end
@@ -499,6 +518,14 @@ module TestRubyParserShared
499
518
  assert_parse rb, pt
500
519
  end
501
520
 
521
+ def test_str_evstr_escape
522
+ char = [0x00bd].pack("U")
523
+ rb = "\"a #\{b}\\302\\275\""
524
+ pt = s(:dstr, "a ", s(:evstr, s(:call, nil, :b)), s(:str, char))
525
+
526
+ assert_parse rb, pt
527
+ end
528
+
502
529
  def test_dsym_to_sym
503
530
  pt = s(:alias, s(:lit, :<<), s(:lit, :>>))
504
531
 
@@ -525,6 +552,10 @@ module TestRubyParserShared
525
552
  # TODO: add more including interpolation etc
526
553
  end
527
554
 
555
+ def test_regexp_escape_extended
556
+ assert_parse '/\“/', s(:lit, /“/)
557
+ end
558
+
528
559
  def test_label_vs_string
529
560
  rb = "_buf << ':\n'"
530
561
  pt = s(:call, s(:call, nil, :_buf), :<<, s(:str, ":\n"))
@@ -702,8 +733,6 @@ module TestRubyParserShared
702
733
  end
703
734
 
704
735
  def test_parse_line_dstr_newline
705
- skip "dstr line numbers are just gonna be screwed for a while..."
706
-
707
736
  rb = <<-'CODE'
708
737
  "a\n#{
709
738
  }"
@@ -1259,6 +1288,16 @@ module TestRubyParserShared
1259
1288
  assert_parse rb, pt
1260
1289
  end
1261
1290
 
1291
+ def test_lasgn_call_bracket_rescue_arg
1292
+ rb = "a = b(1) rescue 2"
1293
+ pt = s(:lasgn, :a,
1294
+ s(:rescue,
1295
+ s(:call, nil, :b, s(:lit, 1)),
1296
+ s(:resbody, s(:array), s(:lit, 2))))
1297
+
1298
+ assert_parse rb, pt
1299
+ end
1300
+
1262
1301
  def test_call_bang_squiggle
1263
1302
  rb = "1 !~ 2"
1264
1303
  pt = s(:not, s(:call, s(:lit, 1), :=~, s(:lit, 2))) # TODO: check for 1.9+
@@ -1554,6 +1593,20 @@ module TestRubyParserShared
1554
1593
  assert_parse rb, pt
1555
1594
  end
1556
1595
 
1596
+ def test_heredoc_bad_hex_escape
1597
+ rb = "s = <<eos\na\\xE9b\neos"
1598
+ pt = s(:lasgn, :s, s(:str, "a\xE9b\n".b))
1599
+
1600
+ assert_parse rb, pt
1601
+ end
1602
+
1603
+ def test_heredoc_bad_oct_escape
1604
+ rb = "s = <<-EOS\na\\247b\ncöd\nEOS\n"
1605
+ pt = s(:lasgn, :s, s(:str, "a\xa7b\nc\xc3\xb6d\n".b))
1606
+
1607
+ assert_parse rb, pt
1608
+ end
1609
+
1557
1610
  def test_masgn_double_paren
1558
1611
  rb = "((a,b))=c" # TODO: blog
1559
1612
  pt = s(:masgn,
@@ -1708,6 +1761,22 @@ module TestRubyParserShared
1708
1761
 
1709
1762
  assert_parse rb, pt
1710
1763
  end
1764
+
1765
+ def test_str_interp_ternary_or_label
1766
+ env = processor.env
1767
+ env[:a] = :lvar
1768
+
1769
+ rb = '"#{a.b? ? ""+a+"": ""}"'
1770
+ pt = s(:dstr,
1771
+ "",
1772
+ s(:evstr,
1773
+ s(:if,
1774
+ s(:call, s(:lvar, :a), :b?),
1775
+ s(:call, s(:call, s(:str, ""), :+, s(:lvar, :a)), :+, s(:str, "")),
1776
+ s(:str, ""))))
1777
+
1778
+ assert_parse rb, pt
1779
+ end
1711
1780
  end
1712
1781
 
1713
1782
  module TestRubyParserShared19Plus
@@ -2537,10 +2606,8 @@ module TestRubyParserShared19Plus
2537
2606
  end
2538
2607
 
2539
2608
  def test_pipe_semicolon
2540
- skip "not yet"
2541
-
2542
2609
  rb = "a.b do | ; c | end"
2543
- pt = s(:iter, s(:call, s(:call, nil, :a), :b), 0)
2610
+ pt = s(:iter, s(:call, s(:call, nil, :a), :b), s(:args, s(:shadow, :c)))
2544
2611
 
2545
2612
  assert_parse rb, pt
2546
2613
  end
@@ -2648,10 +2715,13 @@ module TestRubyParserShared19Plus
2648
2715
  end
2649
2716
 
2650
2717
  def test_kill_me5
2651
- skip "not yet"
2652
-
2653
2718
  rb = "f ->() { g do end }"
2654
- pt = 42
2719
+ pt = s(:call, nil, :f,
2720
+ s(:iter,
2721
+ s(:call, nil, :lambda),
2722
+ s(:args),
2723
+ s(:iter, s(:call, nil, :g), 0)))
2724
+
2655
2725
 
2656
2726
  assert_parse rb, pt
2657
2727
  end
@@ -2664,8 +2734,6 @@ module TestRubyParserShared19Plus
2664
2734
  end
2665
2735
 
2666
2736
  def test_iter_args_5
2667
- skip "not yet"
2668
-
2669
2737
  rb = "f { |a, &b| }"
2670
2738
  pt = s(:iter, s(:call, nil, :f), s(:args, :a, :"&b"))
2671
2739
 
@@ -3264,8 +3332,6 @@ module TestRubyParserShared21Plus
3264
3332
  end
3265
3333
 
3266
3334
  def test_parse_line_heredoc_hardnewline
3267
- skip "not yet"
3268
-
3269
3335
  rb = <<-'CODE'.gsub(/^ /, '')
3270
3336
  <<-EOFOO
3271
3337
  \n\n\n\n\n\n\n\n\n
@@ -3286,6 +3352,13 @@ end
3286
3352
  module TestRubyParserShared22Plus
3287
3353
  include TestRubyParserShared21Plus
3288
3354
 
3355
+ def test_bug_hash_interp_array
3356
+ rp = '{ "#{}": [] }'
3357
+ pt = s(:hash, s(:dsym, "", s(:evstr)), s(:array))
3358
+
3359
+ assert_parse rp, pt
3360
+ end
3361
+
3289
3362
  def test_call_args_assoc_quoted
3290
3363
  pt = s(:call, nil, :x, s(:hash, s(:lit, :k), s(:lit, 42)))
3291
3364
 
@@ -3301,16 +3374,6 @@ module TestRubyParserShared22Plus
3301
3374
  assert_parse rb, pt
3302
3375
  end
3303
3376
 
3304
- def test_bug191
3305
- pt = s(:if, s(:call, nil, :a), s(:str, ""), s(:call, nil, :b))
3306
-
3307
- rb = "a ? '': b"
3308
- assert_parse rb, pt
3309
-
3310
- rb = "a ? \"\": b"
3311
- assert_parse rb, pt
3312
- end
3313
-
3314
3377
  def test_quoted_symbol_keys
3315
3378
  rb = "{ 'a': :b }"
3316
3379
  pt = s(:hash, s(:lit, :a), s(:lit, :b))
@@ -3329,6 +3392,13 @@ end
3329
3392
  module TestRubyParserShared23Plus
3330
3393
  include TestRubyParserShared22Plus
3331
3394
 
3395
+ def test_bug_215
3396
+ rb = 'undef %s(foo)'
3397
+ pt = s(:undef, s(:lit, :foo))
3398
+
3399
+ assert_parse rb, pt
3400
+ end
3401
+
3332
3402
  def test_safe_call
3333
3403
  rb = "a&.b"
3334
3404
  pt = s(:safe_call, s(:call, nil, :a), :b)
@@ -3406,6 +3476,41 @@ module TestRubyParserShared23Plus
3406
3476
  assert_parse rb, pt
3407
3477
  end
3408
3478
 
3479
+ def test_const_op_asgn_or
3480
+ rb = "X::Y ||= 1"
3481
+ pt = s(:op_asgn_or, s(:colon2, s(:const, :X), :Y), s(:lit, 1))
3482
+
3483
+ assert_parse rb, pt
3484
+ end
3485
+
3486
+ def test_const_2_op_asgn_or2
3487
+ rb = "::X::Y ||= 1"
3488
+ pt = s(:op_asgn_or, s(:colon2, s(:colon3, :X), :Y), s(:lit, 1))
3489
+
3490
+ assert_parse rb, pt
3491
+ end
3492
+
3493
+ def test_const_3_op_asgn_or
3494
+ rb = "::X ||= 1"
3495
+ pt = s(:op_asgn_or, s(:colon3, :X), s(:lit, 1))
3496
+
3497
+ assert_parse rb, pt
3498
+ end
3499
+
3500
+ def test_const_op_asgn_and2
3501
+ rb = "::X &&= 1"
3502
+ pt = s(:op_asgn_and, s(:colon3, :X), s(:lit, 1))
3503
+
3504
+ assert_parse rb, pt
3505
+ end
3506
+
3507
+ def test_const_op_asgn_and1
3508
+ rb = "::X &= 1"
3509
+ pt = s(:op_asgn, s(:colon3, :X), :"&", s(:lit, 1))
3510
+
3511
+ assert_parse rb, pt
3512
+ end
3513
+
3409
3514
  def test_ruby21_numbers
3410
3515
  rb = "[1i, 2r, 3ri]"
3411
3516
  pt = s(:array, s(:lit, Complex(0, 1)), s(:lit, Rational(2)), s(:lit, Complex(0, Rational(3))))
@@ -3468,7 +3573,15 @@ end
3468
3573
  module TestRubyParserShared24Plus
3469
3574
  include TestRubyParserShared23Plus
3470
3575
 
3471
- # ...version specific tests to go here...
3576
+ def test_lasgn_call_nobracket_rescue_arg
3577
+ rb = "a = b 1 rescue 2"
3578
+ pt = s(:lasgn, :a,
3579
+ s(:rescue,
3580
+ s(:call, nil, :b, s(:lit, 1)),
3581
+ s(:resbody, s(:array), s(:lit, 2))))
3582
+
3583
+ assert_parse rb, pt
3584
+ end
3472
3585
  end
3473
3586
 
3474
3587
  module TestRubyParserShared25Plus
@@ -3591,7 +3704,11 @@ class RubyParserTestCase < ParseTreeTestCase
3591
3704
  end
3592
3705
  end
3593
3706
 
3594
- assert_equal emsg, e.message
3707
+ if Regexp === emsg then
3708
+ assert_match emsg, e.message
3709
+ else
3710
+ assert_equal emsg, e.message
3711
+ end
3595
3712
  end
3596
3713
 
3597
3714
  def assert_parse_line rb, pt, line
@@ -3643,6 +3760,15 @@ class TestRubyParserV23 < RubyParserTestCase
3643
3760
 
3644
3761
  self.processor = RubyParser::V23.new
3645
3762
  end
3763
+
3764
+ def test_lasgn_call_nobracket_rescue_arg
3765
+ rb = "a = b 1 rescue 2"
3766
+ pt = s(:rescue,
3767
+ s(:lasgn, :a, s(:call, nil, :b, s(:lit, 1))),
3768
+ s(:resbody, s(:array), s(:lit, 2)))
3769
+
3770
+ assert_parse rb, pt
3771
+ end
3646
3772
  end
3647
3773
 
3648
3774
  class TestRubyParserV24 < RubyParserTestCase
@@ -3653,6 +3779,17 @@ class TestRubyParserV24 < RubyParserTestCase
3653
3779
 
3654
3780
  self.processor = RubyParser::V24.new
3655
3781
  end
3782
+
3783
+ def test_rescue_parens
3784
+ rb = "a (b rescue c)"
3785
+ pt = s(:call, nil, :a,
3786
+ s(:rescue, s(:call, nil, :b),
3787
+ s(:resbody, s(:array), s(:call, nil, :c))))
3788
+
3789
+ assert_parse rb, pt
3790
+
3791
+ assert_parse_error "a(b rescue c)", /parse error on value ..rescue/
3792
+ end
3656
3793
  end
3657
3794
 
3658
3795
  class TestRubyParserV25 < RubyParserTestCase
@@ -107,6 +107,7 @@ def munge s
107
107
 
108
108
  '"defined?"', "kDEFINED",
109
109
 
110
+ "<none>", "none",
110
111
 
111
112
  '"do (for condition)"', "kDO_COND",
112
113
  '"do (for lambda)"', "kDO_LAMBDA",
@@ -167,7 +168,7 @@ ARGF.each_line do |line|
167
168
  item = $1
168
169
  stack << munge(item)
169
170
  when /^-> \$\$ = (?:token|nterm) (.+) \(.*\)/ then
170
- stack << "<none>" if stack.empty?
171
+ stack << "none" if stack.empty?
171
172
  item = munge $1
172
173
  x = stack.map { |s| s.strip }.join " "
173
174
  if x != item then # prevent kdef -> kdef
@@ -6,8 +6,13 @@ $p ||= false
6
6
  require "ripper/sexp"
7
7
  require "pp" if $p
8
8
 
9
+ if ARGV.empty? then
10
+ warn "reading from stdin"
11
+ ARGV << "-"
12
+ end
13
+
9
14
  ARGV.each do |path|
10
- src = File.read path
15
+ src = path == "-" ? $stdin.read : File.read(path)
11
16
  rip = Ripper::SexpBuilderPP.new src
12
17
  rip.yydebug = $d
13
18
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.13.0
4
+ version: 3.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -29,7 +29,7 @@ cert_chain:
29
29
  Em82dBUFsipwMLCYj39kcyHWAxyl6Ae1Cn9r/ItVBCxoeFdrHjfavnrIEoXUt4bU
30
30
  UfBugfLD19bu3nvL+zTAGx/U
31
31
  -----END CERTIFICATE-----
32
- date: 2019-03-13 00:00:00.000000000 Z
32
+ date: 2019-03-26 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: sexp_processor
metadata.gz.sig CHANGED
Binary file