ruby_parser 3.14.0 → 3.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/History.rdoc +78 -0
- data/Manifest.txt +4 -0
- data/Rakefile +50 -13
- data/bin/ruby_parse_extract_error +8 -3
- data/compare/normalize.rb +45 -5
- data/debugging.md +172 -0
- data/lib/ruby20_parser.rb +3378 -3353
- data/lib/ruby20_parser.y +99 -64
- data/lib/ruby21_parser.rb +3438 -3411
- data/lib/ruby21_parser.y +99 -64
- data/lib/ruby22_parser.rb +3445 -3414
- data/lib/ruby22_parser.y +99 -64
- data/lib/ruby23_parser.rb +3395 -3367
- data/lib/ruby23_parser.y +99 -64
- data/lib/ruby24_parser.rb +3443 -3407
- data/lib/ruby24_parser.y +99 -64
- data/lib/ruby25_parser.rb +3442 -3407
- data/lib/ruby25_parser.y +99 -64
- data/lib/ruby26_parser.rb +3380 -3343
- data/lib/ruby26_parser.y +100 -64
- data/lib/ruby27_parser.rb +7310 -0
- data/lib/ruby27_parser.y +2677 -0
- data/lib/ruby30_parser.rb +7310 -0
- data/lib/ruby30_parser.y +2677 -0
- data/lib/ruby_lexer.rb +94 -43
- data/lib/ruby_lexer.rex +6 -7
- data/lib/ruby_lexer.rex.rb +7 -9
- data/lib/ruby_parser.rb +4 -0
- data/lib/ruby_parser.yy +122 -64
- data/lib/ruby_parser_extras.rb +52 -23
- data/test/test_ruby_lexer.rb +80 -16
- data/test/test_ruby_parser.rb +259 -4
- data/tools/munge.rb +9 -4
- metadata +57 -36
- metadata.gz.sig +2 -2
data/test/test_ruby_lexer.rb
CHANGED
@@ -1,7 +1,3 @@
|
|
1
|
-
# encoding: US-ASCII
|
2
|
-
|
3
|
-
# TODO: work this out
|
4
|
-
|
5
1
|
require "minitest/autorun"
|
6
2
|
require "ruby_lexer"
|
7
3
|
require "ruby_parser"
|
@@ -84,10 +80,12 @@ class TestRubyLexer < Minitest::Test
|
|
84
80
|
assert_in_epsilon value, act_value, 0.001, msg
|
85
81
|
when NilClass then
|
86
82
|
assert_nil act_value, msg
|
83
|
+
when String then
|
84
|
+
assert_equal value, act_value.b.force_encoding(value.encoding), msg
|
87
85
|
else
|
88
86
|
assert_equal value, act_value, msg
|
89
87
|
end
|
90
|
-
|
88
|
+
assert_match state, @lex.lex_state, msg if state
|
91
89
|
assert_equal paren, @lex.paren_nest, msg if paren
|
92
90
|
assert_equal brace, @lex.brace_nest, msg if brace
|
93
91
|
end
|
@@ -98,7 +96,8 @@ class TestRubyLexer < Minitest::Test
|
|
98
96
|
|
99
97
|
def assert_read_escape expected, input
|
100
98
|
@lex.ss.string = input.dup
|
101
|
-
|
99
|
+
enc = expected.encoding
|
100
|
+
assert_equal expected, @lex.read_escape.b.force_encoding(enc), input
|
102
101
|
end
|
103
102
|
|
104
103
|
def assert_read_escape_bad input # TODO: rename refute_read_escape
|
@@ -146,7 +145,7 @@ class TestRubyLexer < Minitest::Test
|
|
146
145
|
yield
|
147
146
|
|
148
147
|
lexer.lex_state = EXPR_ENDARG
|
149
|
-
assert_next_lexeme :tSTRING_DEND, "}", EXPR_END, 0
|
148
|
+
assert_next_lexeme :tSTRING_DEND, "}", EXPR_END|EXPR_ENDARG, 0
|
150
149
|
|
151
150
|
lexer.lex_strterm = lex_strterm
|
152
151
|
lexer.lex_state = EXPR_BEG
|
@@ -479,6 +478,22 @@ class TestRubyLexer < Minitest::Test
|
|
479
478
|
assert_lex3("!~", nil, :tNMATCH, "!~", EXPR_BEG)
|
480
479
|
end
|
481
480
|
|
481
|
+
def test_yylex_bdot2
|
482
|
+
assert_lex3("..42",
|
483
|
+
nil, # TODO: s(:dot2, nil, s(:lit, 42)),
|
484
|
+
|
485
|
+
:tBDOT2, "..", EXPR_BEG,
|
486
|
+
:tINTEGER, 42, EXPR_END|EXPR_ENDARG)
|
487
|
+
end
|
488
|
+
|
489
|
+
def test_yylex_bdot3
|
490
|
+
assert_lex3("...42",
|
491
|
+
nil, # TODO: s(:dot2, nil, s(:lit, 42)),
|
492
|
+
|
493
|
+
:tBDOT3, "...", EXPR_BEG,
|
494
|
+
:tINTEGER, 42, EXPR_END|EXPR_ENDARG)
|
495
|
+
end
|
496
|
+
|
482
497
|
def test_yylex_block_bug_1
|
483
498
|
assert_lex3("a do end",
|
484
499
|
s(:iter, s(:call, nil, :a), 0),
|
@@ -720,7 +735,7 @@ class TestRubyLexer < Minitest::Test
|
|
720
735
|
|
721
736
|
assert_lex3("do 42 end",
|
722
737
|
nil,
|
723
|
-
:
|
738
|
+
:kDO, "do", EXPR_BEG,
|
724
739
|
:tINTEGER, 42, EXPR_NUM,
|
725
740
|
:kEND, "end", EXPR_END)
|
726
741
|
end
|
@@ -750,10 +765,26 @@ class TestRubyLexer < Minitest::Test
|
|
750
765
|
end
|
751
766
|
|
752
767
|
def test_yylex_dot2
|
768
|
+
assert_lex3("1..2",
|
769
|
+
s(:lit, 1..2),
|
770
|
+
|
771
|
+
:tINTEGER, 1, EXPR_END|EXPR_ENDARG,
|
772
|
+
:tDOT2, "..", EXPR_BEG,
|
773
|
+
:tINTEGER, 2, EXPR_END|EXPR_ENDARG)
|
774
|
+
|
775
|
+
self.lex_state = EXPR_END|EXPR_ENDARG
|
753
776
|
assert_lex3("..", nil, :tDOT2, "..", EXPR_BEG)
|
754
777
|
end
|
755
778
|
|
756
779
|
def test_yylex_dot3
|
780
|
+
assert_lex3("1...2",
|
781
|
+
s(:lit, 1...2),
|
782
|
+
|
783
|
+
:tINTEGER, 1, EXPR_END|EXPR_ENDARG,
|
784
|
+
:tDOT3, "...", EXPR_BEG,
|
785
|
+
:tINTEGER, 2, EXPR_END|EXPR_ENDARG)
|
786
|
+
|
787
|
+
self.lex_state = EXPR_END|EXPR_ENDARG
|
757
788
|
assert_lex3("...", nil, :tDOT3, "...", EXPR_BEG)
|
758
789
|
end
|
759
790
|
|
@@ -926,6 +957,14 @@ class TestRubyLexer < Minitest::Test
|
|
926
957
|
assert_lex3("$1234", nil, :tGVAR, "$1234", EXPR_END)
|
927
958
|
end
|
928
959
|
|
960
|
+
def test_yylex_global_I_have_no_words
|
961
|
+
assert_lex3("$x\xE2\x80\x8B = 42", # zero width space?!?!?
|
962
|
+
nil,
|
963
|
+
:tGVAR, "$x\xE2\x80\x8B", EXPR_END,
|
964
|
+
:tEQL, "=", EXPR_BEG,
|
965
|
+
:tINTEGER, 42, EXPR_NUM)
|
966
|
+
end
|
967
|
+
|
929
968
|
def test_yylex_global_other
|
930
969
|
assert_lex3("[$~, $*, $$, $?, $!, $@, $/, $\\, $;, $,, $., $=, $:, $<, $>, $\"]",
|
931
970
|
nil,
|
@@ -1109,11 +1148,11 @@ class TestRubyLexer < Minitest::Test
|
|
1109
1148
|
:tEQL, "=", EXPR_BEG,
|
1110
1149
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
1111
1150
|
:tSTRING_CONTENT, "#x a ", EXPR_BEG,
|
1112
|
-
:tSTRING_DVAR, "
|
1151
|
+
:tSTRING_DVAR, "#", EXPR_BEG,
|
1113
1152
|
:tSTRING_CONTENT, "@a b ", EXPR_BEG, # HUH?
|
1114
|
-
:tSTRING_DVAR, "
|
1153
|
+
:tSTRING_DVAR, "#", EXPR_BEG,
|
1115
1154
|
:tSTRING_CONTENT, "$b c ", EXPR_BEG, # HUH?
|
1116
|
-
:tSTRING_DVAR, "
|
1155
|
+
:tSTRING_DVAR, "#", EXPR_BEG,
|
1117
1156
|
:tSTRING_CONTENT, "@@d ", EXPR_BEG, # HUH?
|
1118
1157
|
:tSTRING_DBEG, "\#{", EXPR_BEG,
|
1119
1158
|
:tSTRING_CONTENT, "3} \n", EXPR_BEG,
|
@@ -2099,6 +2138,10 @@ class TestRubyLexer < Minitest::Test
|
|
2099
2138
|
assert_lex3("?\\M-\\C-a", nil, :tSTRING, "\M-\C-a", EXPR_END)
|
2100
2139
|
end
|
2101
2140
|
|
2141
|
+
def test_yylex_question_control_escape
|
2142
|
+
assert_lex3('?\C-\]', nil, :tSTRING, ?\C-\], EXPR_END)
|
2143
|
+
end
|
2144
|
+
|
2102
2145
|
def test_yylex_question_ws
|
2103
2146
|
assert_lex3("? ", nil, :tEH, "?", EXPR_BEG)
|
2104
2147
|
assert_lex3("?\n", nil, :tEH, "?", EXPR_BEG)
|
@@ -2549,11 +2592,7 @@ class TestRubyLexer < Minitest::Test
|
|
2549
2592
|
end
|
2550
2593
|
|
2551
2594
|
def test_yylex_string_double_escape_c_backslash
|
2552
|
-
|
2553
|
-
nil,
|
2554
|
-
:tSTRING_BEG, "\"", EXPR_BEG,
|
2555
|
-
:tSTRING_CONTENT, "\034", EXPR_BEG,
|
2556
|
-
:tSTRING_END, "\"", EXPR_LIT)
|
2595
|
+
refute_lex("\"\\c\\\"", :tSTRING_BEG, '"')
|
2557
2596
|
end
|
2558
2597
|
|
2559
2598
|
def test_yylex_string_double_escape_c_escape
|
@@ -2657,6 +2696,22 @@ class TestRubyLexer < Minitest::Test
|
|
2657
2696
|
:tSTRING_END, "]", EXPR_LIT)
|
2658
2697
|
end
|
2659
2698
|
|
2699
|
+
def test_yylex_string_pct_Q_null_wtf?
|
2700
|
+
assert_lex3("%Q\0s1 s2\0",
|
2701
|
+
nil,
|
2702
|
+
:tSTRING_BEG, "%Q\0", EXPR_BEG,
|
2703
|
+
:tSTRING_CONTENT, "s1 s2", EXPR_BEG,
|
2704
|
+
:tSTRING_END, "\0", EXPR_LIT)
|
2705
|
+
end
|
2706
|
+
|
2707
|
+
def test_yylex_string_pct_Q_bang
|
2708
|
+
assert_lex3("%Q!s1 s2!",
|
2709
|
+
nil,
|
2710
|
+
:tSTRING_BEG, "%Q\0", EXPR_BEG,
|
2711
|
+
:tSTRING_CONTENT, "s1 s2", EXPR_BEG,
|
2712
|
+
:tSTRING_END, "!", EXPR_LIT)
|
2713
|
+
end
|
2714
|
+
|
2660
2715
|
def test_yylex_string_pct_W
|
2661
2716
|
assert_lex3("%W[s1 s2\ns3]", # TODO: add interpolation to these
|
2662
2717
|
nil,
|
@@ -2831,6 +2886,15 @@ class TestRubyLexer < Minitest::Test
|
|
2831
2886
|
:tSTRING_END, '"')
|
2832
2887
|
end
|
2833
2888
|
|
2889
|
+
def test_yylex_string_utf8_bad_encoding_with_escapes
|
2890
|
+
str = "\"\\xBADπ\""
|
2891
|
+
exp = "\xBADπ".b
|
2892
|
+
|
2893
|
+
assert_lex(str,
|
2894
|
+
s(:str, exp),
|
2895
|
+
:tSTRING, exp, EXPR_END)
|
2896
|
+
end
|
2897
|
+
|
2834
2898
|
def test_yylex_string_utf8_complex_trailing_hex
|
2835
2899
|
chr = [0x3024].pack("U")
|
2836
2900
|
str = "#{chr}abz"
|
data/test/test_ruby_parser.rb
CHANGED
@@ -162,6 +162,16 @@ module TestRubyParserShared
|
|
162
162
|
assert_parse rb, pt
|
163
163
|
end
|
164
164
|
|
165
|
+
def test_backticks_interpolation_line
|
166
|
+
rb = 'x `#{y}`'
|
167
|
+
pt = s(:call, nil, :x,
|
168
|
+
s(:dxstr, "",
|
169
|
+
s(:evstr,
|
170
|
+
s(:call, nil, :y).line(1)).line(1))).line(1)
|
171
|
+
|
172
|
+
assert_parse rb, pt
|
173
|
+
end
|
174
|
+
|
165
175
|
def test_bang_eq
|
166
176
|
rb = "1 != 2"
|
167
177
|
pt = s(:not, s(:call, s(:lit, 1), :"==", s(:lit, 2)))
|
@@ -175,6 +185,57 @@ module TestRubyParserShared
|
|
175
185
|
assert_syntax_error rb, "else without rescue is useless"
|
176
186
|
end
|
177
187
|
|
188
|
+
def test_begin_ensure_no_bodies
|
189
|
+
rb = "begin\nensure\nend"
|
190
|
+
pt = s(:ensure, s(:nil).line(2)).line(2)
|
191
|
+
|
192
|
+
assert_parse rb, pt
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_begin_rescue_ensure_no_bodies
|
196
|
+
rb = "begin\nrescue\nensure\nend"
|
197
|
+
pt = s(:ensure,
|
198
|
+
s(:rescue,
|
199
|
+
s(:resbody, s(:array).line(2),
|
200
|
+
nil).line(2)
|
201
|
+
).line(2),
|
202
|
+
s(:nil).line(3)
|
203
|
+
).line(2)
|
204
|
+
|
205
|
+
assert_parse rb, pt
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_begin_rescue_else_ensure_bodies
|
209
|
+
rb = "begin\n 1\nrescue\n 2\nelse\n 3\nensure\n 4\nend"
|
210
|
+
pt = s(:ensure,
|
211
|
+
s(:rescue,
|
212
|
+
s(:lit, 1).line(2),
|
213
|
+
s(:resbody, s(:array).line(3),
|
214
|
+
s(:lit, 2).line(4)).line(3),
|
215
|
+
s(:lit, 3).line(6)).line(2),
|
216
|
+
s(:lit, 4).line(8)).line(2)
|
217
|
+
|
218
|
+
s(:ensure, s(:rescue, s(:resbody, s(:array), nil)), s(:nil))
|
219
|
+
|
220
|
+
assert_parse rb, pt
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_begin_rescue_else_ensure_no_bodies
|
224
|
+
rb = "begin\n\nrescue\n\nelse\n\nensure\n\nend"
|
225
|
+
pt = s(:ensure,
|
226
|
+
s(:rescue,
|
227
|
+
s(:resbody, s(:array).line(3),
|
228
|
+
# TODO: s(:nil)
|
229
|
+
nil
|
230
|
+
).line(3),
|
231
|
+
).line(3),
|
232
|
+
s(:nil).line(7)).line(3)
|
233
|
+
|
234
|
+
s(:ensure, s(:rescue, s(:resbody, s(:array), nil)), s(:nil))
|
235
|
+
|
236
|
+
assert_parse rb, pt
|
237
|
+
end
|
238
|
+
|
178
239
|
def test_block_append
|
179
240
|
head = s(:args).line 1
|
180
241
|
tail = s(:zsuper).line 2
|
@@ -280,7 +341,7 @@ module TestRubyParserShared
|
|
280
341
|
def test_bug190
|
281
342
|
skip "not ready for this yet"
|
282
343
|
|
283
|
-
rb = %{%r'
|
344
|
+
rb = %{%r'\\\''} # stupid emacs
|
284
345
|
|
285
346
|
assert_parse rb, :FUCK
|
286
347
|
assert_syntax_error rb, "FUCK"
|
@@ -862,6 +923,13 @@ module TestRubyParserShared
|
|
862
923
|
assert_parse rb, pt
|
863
924
|
end
|
864
925
|
|
926
|
+
def test_heredoc_with_extra_carriage_horrible_mix?
|
927
|
+
rb = "<<'eot'\r\nbody\r\neot\n"
|
928
|
+
pt = s(:str, "body\r\n")
|
929
|
+
|
930
|
+
assert_parse rb, pt
|
931
|
+
end
|
932
|
+
|
865
933
|
def test_heredoc_with_interpolation_and_carriage_return_escapes
|
866
934
|
rb = "<<EOS\nfoo\\r\#@bar\nEOS\n"
|
867
935
|
pt = s(:dstr, "foo\r", s(:evstr, s(:ivar, :@bar)), s(:str, "\n"))
|
@@ -890,6 +958,13 @@ module TestRubyParserShared
|
|
890
958
|
assert_parse rb, pt
|
891
959
|
end
|
892
960
|
|
961
|
+
def test_heredoc_with_not_global_interpolation
|
962
|
+
rb = "<<-HEREDOC\n#${\nHEREDOC"
|
963
|
+
pt = s(:str, "\#${\n")
|
964
|
+
|
965
|
+
assert_parse rb, pt
|
966
|
+
end
|
967
|
+
|
893
968
|
def test_i_fucking_hate_line_numbers
|
894
969
|
rb = <<-END.gsub(/^ {6}/, "")
|
895
970
|
if true
|
@@ -1242,6 +1317,20 @@ module TestRubyParserShared
|
|
1242
1317
|
end
|
1243
1318
|
end
|
1244
1319
|
|
1320
|
+
def test_magic_encoding_comment__bad
|
1321
|
+
rb = "#encoding: bunk\n0"
|
1322
|
+
pt = s(:lit, 0)
|
1323
|
+
|
1324
|
+
assert_parse rb, pt
|
1325
|
+
end
|
1326
|
+
|
1327
|
+
def test_utf8_bom
|
1328
|
+
rb = "\xEF\xBB\xBF#!/usr/bin/env ruby -w\np 0\n"
|
1329
|
+
pt = s(:call, nil, :p, s(:lit, 0))
|
1330
|
+
|
1331
|
+
assert_parse rb, pt
|
1332
|
+
end
|
1333
|
+
|
1245
1334
|
def test_masgn_arg_colon_arg
|
1246
1335
|
rb = "a, b::c = d"
|
1247
1336
|
pt = s(:masgn,
|
@@ -1373,13 +1462,43 @@ module TestRubyParserShared
|
|
1373
1462
|
assert_parse rb, pt
|
1374
1463
|
end
|
1375
1464
|
|
1376
|
-
def
|
1465
|
+
def test_op_asgn_primary_colon_identifier1
|
1377
1466
|
rb = "A::b += 1"
|
1378
1467
|
pt = s(:op_asgn, s(:const, :A), s(:lit, 1), :b, :+) # TODO: check? looks wack
|
1379
1468
|
|
1380
1469
|
assert_parse rb, pt
|
1381
1470
|
end
|
1382
1471
|
|
1472
|
+
def test_lasgn_middle_splat
|
1473
|
+
rb = "a = b, *c, d"
|
1474
|
+
pt = s(:lasgn, :a,
|
1475
|
+
s(:svalue,
|
1476
|
+
s(:array,
|
1477
|
+
s(:call, nil, :b),
|
1478
|
+
s(:splat, s(:call, nil, :c)),
|
1479
|
+
s(:call, nil, :d))))
|
1480
|
+
|
1481
|
+
assert_parse rb, pt
|
1482
|
+
end
|
1483
|
+
|
1484
|
+
def test_op_asgn_primary_colon_const_command_call
|
1485
|
+
rb = "A::B *= c d"
|
1486
|
+
pt = s(:op_asgn, s(:const, :A),
|
1487
|
+
s(:call, nil, :c, s(:call, nil, :d)),
|
1488
|
+
:B, :*)
|
1489
|
+
|
1490
|
+
assert_parse rb, pt
|
1491
|
+
end
|
1492
|
+
|
1493
|
+
def test_op_asgn_primary_colon_identifier_command_call
|
1494
|
+
rb = "A::b *= c d"
|
1495
|
+
pt = s(:op_asgn, s(:const, :A),
|
1496
|
+
s(:call, nil, :c, s(:call, nil, :d)),
|
1497
|
+
:b, :*)
|
1498
|
+
|
1499
|
+
assert_parse rb, pt
|
1500
|
+
end
|
1501
|
+
|
1383
1502
|
def test_op_asgn_val_dot_ident_command_call
|
1384
1503
|
rb = "a.b ||= c 1"
|
1385
1504
|
pt = s(:op_asgn, s(:call, nil, :a), s(:call, nil, :c, s(:lit, 1)), :b, :"||")
|
@@ -1514,6 +1633,13 @@ module TestRubyParserShared
|
|
1514
1633
|
assert_equal 2, c.line, "call should have line number"
|
1515
1634
|
end
|
1516
1635
|
|
1636
|
+
def test_parse_line_defn_no_parens_args
|
1637
|
+
rb = "def f a\nend"
|
1638
|
+
pt = s(:defn, :f, s(:args, :a).line(1), s(:nil).line(2)).line(1)
|
1639
|
+
|
1640
|
+
assert_parse_line rb, pt, 1
|
1641
|
+
end
|
1642
|
+
|
1517
1643
|
def test_parse_line_defn_complex
|
1518
1644
|
rb = "def x(y)\n p(y)\n y *= 2\n return y;\nend" # TODO: remove () & ;
|
1519
1645
|
pt = s(:defn, :x, s(:args, :y),
|
@@ -1530,7 +1656,7 @@ module TestRubyParserShared
|
|
1530
1656
|
end
|
1531
1657
|
|
1532
1658
|
def test_parse_line_defn_no_parens
|
1533
|
-
pt = s(:defn, :f, s(:args), s(:nil))
|
1659
|
+
pt = s(:defn, :f, s(:args).line(1), s(:nil)).line(1)
|
1534
1660
|
|
1535
1661
|
rb = "def f\nend"
|
1536
1662
|
assert_parse_line rb, pt, 1
|
@@ -2954,6 +3080,8 @@ module TestRubyParserShared19Plus
|
|
2954
3080
|
end
|
2955
3081
|
|
2956
3082
|
def test_motherfuckin_leading_dots
|
3083
|
+
skip if processor.class.version >= 27
|
3084
|
+
|
2957
3085
|
rb = "a\n.b"
|
2958
3086
|
pt = s(:call, s(:call, nil, :a), :b)
|
2959
3087
|
|
@@ -2961,6 +3089,8 @@ module TestRubyParserShared19Plus
|
|
2961
3089
|
end
|
2962
3090
|
|
2963
3091
|
def test_motherfuckin_leading_dots2
|
3092
|
+
skip if processor.class.version >= 27
|
3093
|
+
|
2964
3094
|
rb = "a\n..b"
|
2965
3095
|
|
2966
3096
|
assert_parse_error rb, '(string):2 :: parse error on value ".." (tDOT2)'
|
@@ -3271,6 +3401,76 @@ module TestRubyParserShared20Plus
|
|
3271
3401
|
assert_parse rb, pt
|
3272
3402
|
end
|
3273
3403
|
|
3404
|
+
def test_call_array_block_call
|
3405
|
+
rb = "a [ nil, b do end ]"
|
3406
|
+
pt = s(:call, nil, :a,
|
3407
|
+
s(:array,
|
3408
|
+
s(:nil),
|
3409
|
+
s(:iter, s(:call, nil, :b), 0)))
|
3410
|
+
|
3411
|
+
assert_parse rb, pt
|
3412
|
+
end
|
3413
|
+
|
3414
|
+
def test_block_call_paren_call_block_call
|
3415
|
+
rb = "a (b)\nc.d do end"
|
3416
|
+
pt = s(:block,
|
3417
|
+
s(:call, nil, :a, s(:call, nil, :b)),
|
3418
|
+
s(:iter, s(:call, s(:call, nil, :c), :d), 0))
|
3419
|
+
|
3420
|
+
|
3421
|
+
assert_parse rb, pt
|
3422
|
+
end
|
3423
|
+
|
3424
|
+
def test_block_call_defn_call_block_call
|
3425
|
+
rb = "a def b(c)\n d\n end\n e.f do end"
|
3426
|
+
pt = s(:block,
|
3427
|
+
s(:call, nil, :a,
|
3428
|
+
s(:defn, :b, s(:args, :c), s(:call, nil, :d))),
|
3429
|
+
s(:iter, s(:call, s(:call, nil, :e), :f), 0))
|
3430
|
+
|
3431
|
+
assert_parse rb, pt
|
3432
|
+
end
|
3433
|
+
|
3434
|
+
def test_call_array_lambda_block_call
|
3435
|
+
rb = "a [->() {}] do\nend"
|
3436
|
+
pt = s(:iter,
|
3437
|
+
s(:call, nil, :a,
|
3438
|
+
s(:array, s(:iter, s(:lambda), s(:args)))),
|
3439
|
+
0)
|
3440
|
+
|
3441
|
+
assert_parse rb, pt
|
3442
|
+
end
|
3443
|
+
|
3444
|
+
def test_call_begin_call_block_call
|
3445
|
+
rb = "a begin\nb.c do end\nend"
|
3446
|
+
pt = s(:call, nil, :a,
|
3447
|
+
s(:iter, s(:call, s(:call, nil, :b), :c), 0))
|
3448
|
+
|
3449
|
+
assert_parse rb, pt
|
3450
|
+
end
|
3451
|
+
|
3452
|
+
def test_messy_op_asgn_lineno
|
3453
|
+
rb = "a (B::C *= d e)"
|
3454
|
+
pt = s(:call, nil, :a,
|
3455
|
+
s(:op_asgn, s(:const, :B),
|
3456
|
+
s(:call, nil, :d, s(:call, nil, :e)),
|
3457
|
+
:C,
|
3458
|
+
:*)).line(1)
|
3459
|
+
|
3460
|
+
assert_parse rb, pt
|
3461
|
+
end
|
3462
|
+
|
3463
|
+
def test_str_lit_concat_bad_encodings
|
3464
|
+
rb = '"\xE3\xD3\x8B\xE3\x83\xBC\x83\xE3\x83\xE3\x82\xB3\xA3\x82\x99" \
|
3465
|
+
"\xE3\x83\xB3\xE3\x83\x8F\xE3\x82\x9A\xC3\xBD;foo@bar.com"'.b
|
3466
|
+
pt = s(:str, "\xE3\xD3\x8B\xE3\x83\xBC\x83\xE3\x83\xE3\x82\xB3\xA3\x82\x99\xE3\x83\xB3\xE3\x83\x8F\xE3\x82\x9A\xC3\xBD;foo@bar.com".b)
|
3467
|
+
|
3468
|
+
assert_parse rb, pt
|
3469
|
+
|
3470
|
+
sexp = processor.parse rb
|
3471
|
+
assert_equal Encoding::ASCII_8BIT, sexp.last.encoding
|
3472
|
+
end
|
3473
|
+
|
3274
3474
|
def test_block_call_dot_op2_cmd_args_do_block
|
3275
3475
|
rb = "a.b c() do d end.e f do |g| h end"
|
3276
3476
|
pt = s(:iter,
|
@@ -3571,7 +3771,7 @@ module TestRubyParserShared21Plus
|
|
3571
3771
|
|
3572
3772
|
def test_bug162__21plus
|
3573
3773
|
rb = %q(<<E\nfoo\nE\rO)
|
3574
|
-
emsg = "can't match /E(
|
3774
|
+
emsg = "can't match /E(\\r*\\n|\\z)/ anywhere in . near line 1: \"\""
|
3575
3775
|
|
3576
3776
|
assert_syntax_error rb, emsg
|
3577
3777
|
end
|
@@ -3721,6 +3921,13 @@ module TestRubyParserShared23Plus
|
|
3721
3921
|
assert_parse rb, pt
|
3722
3922
|
end
|
3723
3923
|
|
3924
|
+
def test_heredoc__backslash_dos_format
|
3925
|
+
rb = "str = <<-XXX\r\nbefore\\\r\nafter\r\nXXX\r\n"
|
3926
|
+
pt = s(:lasgn, :str, s(:str, "before\nafter\n"))
|
3927
|
+
|
3928
|
+
assert_parse rb, pt
|
3929
|
+
end
|
3930
|
+
|
3724
3931
|
def test_heredoc_squiggly
|
3725
3932
|
rb = "a = <<~\"EOF\"\n x\n y\n z\n EOF\n\n"
|
3726
3933
|
pt = s(:lasgn, :a, s(:str, "x\ny\nz\n"))
|
@@ -3929,6 +4136,14 @@ module TestRubyParserShared26Plus
|
|
3929
4136
|
end
|
3930
4137
|
end
|
3931
4138
|
|
4139
|
+
module TestRubyParserShared27Plus
|
4140
|
+
include TestRubyParserShared26Plus
|
4141
|
+
end
|
4142
|
+
|
4143
|
+
module TestRubyParserShared30Plus
|
4144
|
+
include TestRubyParserShared27Plus
|
4145
|
+
end
|
4146
|
+
|
3932
4147
|
class TestRubyParser < Minitest::Test
|
3933
4148
|
def test_cls_version
|
3934
4149
|
assert_equal 23, RubyParser::V23.version
|
@@ -4225,6 +4440,46 @@ class TestRubyParserV26 < RubyParserTestCase
|
|
4225
4440
|
|
4226
4441
|
end
|
4227
4442
|
|
4443
|
+
class TestRubyParserV27 < RubyParserTestCase
|
4444
|
+
include TestRubyParserShared27Plus
|
4445
|
+
|
4446
|
+
def setup
|
4447
|
+
super
|
4448
|
+
|
4449
|
+
self.processor = RubyParser::V27.new
|
4450
|
+
end
|
4451
|
+
|
4452
|
+
def test_bdot2
|
4453
|
+
rb = "..10\n; ..a\n; c"
|
4454
|
+
pt = s(:block,
|
4455
|
+
s(:dot2, nil, s(:lit, 10).line(1)).line(1),
|
4456
|
+
s(:dot2, nil, s(:call, nil, :a).line(2)).line(2),
|
4457
|
+
s(:call, nil, :c).line(3)).line(1)
|
4458
|
+
|
4459
|
+
assert_parse_line rb, pt, 1
|
4460
|
+
end
|
4461
|
+
|
4462
|
+
def test_bdot3
|
4463
|
+
rb = "...10\n; ...a\n; c"
|
4464
|
+
pt = s(:block,
|
4465
|
+
s(:dot3, nil, s(:lit, 10).line(1)).line(1),
|
4466
|
+
s(:dot3, nil, s(:call, nil, :a).line(2)).line(2),
|
4467
|
+
s(:call, nil, :c).line(3)).line(1)
|
4468
|
+
|
4469
|
+
assert_parse_line rb, pt, 1
|
4470
|
+
end
|
4471
|
+
end
|
4472
|
+
|
4473
|
+
class TestRubyParserV30 < RubyParserTestCase
|
4474
|
+
include TestRubyParserShared30Plus
|
4475
|
+
|
4476
|
+
def setup
|
4477
|
+
super
|
4478
|
+
|
4479
|
+
self.processor = RubyParser::V30.new
|
4480
|
+
end
|
4481
|
+
end
|
4482
|
+
|
4228
4483
|
RubyParser::VERSIONS.each do |klass|
|
4229
4484
|
v = klass.version
|
4230
4485
|
describe "block args arity #{v}" do
|