ruby_parser 3.18.0 → 3.18.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/History.rdoc +12 -0
- data/Rakefile +10 -0
- data/lib/ruby20_parser.rb +9 -3
- data/lib/ruby20_parser.y +9 -3
- data/lib/ruby21_parser.rb +9 -3
- data/lib/ruby21_parser.y +9 -3
- data/lib/ruby22_parser.rb +9 -3
- data/lib/ruby22_parser.y +9 -3
- data/lib/ruby23_parser.rb +9 -3
- data/lib/ruby23_parser.y +9 -3
- data/lib/ruby24_parser.rb +9 -3
- data/lib/ruby24_parser.y +9 -3
- data/lib/ruby25_parser.rb +9 -3
- data/lib/ruby25_parser.y +9 -3
- data/lib/ruby26_parser.rb +9 -3
- data/lib/ruby26_parser.y +9 -3
- data/lib/ruby27_parser.rb +9 -3
- data/lib/ruby27_parser.y +9 -3
- data/lib/ruby30_parser.rb +15 -5
- data/lib/ruby30_parser.y +12 -3
- data/lib/ruby3_parser.yy +12 -3
- data/lib/ruby_parser.yy +9 -3
- data/lib/ruby_parser_extras.rb +1 -1
- data/test/test_ruby_parser.rb +363 -343
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
data/test/test_ruby_parser.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
ENV["VERBOSE"] = "1"
|
4
4
|
|
5
5
|
require "minitest/autorun"
|
6
6
|
require "ruby_parser"
|
@@ -89,10 +89,10 @@ module TestRubyParserShared
|
|
89
89
|
def test_and_multi
|
90
90
|
rb = "true and\nnot false and\ntrue"
|
91
91
|
pt = s(:and,
|
92
|
-
s(:true)
|
92
|
+
s(:true),
|
93
93
|
s(:and,
|
94
94
|
s(:call, s(:false).line(2), :!).line(2),
|
95
|
-
s(:true).line(3)).line(2))
|
95
|
+
s(:true).line(3)).line(2))
|
96
96
|
|
97
97
|
assert_parse rb, pt
|
98
98
|
end
|
@@ -120,7 +120,7 @@ module TestRubyParserShared
|
|
120
120
|
pt = s(:block,
|
121
121
|
s(:array,
|
122
122
|
s(:str, "a").line(2),
|
123
|
-
s(:str, "b").line(3))
|
123
|
+
s(:str, "b").line(3)),
|
124
124
|
s(:lit, 1).line(4)).line 1
|
125
125
|
assert_parse rb, pt
|
126
126
|
end
|
@@ -170,7 +170,7 @@ module TestRubyParserShared
|
|
170
170
|
pt = s(:call, nil, :x,
|
171
171
|
s(:dxstr, "",
|
172
172
|
s(:evstr,
|
173
|
-
s(:call, nil, :y)
|
173
|
+
s(:call, nil, :y))))
|
174
174
|
|
175
175
|
assert_parse rb, pt
|
176
176
|
end
|
@@ -246,26 +246,26 @@ module TestRubyParserShared
|
|
246
246
|
head = s(:args).line 1
|
247
247
|
tail = s(:zsuper).line 2
|
248
248
|
expected = s(:block,
|
249
|
-
s(:args)
|
249
|
+
s(:args),
|
250
250
|
s(:zsuper).line(2)).line 1
|
251
251
|
assert_equal expected, processor.block_append(head, tail)
|
252
252
|
end
|
253
253
|
|
254
254
|
def test_block_append_begin_begin
|
255
|
-
head = s(:begin, s(:args)
|
255
|
+
head = s(:begin, s(:args)).line 1
|
256
256
|
tail = s(:begin, s(:args).line(2)).line 2
|
257
257
|
expected = s(:block,
|
258
|
-
s(:args)
|
258
|
+
s(:args),
|
259
259
|
s(:begin,
|
260
260
|
s(:args).line(2)).line(2)).line 1
|
261
261
|
assert_equal expected, processor.block_append(head, tail)
|
262
262
|
end
|
263
263
|
|
264
264
|
def test_block_append_block
|
265
|
-
head = s(:block, s(:args)
|
265
|
+
head = s(:block, s(:args))
|
266
266
|
tail = s(:zsuper).line(2)
|
267
267
|
expected = s(:block,
|
268
|
-
s(:args)
|
268
|
+
s(:args),
|
269
269
|
s(:zsuper).line(2)).line 1
|
270
270
|
assert_equal expected, processor.block_append(head, tail)
|
271
271
|
end
|
@@ -290,7 +290,7 @@ module TestRubyParserShared
|
|
290
290
|
s(:undef, s(:lit, :x)).line(2),
|
291
291
|
s(:undef, s(:lit, :y)).line(3)).line 2
|
292
292
|
expected = s(:block,
|
293
|
-
s(:call, nil, :f1)
|
293
|
+
s(:call, nil, :f1),
|
294
294
|
s(:block,
|
295
295
|
s(:undef, s(:lit, :x)).line(2),
|
296
296
|
s(:undef, s(:lit, :y)).line(3)).line(2)).line 1
|
@@ -370,7 +370,7 @@ module TestRubyParserShared
|
|
370
370
|
rb = "$测试 = 1\n测试 = 1"
|
371
371
|
pt = s(:block,
|
372
372
|
s(:gasgn, :$测试, s(:lit, 1)),
|
373
|
-
s(:lasgn, :测试, s(:lit, 1)))
|
373
|
+
s(:lasgn, :测试, s(:lit, 1).line(2)).line(2))
|
374
374
|
|
375
375
|
assert_parse rb, pt
|
376
376
|
end
|
@@ -401,7 +401,7 @@ module TestRubyParserShared
|
|
401
401
|
assert_parse rb, pt
|
402
402
|
|
403
403
|
rb = "true and\ntrue"
|
404
|
-
pt = s(:and, s(:true), s(:true))
|
404
|
+
pt = s(:and, s(:true), s(:true).line(2))
|
405
405
|
|
406
406
|
assert_parse rb, pt
|
407
407
|
end
|
@@ -446,7 +446,7 @@ module TestRubyParserShared
|
|
446
446
|
CODE
|
447
447
|
|
448
448
|
pt = s(:defn, :f, s(:args),
|
449
|
-
s(:call, nil, :g, s(:lit, 1), s(:lit, 2)))
|
449
|
+
s(:call, nil, :g, s(:lit, 1).line(2), s(:lit, 2).line(2)).line(2))
|
450
450
|
|
451
451
|
assert_parse rb, pt
|
452
452
|
|
@@ -674,7 +674,7 @@ module TestRubyParserShared
|
|
674
674
|
def test_class_comments
|
675
675
|
rb = "# blah 1\n# blah 2\n\nclass X\n # blah 3\n def blah\n # blah 4\n end\nend"
|
676
676
|
pt = s(:class, :X, nil,
|
677
|
-
s(:defn, :blah, s(:args), s(:nil)))
|
677
|
+
s(:defn, :blah, s(:args).line(6), s(:nil).line(6)).line(6)).line(4)
|
678
678
|
|
679
679
|
assert_parse rb, pt
|
680
680
|
|
@@ -695,12 +695,13 @@ module TestRubyParserShared
|
|
695
695
|
s(:call, nil, :a),
|
696
696
|
0,
|
697
697
|
s(:block,
|
698
|
-
s(:lasgn, :v, s(:nil)),
|
698
|
+
s(:lasgn, :v, s(:nil).line(2)).line(2),
|
699
699
|
s(:rescue,
|
700
|
-
s(:yield),
|
700
|
+
s(:yield).line(4),
|
701
701
|
s(:resbody,
|
702
|
-
s(:array, s(:const, :Exception)
|
703
|
-
|
702
|
+
s(:array, s(:const, :Exception).line(5),
|
703
|
+
s(:lasgn, :v, s(:gvar, :$!).line(5)).line(5)).line(5),
|
704
|
+
s(:break).line(6)).line(5)).line(4)).line(2))
|
704
705
|
|
705
706
|
assert_parse rb, pt
|
706
707
|
end
|
@@ -714,7 +715,7 @@ module TestRubyParserShared
|
|
714
715
|
|
715
716
|
def test_defn_comments
|
716
717
|
rb = "# blah 1\n# blah 2\n\ndef blah\nend"
|
717
|
-
pt = s(:defn, :blah, s(:args), s(:nil))
|
718
|
+
pt = s(:defn, :blah, s(:args).line(4), s(:nil).line(4)).line(4)
|
718
719
|
|
719
720
|
assert_parse rb, pt
|
720
721
|
assert_equal "# blah 1\n# blah 2\n\n", result.comments
|
@@ -740,7 +741,8 @@ module TestRubyParserShared
|
|
740
741
|
|
741
742
|
def test_defs_comments
|
742
743
|
rb = "# blah 1\n# blah 2\n\ndef self.blah\nend"
|
743
|
-
pt = s(:defs, s(:self), :blah, s(:args)
|
744
|
+
pt = s(:defs, s(:self).line(4), :blah, s(:args).line(4),
|
745
|
+
s(:nil).line(4)).line(4)
|
744
746
|
|
745
747
|
assert_parse rb, pt
|
746
748
|
assert_equal "# blah 1\n# blah 2\n\n", result.comments
|
@@ -751,8 +753,8 @@ module TestRubyParserShared
|
|
751
753
|
pt = s(:block,
|
752
754
|
s(:call, nil, :a, s(:lit, 1)),
|
753
755
|
s(:iter,
|
754
|
-
s(:call, s(:call, nil, :a), :b),
|
755
|
-
s(:args, :c)))
|
756
|
+
s(:call, s(:call, nil, :a).line(2), :b).line(2),
|
757
|
+
s(:args, :c).line(2)).line(2))
|
756
758
|
|
757
759
|
assert_parse rb, pt
|
758
760
|
end
|
@@ -831,7 +833,7 @@ module TestRubyParserShared
|
|
831
833
|
def test_eq_begin_line_numbers
|
832
834
|
rb = "1\n=begin\ncomment\ncomment\n=end\n2"
|
833
835
|
pt = s(:block,
|
834
|
-
s(:lit, 1)
|
836
|
+
s(:lit, 1),
|
835
837
|
s(:lit, 2).line(6))
|
836
838
|
|
837
839
|
assert_parse rb, pt
|
@@ -839,7 +841,9 @@ module TestRubyParserShared
|
|
839
841
|
|
840
842
|
def test_eq_begin_why_wont_people_use_their_spacebar?
|
841
843
|
rb = "h[k]=begin\n 42\n end"
|
842
|
-
pt = s(:attrasgn,
|
844
|
+
pt = s(:attrasgn,
|
845
|
+
s(:call, nil, :h), :[]=, s(:call, nil, :k),
|
846
|
+
s(:lit, 42).line(2))
|
843
847
|
|
844
848
|
assert_parse rb, pt
|
845
849
|
end
|
@@ -891,8 +895,8 @@ module TestRubyParserShared
|
|
891
895
|
def test_heredoc_lineno
|
892
896
|
rb = "c = <<'CCC'\nline2\nline3\nline4\nCCC\n\nd = 42"
|
893
897
|
pt = s(:block,
|
894
|
-
s(:lasgn, :c, s(:str, "line2\nline3\nline4\n")
|
895
|
-
s(:lasgn, :d, s(:lit, 42).line(7)).line(7))
|
898
|
+
s(:lasgn, :c, s(:str, "line2\nline3\nline4\n")),
|
899
|
+
s(:lasgn, :d, s(:lit, 42).line(7)).line(7))
|
896
900
|
|
897
901
|
assert_parse rb, pt
|
898
902
|
end
|
@@ -900,13 +904,13 @@ module TestRubyParserShared
|
|
900
904
|
def test_pctW_lineno
|
901
905
|
rb = "%W(a\\nb\nc\ d\ne\\\nf\ng\y h\\y i\\\y)"
|
902
906
|
pt = s(:array,
|
903
|
-
s(:str, "a\nb")
|
907
|
+
s(:str, "a\nb"),
|
904
908
|
s(:str, "c").line(2),
|
905
909
|
s(:str, "d").line(2),
|
906
910
|
s(:str, "e\nf").line(3),
|
907
911
|
s(:str, "gy").line(5),
|
908
912
|
s(:str, "hy").line(5),
|
909
|
-
s(:str, "iy").line(5))
|
913
|
+
s(:str, "iy").line(5))
|
910
914
|
|
911
915
|
assert_parse rb, pt
|
912
916
|
end
|
@@ -962,14 +966,17 @@ module TestRubyParserShared
|
|
962
966
|
|
963
967
|
def test_heredoc_with_interpolation_and_carriage_return_escapes
|
964
968
|
rb = "<<EOS\nfoo\\r\#@bar\nEOS\n"
|
965
|
-
pt = s(:dstr, "foo\r", s(:evstr, s(:ivar, :@bar)), s(:str, "\n"))
|
969
|
+
pt = s(:dstr, "foo\r", s(:evstr, s(:ivar, :@bar).line(2)).line(2), s(:str, "\n").line(2))
|
966
970
|
|
967
971
|
assert_parse rb, pt
|
968
972
|
end
|
969
973
|
|
970
974
|
def test_heredoc_with_interpolation_and_carriage_return_escapes_windows
|
971
975
|
rb = "<<EOS\r\nfoo\\r\#@bar\r\nEOS\r\n"
|
972
|
-
pt = s(:dstr,
|
976
|
+
pt = s(:dstr,
|
977
|
+
"foo\r",
|
978
|
+
s(:evstr, s(:ivar, :@bar).line(2)).line(2),
|
979
|
+
s(:str, "\n").line(2))
|
973
980
|
|
974
981
|
assert_parse rb, pt
|
975
982
|
end
|
@@ -1011,7 +1018,7 @@ module TestRubyParserShared
|
|
1011
1018
|
end
|
1012
1019
|
END
|
1013
1020
|
|
1014
|
-
pt = s(:if, s(:true)
|
1021
|
+
pt = s(:if, s(:true),
|
1015
1022
|
s(:block,
|
1016
1023
|
s(:call, nil, :p, s(:lit, 1).line(2)).line(2),
|
1017
1024
|
s(:call, s(:call, nil, :a).line(3), :b,
|
@@ -1031,7 +1038,7 @@ module TestRubyParserShared
|
|
1031
1038
|
s(:lit, 5).line(10)).line(10),
|
1032
1039
|
s(:call, s(:call, nil, :g).line(11), :h,
|
1033
1040
|
s(:lit, 6).line(11), s(:lit, 7).line(11)).line(11)).line(2),
|
1034
|
-
nil)
|
1041
|
+
nil)
|
1035
1042
|
|
1036
1043
|
assert_parse rb, pt
|
1037
1044
|
end
|
@@ -1048,14 +1055,14 @@ module TestRubyParserShared
|
|
1048
1055
|
EOM
|
1049
1056
|
|
1050
1057
|
pt = s(:block,
|
1051
|
-
s(:if, s(:true)
|
1058
|
+
s(:if, s(:true),
|
1052
1059
|
s(:block,
|
1053
1060
|
s(:call, nil, :p, s(:str, "a").line(2)).line(2),
|
1054
1061
|
s(:lasgn, :b, s(:lit, 1).line(3)).line(3),
|
1055
1062
|
s(:call, nil, :p, s(:lvar, :b).line(4)).line(4),
|
1056
1063
|
s(:lasgn, :c, s(:lit, 1).line(5)).line(5)).line(2),
|
1057
|
-
nil)
|
1058
|
-
s(:call, nil, :a).line(7))
|
1064
|
+
nil),
|
1065
|
+
s(:call, nil, :a).line(7))
|
1059
1066
|
|
1060
1067
|
assert_parse rb, pt
|
1061
1068
|
end
|
@@ -1086,8 +1093,8 @@ module TestRubyParserShared
|
|
1086
1093
|
pt = s(:block,
|
1087
1094
|
s(:array,
|
1088
1095
|
s(:str, "a").line(2),
|
1089
|
-
s(:str, "b").line(3))
|
1090
|
-
s(:lit, 1).line(5))
|
1096
|
+
s(:str, "b").line(3)),
|
1097
|
+
s(:lit, 1).line(5))
|
1091
1098
|
assert_parse rb, pt
|
1092
1099
|
end
|
1093
1100
|
|
@@ -1247,14 +1254,14 @@ module TestRubyParserShared
|
|
1247
1254
|
def test_logical_op_12
|
1248
1255
|
lhs = s(:lit, 1).line 1
|
1249
1256
|
rhs = s(:lit, 2).line 2
|
1250
|
-
exp = s(:and, s(:lit, 1)
|
1257
|
+
exp = s(:and, s(:lit, 1), s(:lit, 2).line(2)).line 1
|
1251
1258
|
|
1252
1259
|
assert_equal exp, processor.logical_op(:and, lhs, rhs)
|
1253
1260
|
end
|
1254
1261
|
|
1255
1262
|
def test_logical_op_1234_5
|
1256
1263
|
lhs = s(:and,
|
1257
|
-
s(:lit, 1)
|
1264
|
+
s(:lit, 1),
|
1258
1265
|
s(:and,
|
1259
1266
|
s(:lit, 2).line(2),
|
1260
1267
|
s(:and,
|
@@ -1262,7 +1269,7 @@ module TestRubyParserShared
|
|
1262
1269
|
s(:lit, 4).line(4)).line(3)).line(2)).line 1
|
1263
1270
|
rhs = s(:lit, 5).line(5)
|
1264
1271
|
exp = s(:and,
|
1265
|
-
s(:lit, 1)
|
1272
|
+
s(:lit, 1),
|
1266
1273
|
s(:and,
|
1267
1274
|
s(:lit, 2).line(2),
|
1268
1275
|
s(:and,
|
@@ -1276,13 +1283,13 @@ module TestRubyParserShared
|
|
1276
1283
|
|
1277
1284
|
def test_logical_op_123_4
|
1278
1285
|
lhs = s(:and,
|
1279
|
-
s(:lit, 1)
|
1286
|
+
s(:lit, 1),
|
1280
1287
|
s(:and,
|
1281
1288
|
s(:lit, 2).line(2),
|
1282
1289
|
s(:lit, 3).line(3)).line(2)).line 1
|
1283
1290
|
rhs = s(:lit, 4).line 4
|
1284
1291
|
exp = s(:and,
|
1285
|
-
s(:lit, 1)
|
1292
|
+
s(:lit, 1),
|
1286
1293
|
s(:and,
|
1287
1294
|
s(:lit, 2).line(2),
|
1288
1295
|
s(:and,
|
@@ -1294,11 +1301,11 @@ module TestRubyParserShared
|
|
1294
1301
|
|
1295
1302
|
def test_logical_op_12_3
|
1296
1303
|
lhs = s(:and,
|
1297
|
-
s(:lit, 1)
|
1304
|
+
s(:lit, 1),
|
1298
1305
|
s(:lit, 2).line(2)).line 1
|
1299
1306
|
rhs = s(:lit, 3).line 3
|
1300
1307
|
exp = s(:and,
|
1301
|
-
s(:lit, 1)
|
1308
|
+
s(:lit, 1),
|
1302
1309
|
s(:and,
|
1303
1310
|
s(:lit, 2).line(2),
|
1304
1311
|
s(:lit, 3).line(3)).line(2)).line 1
|
@@ -1308,15 +1315,15 @@ module TestRubyParserShared
|
|
1308
1315
|
|
1309
1316
|
def test_logical_op_nested_mix
|
1310
1317
|
lhs = s(:or,
|
1311
|
-
s(:call, nil, :a)
|
1318
|
+
s(:call, nil, :a),
|
1312
1319
|
s(:call, nil, :b).line(2)).line 1
|
1313
1320
|
rhs = s(:and,
|
1314
1321
|
s(:call, nil, :c).line(3),
|
1315
1322
|
s(:call, nil, :d).line(4)).line 3
|
1316
1323
|
exp = s(:or,
|
1317
1324
|
s(:or,
|
1318
|
-
s(:call, nil, :a)
|
1319
|
-
s(:call, nil, :b).line(2))
|
1325
|
+
s(:call, nil, :a),
|
1326
|
+
s(:call, nil, :b).line(2)),
|
1320
1327
|
s(:and,
|
1321
1328
|
s(:call, nil, :c).line(3),
|
1322
1329
|
s(:call, nil, :d).line(4)).line(3)).line 1
|
@@ -1337,8 +1344,8 @@ module TestRubyParserShared
|
|
1337
1344
|
# TODO: globals
|
1338
1345
|
|
1339
1346
|
pt = s(:class, :"ExampleUTF8ClassNameVariet\303\240", nil,
|
1340
|
-
s(:defs, s(:self), :"\303\250", s(:args),
|
1341
|
-
s(:lasgn, :"cos\303\254", s(:lit, :"per\303\262"))))
|
1347
|
+
s(:defs, s(:self).line(2), :"\303\250", s(:args).line(2),
|
1348
|
+
s(:lasgn, :"cos\303\254", s(:lit, :"per\303\262").line(2)).line(2)).line(2)).line(2)
|
1342
1349
|
|
1343
1350
|
err = RUBY_VERSION =~ /^1\.8/ ? "Skipping magic encoding comment\n" : ""
|
1344
1351
|
|
@@ -1349,14 +1356,14 @@ module TestRubyParserShared
|
|
1349
1356
|
|
1350
1357
|
def test_magic_encoding_comment__bad
|
1351
1358
|
rb = "#encoding: bunk\n0"
|
1352
|
-
pt = s(:lit, 0)
|
1359
|
+
pt = s(:lit, 0).line(2)
|
1353
1360
|
|
1354
1361
|
assert_parse rb, pt
|
1355
1362
|
end
|
1356
1363
|
|
1357
1364
|
def test_utf8_bom
|
1358
1365
|
rb = "\xEF\xBB\xBF#!/usr/bin/env ruby -w\np 0\n"
|
1359
|
-
pt = s(:call, nil, :p, s(:lit, 0))
|
1366
|
+
pt = s(:call, nil, :p, s(:lit, 0).line(2)).line(2)
|
1360
1367
|
|
1361
1368
|
assert_parse rb, pt
|
1362
1369
|
end
|
@@ -1365,12 +1372,12 @@ module TestRubyParserShared
|
|
1365
1372
|
rb = "a, b::c = d"
|
1366
1373
|
pt = s(:masgn,
|
1367
1374
|
s(:array,
|
1368
|
-
s(:lasgn, :a)
|
1375
|
+
s(:lasgn, :a),
|
1369
1376
|
s(:attrasgn,
|
1370
|
-
s(:call, nil, :b)
|
1371
|
-
:c=)
|
1377
|
+
s(:call, nil, :b),
|
1378
|
+
:c=)),
|
1372
1379
|
s(:to_ary,
|
1373
|
-
s(:call, nil, :d)
|
1380
|
+
s(:call, nil, :d)))
|
1374
1381
|
|
1375
1382
|
assert_parse rb, pt
|
1376
1383
|
end
|
@@ -1450,7 +1457,7 @@ module TestRubyParserShared
|
|
1450
1457
|
def test_module_comments
|
1451
1458
|
rb = "# blah 1\n \n # blah 2\n\nmodule X\n # blah 3\n def blah\n # blah 4\n end\nend"
|
1452
1459
|
pt = s(:module, :X,
|
1453
|
-
s(:defn, :blah, s(:args), s(:nil)))
|
1460
|
+
s(:defn, :blah, s(:args).line(7), s(:nil).line(7)).line(7)).line(5)
|
1454
1461
|
|
1455
1462
|
assert_parse rb, pt
|
1456
1463
|
assert_equal "# blah 1\n\n# blah 2\n\n", result.comments
|
@@ -1462,8 +1469,8 @@ module TestRubyParserShared
|
|
1462
1469
|
pt = s(:block,
|
1463
1470
|
s(:array,
|
1464
1471
|
s(:str, "a").line(2),
|
1465
|
-
s(:str, "b").line(3))
|
1466
|
-
s(:lit, 1).line(5))
|
1472
|
+
s(:str, "b").line(3)),
|
1473
|
+
s(:lit, 1).line(5))
|
1467
1474
|
assert_parse rb, pt
|
1468
1475
|
end
|
1469
1476
|
|
@@ -1587,17 +1594,11 @@ module TestRubyParserShared
|
|
1587
1594
|
rb = "a = 42\np a"
|
1588
1595
|
pt = s(:block,
|
1589
1596
|
s(:lasgn, :a, s(:lit, 42)),
|
1590
|
-
s(:call, nil, :p, s(:lvar, :a)))
|
1591
|
-
|
1592
|
-
assert_parse_line rb, pt, 1
|
1593
|
-
assert_equal 1, result.lasgn.line, "lasgn should have line number"
|
1594
|
-
assert_equal 2, result.call.line, "call should have line number"
|
1597
|
+
s(:call, nil, :p, s(:lvar, :a).line(2)).line(2))
|
1595
1598
|
|
1596
|
-
|
1597
|
-
assert_equal expected, result.file
|
1598
|
-
assert_equal expected, result.lasgn.file
|
1599
|
-
assert_equal expected, result.call.file
|
1599
|
+
assert_parse rb, pt
|
1600
1600
|
|
1601
|
+
assert_equal "(string)", result.file
|
1601
1602
|
assert_same result.file, result.lasgn.file
|
1602
1603
|
assert_same result.file, result.call.file
|
1603
1604
|
end
|
@@ -1605,7 +1606,7 @@ module TestRubyParserShared
|
|
1605
1606
|
def test_parse_line_block_inline_comment
|
1606
1607
|
rb = "a\nb # comment\nc"
|
1607
1608
|
pt = s(:block,
|
1608
|
-
s(:call, nil, :a)
|
1609
|
+
s(:call, nil, :a),
|
1609
1610
|
s(:call, nil, :b).line(2),
|
1610
1611
|
s(:call, nil, :c).line(3))
|
1611
1612
|
|
@@ -1625,23 +1626,23 @@ module TestRubyParserShared
|
|
1625
1626
|
def test_parse_line_block_inline_multiline_comment
|
1626
1627
|
rb = "a\nb # comment\n# another comment\nc"
|
1627
1628
|
pt = s(:block,
|
1628
|
-
s(:call, nil, :a)
|
1629
|
+
s(:call, nil, :a),
|
1629
1630
|
s(:call, nil, :b).line(2),
|
1630
|
-
s(:call, nil, :c).line(4))
|
1631
|
+
s(:call, nil, :c).line(4))
|
1631
1632
|
|
1632
1633
|
assert_parse rb, pt
|
1633
1634
|
end
|
1634
1635
|
|
1635
1636
|
def test_parse_line_call_ivar_arg_no_parens_line_break
|
1636
1637
|
rb = "a @b\n"
|
1637
|
-
pt = s(:call, nil, :a, s(:ivar, :@b)
|
1638
|
+
pt = s(:call, nil, :a, s(:ivar, :@b))
|
1638
1639
|
|
1639
1640
|
assert_parse rb, pt
|
1640
1641
|
end
|
1641
1642
|
|
1642
1643
|
def test_parse_line_call_ivar_line_break_paren
|
1643
1644
|
rb = "a(@b\n)"
|
1644
|
-
pt = s(:call, nil, :a, s(:ivar, :@b)
|
1645
|
+
pt = s(:call, nil, :a, s(:ivar, :@b))
|
1645
1646
|
|
1646
1647
|
assert_parse rb, pt
|
1647
1648
|
end
|
@@ -1652,9 +1653,9 @@ module TestRubyParserShared
|
|
1652
1653
|
pt = s(:iter,
|
1653
1654
|
s(:call, nil, :f),
|
1654
1655
|
s(:args, :x, :y),
|
1655
|
-
s(:call, s(:lvar, :x), :+, s(:lvar, :y)))
|
1656
|
+
s(:call, s(:lvar, :x).line(2), :+, s(:lvar, :y).line(2)).line(2))
|
1656
1657
|
|
1657
|
-
|
1658
|
+
assert_parse rb, pt
|
1658
1659
|
|
1659
1660
|
_, a, b, c, = result
|
1660
1661
|
|
@@ -1665,19 +1666,19 @@ module TestRubyParserShared
|
|
1665
1666
|
|
1666
1667
|
def test_parse_line_defn_no_parens_args
|
1667
1668
|
rb = "def f a\nend"
|
1668
|
-
pt = s(:defn, :f, s(:args, :a)
|
1669
|
+
pt = s(:defn, :f, s(:args, :a), s(:nil))
|
1669
1670
|
|
1670
|
-
|
1671
|
+
assert_parse rb, pt
|
1671
1672
|
end
|
1672
1673
|
|
1673
1674
|
def test_parse_line_defn_complex
|
1674
1675
|
rb = "def x(y)\n p(y)\n y *= 2\n return y;\nend" # TODO: remove () & ;
|
1675
1676
|
pt = s(:defn, :x, s(:args, :y),
|
1676
|
-
s(:call, nil, :p, s(:lvar, :y)),
|
1677
|
-
s(:lasgn, :y, s(:call, s(:lvar, :y), :*, s(:lit, 2))),
|
1678
|
-
s(:return, s(:lvar, :y)))
|
1677
|
+
s(:call, nil, :p, s(:lvar, :y).line(2)).line(2),
|
1678
|
+
s(:lasgn, :y, s(:call, s(:lvar, :y).line(3), :*, s(:lit, 2).line(3)).line(3)).line(3),
|
1679
|
+
s(:return, s(:lvar, :y).line(4)).line(4))
|
1679
1680
|
|
1680
|
-
|
1681
|
+
assert_parse rb, pt
|
1681
1682
|
|
1682
1683
|
body = result
|
1683
1684
|
assert_equal 2, body.call.line, "call should have line number"
|
@@ -1686,47 +1687,47 @@ module TestRubyParserShared
|
|
1686
1687
|
end
|
1687
1688
|
|
1688
1689
|
def test_parse_line_defn_no_parens
|
1689
|
-
pt = s(:defn, :f, s(:args)
|
1690
|
+
pt = s(:defn, :f, s(:args), s(:nil))
|
1690
1691
|
|
1691
1692
|
rb = "def f\nend"
|
1692
|
-
|
1693
|
+
assert_parse rb, pt
|
1693
1694
|
|
1694
1695
|
processor.reset
|
1695
1696
|
|
1696
1697
|
rb = "def f\n\nend"
|
1697
|
-
|
1698
|
+
assert_parse rb, pt
|
1698
1699
|
end
|
1699
1700
|
|
1700
1701
|
def test_parse_line_dot2
|
1701
1702
|
rb = "0..\n4\na..\nb\nc"
|
1702
1703
|
pt = s(:block,
|
1703
|
-
s(:lit, 0..4)
|
1704
|
+
s(:lit, 0..4),
|
1704
1705
|
s(:dot2,
|
1705
1706
|
s(:call, nil, :a).line(3),
|
1706
1707
|
s(:call, nil, :b).line(4)).line(3),
|
1707
|
-
s(:call, nil, :c).line(5))
|
1708
|
+
s(:call, nil, :c).line(5))
|
1708
1709
|
|
1709
|
-
|
1710
|
+
assert_parse rb, pt
|
1710
1711
|
end
|
1711
1712
|
|
1712
1713
|
def test_parse_line_dot3
|
1713
1714
|
rb = "0...\n4\na...\nb\nc"
|
1714
1715
|
pt = s(:block,
|
1715
|
-
s(:lit, 0...4)
|
1716
|
+
s(:lit, 0...4),
|
1716
1717
|
s(:dot3,
|
1717
1718
|
s(:call, nil, :a).line(3),
|
1718
1719
|
s(:call, nil, :b).line(4)).line(3),
|
1719
|
-
s(:call, nil, :c).line(5))
|
1720
|
+
s(:call, nil, :c).line(5))
|
1720
1721
|
|
1721
|
-
|
1722
|
+
assert_parse rb, pt
|
1722
1723
|
end
|
1723
1724
|
|
1724
1725
|
def test_parse_line_dstr_escaped_newline
|
1725
1726
|
rb = "\"a\\n\#{\n}\"\ntrue"
|
1726
1727
|
pt = s(:block,
|
1727
1728
|
s(:dstr, "a\n",
|
1728
|
-
s(:evstr)
|
1729
|
-
s(:true).line(3))
|
1729
|
+
s(:evstr)),
|
1730
|
+
s(:true).line(3))
|
1730
1731
|
|
1731
1732
|
assert_parse rb, pt
|
1732
1733
|
end
|
@@ -1734,8 +1735,8 @@ module TestRubyParserShared
|
|
1734
1735
|
def test_parse_line_dstr_soft_newline
|
1735
1736
|
rb = "\"a\n#\{\n}\"\ntrue"
|
1736
1737
|
pt = s(:block,
|
1737
|
-
s(:dstr, "a\n", s(:evstr).line(2))
|
1738
|
-
s(:true).line(4))
|
1738
|
+
s(:dstr, "a\n", s(:evstr).line(2)),
|
1739
|
+
s(:true).line(4))
|
1739
1740
|
|
1740
1741
|
assert_parse rb, pt
|
1741
1742
|
end
|
@@ -1744,7 +1745,7 @@ module TestRubyParserShared
|
|
1744
1745
|
rb = "\"a\"\\\n\"\#{b}\""
|
1745
1746
|
pt = s(:dstr, "a",
|
1746
1747
|
s(:evstr,
|
1747
|
-
s(:call, nil, :b).line(2)).line(2))
|
1748
|
+
s(:call, nil, :b).line(2)).line(2))
|
1748
1749
|
|
1749
1750
|
assert_parse rb, pt
|
1750
1751
|
end
|
@@ -1753,7 +1754,7 @@ module TestRubyParserShared
|
|
1753
1754
|
rb = "{\n:s1 => 1,\n}"
|
1754
1755
|
pt = s(:hash,
|
1755
1756
|
s(:lit, :s1).line(2), s(:lit, 1).line(2),
|
1756
|
-
)
|
1757
|
+
)
|
1757
1758
|
|
1758
1759
|
assert_parse rb, pt
|
1759
1760
|
end
|
@@ -1769,12 +1770,12 @@ module TestRubyParserShared
|
|
1769
1770
|
pt = s(:block,
|
1770
1771
|
s(:lasgn, :string,
|
1771
1772
|
s(:call,
|
1772
|
-
s(:str, " very long string\n")
|
1773
|
-
:strip)
|
1774
|
-
)
|
1773
|
+
s(:str, " very long string\n"),
|
1774
|
+
:strip),
|
1775
|
+
),
|
1775
1776
|
s(:call, nil, :puts,
|
1776
1777
|
s(:lvar, :string).line(4)).line(4)
|
1777
|
-
)
|
1778
|
+
)
|
1778
1779
|
|
1779
1780
|
assert_parse rb, pt
|
1780
1781
|
end
|
@@ -1784,7 +1785,7 @@ module TestRubyParserShared
|
|
1784
1785
|
pt = s(:dstr,
|
1785
1786
|
"a\n",
|
1786
1787
|
s(:evstr, s(:call, nil, :b).line(3)).line(3), s(:str, "\n").line(3)
|
1787
|
-
)
|
1788
|
+
)
|
1788
1789
|
|
1789
1790
|
assert_parse rb, pt
|
1790
1791
|
end
|
@@ -1799,8 +1800,8 @@ module TestRubyParserShared
|
|
1799
1800
|
|
1800
1801
|
pt = s(:block,
|
1801
1802
|
s(:lasgn, :string,
|
1802
|
-
s(:str, " very long string\n")
|
1803
|
-
s(:call, nil, :puts, s(:lvar, :string).line(4)).line(4))
|
1803
|
+
s(:str, " very long string\n")),
|
1804
|
+
s(:call, nil, :puts, s(:lvar, :string).line(4)).line(4))
|
1804
1805
|
|
1805
1806
|
assert_parse rb, pt
|
1806
1807
|
end
|
@@ -1809,10 +1810,10 @@ module TestRubyParserShared
|
|
1809
1810
|
rb = "f a do |x, y|\n x + y\nend"
|
1810
1811
|
|
1811
1812
|
pt = s(:iter,
|
1812
|
-
s(:call, nil, :f, s(:call, nil, :a)
|
1813
|
-
s(:args, :x, :y)
|
1813
|
+
s(:call, nil, :f, s(:call, nil, :a)),
|
1814
|
+
s(:args, :x, :y),
|
1814
1815
|
s(:call, s(:lvar, :x).line(2), :+,
|
1815
|
-
s(:lvar, :y).line(2)).line(2))
|
1816
|
+
s(:lvar, :y).line(2)).line(2))
|
1816
1817
|
|
1817
1818
|
assert_parse rb, pt
|
1818
1819
|
end
|
@@ -1823,9 +1824,9 @@ module TestRubyParserShared
|
|
1823
1824
|
pt = s(:iter,
|
1824
1825
|
s(:call, nil, :f, s(:call, nil, :a)),
|
1825
1826
|
s(:args, :x, :y),
|
1826
|
-
s(:call, s(:lvar, :x), :+, s(:lvar, :y)))
|
1827
|
+
s(:call, s(:lvar, :x).line(2), :+, s(:lvar, :y).line(2)).line(2))
|
1827
1828
|
|
1828
|
-
|
1829
|
+
assert_parse rb, pt
|
1829
1830
|
|
1830
1831
|
_, a, b, c, = result
|
1831
1832
|
|
@@ -1837,8 +1838,8 @@ module TestRubyParserShared
|
|
1837
1838
|
def test_parse_line_multiline_str
|
1838
1839
|
rb = "\"a\nb\"\n1"
|
1839
1840
|
pt = s(:block,
|
1840
|
-
s(:str, "a\nb")
|
1841
|
-
s(:lit, 1).line(3))
|
1841
|
+
s(:str, "a\nb"),
|
1842
|
+
s(:lit, 1).line(3))
|
1842
1843
|
|
1843
1844
|
assert_parse rb, pt
|
1844
1845
|
end
|
@@ -1846,8 +1847,8 @@ module TestRubyParserShared
|
|
1846
1847
|
def test_parse_line_multiline_str_literal_n
|
1847
1848
|
rb = "\"a\\nb\"\n1"
|
1848
1849
|
pt = s(:block,
|
1849
|
-
s(:str, "a\nb")
|
1850
|
-
s(:lit, 1).line(2))
|
1850
|
+
s(:str, "a\nb"),
|
1851
|
+
s(:lit, 1).line(2))
|
1851
1852
|
|
1852
1853
|
assert_parse rb, pt
|
1853
1854
|
end
|
@@ -1856,7 +1857,7 @@ module TestRubyParserShared
|
|
1856
1857
|
rb = "true\n\n"
|
1857
1858
|
pt = s(:true)
|
1858
1859
|
|
1859
|
-
|
1860
|
+
assert_parse rb, pt
|
1860
1861
|
end
|
1861
1862
|
|
1862
1863
|
def test_parse_line_op_asgn
|
@@ -1869,30 +1870,30 @@ module TestRubyParserShared
|
|
1869
1870
|
pt = s(:block,
|
1870
1871
|
s(:lasgn, :foo,
|
1871
1872
|
s(:call,
|
1872
|
-
s(:lvar, :foo)
|
1873
|
+
s(:lvar, :foo),
|
1873
1874
|
:+,
|
1874
|
-
s(:call, nil, :bar).line(2))
|
1875
|
-
s(:call, nil, :baz).line(3))
|
1875
|
+
s(:call, nil, :bar).line(2))),
|
1876
|
+
s(:call, nil, :baz).line(3))
|
1876
1877
|
|
1877
|
-
|
1878
|
+
assert_parse rb, pt
|
1878
1879
|
end
|
1879
1880
|
|
1880
1881
|
def test_parse_line_postexe
|
1881
1882
|
rb = "END {\nfoo\n}"
|
1882
1883
|
pt = s(:iter,
|
1883
|
-
s(:postexe)
|
1884
|
-
s(:call, nil, :foo).line(2))
|
1884
|
+
s(:postexe), 0,
|
1885
|
+
s(:call, nil, :foo).line(2))
|
1885
1886
|
|
1886
|
-
|
1887
|
+
assert_parse rb, pt
|
1887
1888
|
end
|
1888
1889
|
|
1889
1890
|
def test_parse_line_preexe
|
1890
1891
|
rb = "BEGIN {\nfoo\n}"
|
1891
1892
|
pt = s(:iter,
|
1892
|
-
s(:preexe)
|
1893
|
-
s(:call, nil, :foo).line(2))
|
1893
|
+
s(:preexe), 0,
|
1894
|
+
s(:call, nil, :foo).line(2))
|
1894
1895
|
|
1895
|
-
|
1896
|
+
assert_parse rb, pt
|
1896
1897
|
end
|
1897
1898
|
|
1898
1899
|
def test_parse_line_rescue
|
@@ -1904,7 +1905,7 @@ module TestRubyParserShared
|
|
1904
1905
|
s(:resbody, s(:array).line(5),
|
1905
1906
|
s(:call, nil, :c).line(6)).line(5)).line(2)
|
1906
1907
|
|
1907
|
-
|
1908
|
+
assert_parse rb, pt
|
1908
1909
|
end
|
1909
1910
|
|
1910
1911
|
def test_parse_line_return
|
@@ -1917,11 +1918,11 @@ module TestRubyParserShared
|
|
1917
1918
|
RUBY
|
1918
1919
|
|
1919
1920
|
pt = s(:defn, :blah, s(:args),
|
1920
|
-
s(:if, s(:true),
|
1921
|
-
s(:return, s(:lit, 42)),
|
1922
|
-
nil))
|
1921
|
+
s(:if, s(:true).line(2),
|
1922
|
+
s(:return, s(:lit, 42).line(3)).line(3),
|
1923
|
+
nil).line(2))
|
1923
1924
|
|
1924
|
-
|
1925
|
+
assert_parse rb, pt
|
1925
1926
|
|
1926
1927
|
assert_equal 3, result.if.return.line
|
1927
1928
|
assert_equal 3, result.if.return.lit.line
|
@@ -1930,8 +1931,8 @@ module TestRubyParserShared
|
|
1930
1931
|
def test_parse_line_str_with_newline_escape
|
1931
1932
|
rb = 'a("\n", true)'
|
1932
1933
|
pt = s(:call, nil, :a,
|
1933
|
-
s(:str, "\n")
|
1934
|
-
s(:true)
|
1934
|
+
s(:str, "\n"),
|
1935
|
+
s(:true))
|
1935
1936
|
|
1936
1937
|
assert_parse rb, pt
|
1937
1938
|
end
|
@@ -1940,18 +1941,18 @@ module TestRubyParserShared
|
|
1940
1941
|
rb = "a,\nb = c\nd"
|
1941
1942
|
pt = s(:block,
|
1942
1943
|
s(:masgn,
|
1943
|
-
s(:array, s(:lasgn, :a)
|
1944
|
-
s(:to_ary, s(:call, nil, :c).line(2)).line(2))
|
1945
|
-
s(:call, nil, :d).line(3))
|
1944
|
+
s(:array, s(:lasgn, :a), s(:lasgn, :b).line(2)),
|
1945
|
+
s(:to_ary, s(:call, nil, :c).line(2)).line(2)),
|
1946
|
+
s(:call, nil, :d).line(3))
|
1946
1947
|
|
1947
|
-
|
1948
|
+
assert_parse rb, pt
|
1948
1949
|
end
|
1949
1950
|
|
1950
1951
|
def test_parse_line_trailing_newlines
|
1951
1952
|
rb = "a \nb"
|
1952
1953
|
pt = s(:block,
|
1953
|
-
s(:call, nil, :a)
|
1954
|
-
s(:call, nil, :b).line(2))
|
1954
|
+
s(:call, nil, :a),
|
1955
|
+
s(:call, nil, :b).line(2))
|
1955
1956
|
|
1956
1957
|
assert_parse rb, pt
|
1957
1958
|
end
|
@@ -2063,7 +2064,9 @@ module TestRubyParserShared
|
|
2063
2064
|
|
2064
2065
|
def test_str_heredoc_interp
|
2065
2066
|
rb = "<<\"\"\n\#{x}\nblah2\n\n"
|
2066
|
-
pt = s(:dstr, "",
|
2067
|
+
pt = s(:dstr, "",
|
2068
|
+
s(:evstr, s(:call, nil, :x).line(2)).line(2),
|
2069
|
+
s(:str, "\nblah2\n").line(2))
|
2067
2070
|
|
2068
2071
|
assert_parse rb, pt
|
2069
2072
|
end
|
@@ -2086,7 +2089,7 @@ module TestRubyParserShared
|
|
2086
2089
|
|
2087
2090
|
def test_str_newline_hash_line_number
|
2088
2091
|
rb = "\"\\n\\n\\n\\n#\"\n1"
|
2089
|
-
pt = s(:block, s(:str, "\n\n\n\n#")
|
2092
|
+
pt = s(:block, s(:str, "\n\n\n\n#"),
|
2090
2093
|
s(:lit, 1).line(2))
|
2091
2094
|
|
2092
2095
|
assert_parse rb, pt
|
@@ -2117,8 +2120,8 @@ module TestRubyParserShared
|
|
2117
2120
|
def test_str_single_newline
|
2118
2121
|
rp = "a '\n';b"
|
2119
2122
|
pt = s(:block,
|
2120
|
-
s(:call, nil, :a, s(:str, "\n")
|
2121
|
-
s(:call, nil, :b).line(2))
|
2123
|
+
s(:call, nil, :a, s(:str, "\n")),
|
2124
|
+
s(:call, nil, :b).line(2))
|
2122
2125
|
|
2123
2126
|
assert_parse rp, pt
|
2124
2127
|
end
|
@@ -2126,8 +2129,8 @@ module TestRubyParserShared
|
|
2126
2129
|
def test_str_single_escaped_newline
|
2127
2130
|
rp = "a '\\n';b"
|
2128
2131
|
pt = s(:block,
|
2129
|
-
s(:call, nil, :a, s(:str, "\\n")
|
2130
|
-
s(:call, nil, :b)
|
2132
|
+
s(:call, nil, :a, s(:str, "\\n")),
|
2133
|
+
s(:call, nil, :b))
|
2131
2134
|
|
2132
2135
|
assert_parse rp, pt
|
2133
2136
|
end
|
@@ -2135,8 +2138,8 @@ module TestRubyParserShared
|
|
2135
2138
|
def test_str_single_double_escaped_newline
|
2136
2139
|
rp = "a '\\\\n';b"
|
2137
2140
|
pt = s(:block,
|
2138
|
-
s(:call, nil, :a, s(:str, "\\n")
|
2139
|
-
s(:call, nil, :b)
|
2141
|
+
s(:call, nil, :a, s(:str, "\\n")),
|
2142
|
+
s(:call, nil, :b))
|
2140
2143
|
|
2141
2144
|
assert_parse rp, pt
|
2142
2145
|
end
|
@@ -2144,8 +2147,8 @@ module TestRubyParserShared
|
|
2144
2147
|
def test_str_double_newline
|
2145
2148
|
rp = "a \"\n\";b"
|
2146
2149
|
pt = s(:block,
|
2147
|
-
s(:call, nil, :a, s(:str, "\n")
|
2148
|
-
s(:call, nil, :b).line(2))
|
2150
|
+
s(:call, nil, :a, s(:str, "\n")),
|
2151
|
+
s(:call, nil, :b).line(2))
|
2149
2152
|
|
2150
2153
|
assert_parse rp, pt
|
2151
2154
|
end
|
@@ -2153,8 +2156,8 @@ module TestRubyParserShared
|
|
2153
2156
|
def test_str_double_escaped_newline
|
2154
2157
|
rp = "a \"\\n\";b"
|
2155
2158
|
pt = s(:block,
|
2156
|
-
s(:call, nil, :a, s(:str, "\n")
|
2157
|
-
s(:call, nil, :b)
|
2159
|
+
s(:call, nil, :a, s(:str, "\n")),
|
2160
|
+
s(:call, nil, :b))
|
2158
2161
|
|
2159
2162
|
assert_parse rp, pt
|
2160
2163
|
end
|
@@ -2162,8 +2165,8 @@ module TestRubyParserShared
|
|
2162
2165
|
def test_str_double_double_escaped_newline
|
2163
2166
|
rp = "a \"\\\\n\";b"
|
2164
2167
|
pt = s(:block,
|
2165
|
-
s(:call, nil, :a, s(:str, "\\n")
|
2166
|
-
s(:call, nil, :b)
|
2168
|
+
s(:call, nil, :a, s(:str, "\\n")),
|
2169
|
+
s(:call, nil, :b))
|
2167
2170
|
|
2168
2171
|
assert_parse rp, pt
|
2169
2172
|
end
|
@@ -2555,7 +2558,7 @@ module TestRubyParserShared19Plus
|
|
2555
2558
|
nil,
|
2556
2559
|
:private,
|
2557
2560
|
s(:defn, :f, s(:args),
|
2558
|
-
s(:iter, s(:call, s(:call, nil, :a), :b), 0)))
|
2561
|
+
s(:iter, s(:call, s(:call, nil, :a).line(2), :b).line(2), 0).line(2)))
|
2559
2562
|
|
2560
2563
|
assert_parse rb, pt
|
2561
2564
|
end
|
@@ -2633,7 +2636,10 @@ module TestRubyParserShared19Plus
|
|
2633
2636
|
|
2634
2637
|
def test_call_assoc_new_if_multiline
|
2635
2638
|
rb = "a(b: if :c\n1\nelse\n2\nend)"
|
2636
|
-
pt = s(:call, nil, :a,
|
2639
|
+
pt = s(:call, nil, :a,
|
2640
|
+
s(:hash,
|
2641
|
+
s(:lit, :b),
|
2642
|
+
s(:if, s(:lit, :c), s(:lit, 1).line(2), s(:lit, 2).line(4))))
|
2637
2643
|
|
2638
2644
|
assert_parse rb, pt
|
2639
2645
|
end
|
@@ -2722,8 +2728,8 @@ module TestRubyParserShared19Plus
|
|
2722
2728
|
def test_defn_opt_last_arg
|
2723
2729
|
rb = "def m arg = false\nend"
|
2724
2730
|
pt = s(:defn, :m,
|
2725
|
-
s(:args, s(:lasgn, :arg, s(:false)
|
2726
|
-
s(:nil)
|
2731
|
+
s(:args, s(:lasgn, :arg, s(:false))),
|
2732
|
+
s(:nil))
|
2727
2733
|
|
2728
2734
|
assert_parse rb, pt
|
2729
2735
|
end
|
@@ -2780,7 +2786,7 @@ module TestRubyParserShared19Plus
|
|
2780
2786
|
rb = "1 ? b('') : 2\na d: 3"
|
2781
2787
|
pt = s(:block,
|
2782
2788
|
s(:if, s(:lit, 1), s(:call, nil, :b, s(:str, "")), s(:lit, 2)),
|
2783
|
-
s(:call, nil, :a, s(:hash, s(:lit, :d), s(:lit, 3))))
|
2789
|
+
s(:call, nil, :a, s(:hash, s(:lit, :d).line(2), s(:lit, 3).line(2)).line(2)).line(2))
|
2784
2790
|
|
2785
2791
|
assert_parse rb, pt
|
2786
2792
|
end
|
@@ -3181,9 +3187,9 @@ module TestRubyParserShared19Plus
|
|
3181
3187
|
rb = "a\n.b\n#.c\n.d"
|
3182
3188
|
pt = s(:call,
|
3183
3189
|
s(:call,
|
3184
|
-
s(:call, nil, :a)
|
3185
|
-
:b)
|
3186
|
-
:d)
|
3190
|
+
s(:call, nil, :a),
|
3191
|
+
:b),
|
3192
|
+
:d) # TODO: fix linenos: 1, 2, 4
|
3187
3193
|
|
3188
3194
|
assert_parse rb, pt
|
3189
3195
|
end
|
@@ -3204,8 +3210,8 @@ module TestRubyParserShared19Plus
|
|
3204
3210
|
|
3205
3211
|
def test_motherfuckin_leading_dots2
|
3206
3212
|
rb = "1\n..3"
|
3207
|
-
pt = s(:block, s(:lit, 1)
|
3208
|
-
s(:dot2, nil, s(:lit, 3).line(2)).line(2))
|
3213
|
+
pt = s(:block, s(:lit, 1),
|
3214
|
+
s(:dot2, nil, s(:lit, 3).line(2)).line(2))
|
3209
3215
|
|
3210
3216
|
if processor.class.version >= 27
|
3211
3217
|
assert_parse rb, pt
|
@@ -3219,6 +3225,8 @@ module TestRubyParserShared19Plus
|
|
3219
3225
|
|
3220
3226
|
assert_parse "f(state: {})", pt
|
3221
3227
|
assert_parse "f(state: {\n})", pt
|
3228
|
+
|
3229
|
+
pt = s(:call, nil, :f, s(:hash, s(:lit, :state), s(:hash).line(2)))
|
3222
3230
|
assert_parse "f(state:\n {\n})", pt
|
3223
3231
|
end
|
3224
3232
|
|
@@ -3281,7 +3289,7 @@ module TestRubyParserShared19Plus
|
|
3281
3289
|
rb = "until not var.nil?\n 'foo'\nend"
|
3282
3290
|
pt = s(:until,
|
3283
3291
|
s(:call, s(:call, s(:call, nil, :var), :nil?), :"!"),
|
3284
|
-
s(:str, "foo"), true)
|
3292
|
+
s(:str, "foo").line(2), true)
|
3285
3293
|
|
3286
3294
|
assert_parse rb, pt
|
3287
3295
|
end
|
@@ -3290,7 +3298,7 @@ module TestRubyParserShared19Plus
|
|
3290
3298
|
rb = "until not var.nil?\n 'foo'\nend"
|
3291
3299
|
pt = s(:until,
|
3292
3300
|
s(:call, s(:call, s(:call, nil, :var), :nil?), :"!"),
|
3293
|
-
s(:str, "foo"), true)
|
3301
|
+
s(:str, "foo").line(2), true)
|
3294
3302
|
|
3295
3303
|
processor.canonicalize_conditions = false
|
3296
3304
|
|
@@ -3301,7 +3309,7 @@ module TestRubyParserShared19Plus
|
|
3301
3309
|
rb = "while not var.nil?\n 'foo'\nend"
|
3302
3310
|
pt = s(:while,
|
3303
3311
|
s(:call, s(:call, s(:call, nil, :var), :nil?), :"!"),
|
3304
|
-
s(:str, "foo"), true)
|
3312
|
+
s(:str, "foo").line(2), true)
|
3305
3313
|
|
3306
3314
|
assert_parse rb, pt
|
3307
3315
|
end
|
@@ -3310,7 +3318,7 @@ module TestRubyParserShared19Plus
|
|
3310
3318
|
rb = "while not var.nil?\n 'foo'\nend"
|
3311
3319
|
pt = s(:while,
|
3312
3320
|
s(:call, s(:call, s(:call, nil, :var), :nil?), :"!"),
|
3313
|
-
s(:str, "foo"), true)
|
3321
|
+
s(:str, "foo").line(2), true)
|
3314
3322
|
|
3315
3323
|
processor.canonicalize_conditions = false
|
3316
3324
|
|
@@ -3474,14 +3482,16 @@ module TestRubyParserShared19Plus
|
|
3474
3482
|
RUBY
|
3475
3483
|
|
3476
3484
|
pt = s(:hash,
|
3477
|
-
s(:lit, :a),
|
3485
|
+
s(:lit, :a).line(2),
|
3478
3486
|
s(:iter,
|
3479
|
-
s(:call, nil, :lambda),
|
3487
|
+
s(:call, nil, :lambda).line(2),
|
3480
3488
|
0,
|
3481
|
-
s(:if, s(:call, nil, :b)
|
3489
|
+
s(:if, s(:call, nil, :b).line(2),
|
3490
|
+
s(:call, nil, :c).line(2),
|
3491
|
+
s(:call, nil, :d).line(2)).line(2)).line(2),
|
3482
3492
|
|
3483
|
-
s(:lit, :e),
|
3484
|
-
s(:nil))
|
3493
|
+
s(:lit, :e).line(3),
|
3494
|
+
s(:nil).line(3))
|
3485
3495
|
|
3486
3496
|
assert_parse rb, pt
|
3487
3497
|
end
|
@@ -3543,15 +3553,15 @@ module TestRubyParserShared20Plus
|
|
3543
3553
|
s(:call,
|
3544
3554
|
s(:call, s(:str, " a\n"), :+,
|
3545
3555
|
s(:str, "b\n c")),
|
3546
|
-
:+, s(:str, "d")))
|
3556
|
+
:+, s(:str, "d").line(4)))
|
3547
3557
|
|
3548
3558
|
assert_parse rb, pt
|
3549
3559
|
end
|
3550
3560
|
|
3551
3561
|
def test_heredoc_nested
|
3552
3562
|
rb = "[<<A,\n\#{<<B}\nb\nB\na\nA\n0]"
|
3553
|
-
pt = s(:array, s(:str, "b\n\na\n")
|
3554
|
-
s(:lit, 0).line(7))
|
3563
|
+
pt = s(:array, s(:str, "b\n\na\n"),
|
3564
|
+
s(:lit, 0).line(7))
|
3555
3565
|
|
3556
3566
|
assert_parse rb, pt
|
3557
3567
|
end
|
@@ -3562,8 +3572,8 @@ module TestRubyParserShared20Plus
|
|
3562
3572
|
s(:str, "1"),
|
3563
3573
|
s(:str, "2\n"),
|
3564
3574
|
s(:str, "3"),
|
3565
|
-
s(:str, "4"),
|
3566
|
-
s(:str, "5"))
|
3575
|
+
s(:str, "4").line(4),
|
3576
|
+
s(:str, "5").line(4))
|
3567
3577
|
|
3568
3578
|
assert_parse rb, pt
|
3569
3579
|
end
|
@@ -3668,7 +3678,7 @@ module TestRubyParserShared20Plus
|
|
3668
3678
|
rb = "a (b)\nc.d do end"
|
3669
3679
|
pt = s(:block,
|
3670
3680
|
s(:call, nil, :a, s(:call, nil, :b)),
|
3671
|
-
s(:iter, s(:call, s(:call, nil, :c), :d), 0))
|
3681
|
+
s(:iter, s(:call, s(:call, nil, :c).line(2), :d).line(2), 0).line(2))
|
3672
3682
|
|
3673
3683
|
|
3674
3684
|
assert_parse rb, pt
|
@@ -3678,8 +3688,9 @@ module TestRubyParserShared20Plus
|
|
3678
3688
|
rb = "a def b(c)\n d\n end\n e.f do end"
|
3679
3689
|
pt = s(:block,
|
3680
3690
|
s(:call, nil, :a,
|
3681
|
-
s(:defn, :b, s(:args, :c),
|
3682
|
-
|
3691
|
+
s(:defn, :b, s(:args, :c),
|
3692
|
+
s(:call, nil, :d).line(2))),
|
3693
|
+
s(:iter, s(:call, s(:call, nil, :e).line(4), :f).line(4), 0).line(4))
|
3683
3694
|
|
3684
3695
|
assert_parse rb, pt
|
3685
3696
|
end
|
@@ -3697,7 +3708,9 @@ module TestRubyParserShared20Plus
|
|
3697
3708
|
def test_call_begin_call_block_call
|
3698
3709
|
rb = "a begin\nb.c do end\nend"
|
3699
3710
|
pt = s(:call, nil, :a,
|
3700
|
-
s(:iter,
|
3711
|
+
s(:iter,
|
3712
|
+
s(:call, s(:call, nil, :b).line(2), :c).line(2),
|
3713
|
+
0).line(2))
|
3701
3714
|
|
3702
3715
|
assert_parse rb, pt
|
3703
3716
|
end
|
@@ -3708,7 +3721,7 @@ module TestRubyParserShared20Plus
|
|
3708
3721
|
s(:op_asgn, s(:const, :B),
|
3709
3722
|
s(:call, nil, :d, s(:call, nil, :e)),
|
3710
3723
|
:C,
|
3711
|
-
:*))
|
3724
|
+
:*))
|
3712
3725
|
|
3713
3726
|
assert_parse rb, pt
|
3714
3727
|
end
|
@@ -3766,9 +3779,9 @@ module TestRubyParserShared20Plus
|
|
3766
3779
|
s(:iter,
|
3767
3780
|
s(:call, s(:const, :Class), :new),
|
3768
3781
|
0,
|
3769
|
-
s(:defn, :initialize, s(:args), s(:nil))),
|
3782
|
+
s(:defn, :initialize, s(:args).line(2), s(:nil).line(2)).line(2)),
|
3770
3783
|
:new),
|
3771
|
-
s(:hash, s(:lit, :at), s(:str, "endpoint")))
|
3784
|
+
s(:hash, s(:lit, :at).line(4), s(:str, "endpoint").line(4)).line(4))
|
3772
3785
|
|
3773
3786
|
assert_parse rb, pt
|
3774
3787
|
end
|
@@ -3875,8 +3888,8 @@ module TestRubyParserShared20Plus
|
|
3875
3888
|
pt = s(:block,
|
3876
3889
|
s(:array,
|
3877
3890
|
s(:lit, :a).line(2),
|
3878
|
-
s(:lit, :b).line(3))
|
3879
|
-
s(:lit, 1).line(5))
|
3891
|
+
s(:lit, :b).line(3)),
|
3892
|
+
s(:lit, 1).line(5))
|
3880
3893
|
assert_parse rb, pt
|
3881
3894
|
end
|
3882
3895
|
|
@@ -3913,7 +3926,7 @@ module TestRubyParserShared20Plus
|
|
3913
3926
|
pt = s(:block,
|
3914
3927
|
s(:array,
|
3915
3928
|
s(:lit, :a).line(2),
|
3916
|
-
s(:lit, :b).line(3))
|
3929
|
+
s(:lit, :b).line(3)),
|
3917
3930
|
s(:lit, 1).line(5))
|
3918
3931
|
assert_parse rb, pt
|
3919
3932
|
end
|
@@ -3955,7 +3968,7 @@ module TestRubyParserShared20Plus
|
|
3955
3968
|
s(:iter,
|
3956
3969
|
s(:lambda),
|
3957
3970
|
s(:args),
|
3958
|
-
s(:iter, s(:call, s(:call, nil, :a), :b), 0)))
|
3971
|
+
s(:iter, s(:call, s(:call, nil, :a).line(2), :b).line(2), 0).line(2)))
|
3959
3972
|
|
3960
3973
|
assert_parse rb, pt
|
3961
3974
|
end
|
@@ -3968,7 +3981,7 @@ module TestRubyParserShared20Plus
|
|
3968
3981
|
s(:args),
|
3969
3982
|
s(:iter,
|
3970
3983
|
s(:call, nil, :a,
|
3971
|
-
s(:lit, 1)), 0)))
|
3984
|
+
s(:lit, 1).line(2)).line(2), 0).line(2)))
|
3972
3985
|
|
3973
3986
|
assert_parse rb, pt
|
3974
3987
|
end
|
@@ -4075,8 +4088,8 @@ module TestRubyParserShared21Plus
|
|
4075
4088
|
CODE
|
4076
4089
|
|
4077
4090
|
pt = s(:block,
|
4078
|
-
s(:str, "\n\n\n\n\n\n\n\n\n\n")
|
4079
|
-
s(:class, :Foo, nil).line(5))
|
4091
|
+
s(:str, "\n\n\n\n\n\n\n\n\n\n"),
|
4092
|
+
s(:class, :Foo, nil).line(5))
|
4080
4093
|
|
4081
4094
|
assert_parse rb, pt
|
4082
4095
|
end
|
@@ -4205,8 +4218,8 @@ module TestRubyParserShared23Plus
|
|
4205
4218
|
def test_heredoc_squiggly_interp
|
4206
4219
|
rb = "a = <<~EOF\n w\n x#\{42} y\n z\n EOF"
|
4207
4220
|
pt = s(:lasgn, :a, s(:dstr, " w\nx",
|
4208
|
-
s(:evstr, s(:lit, 42)),
|
4209
|
-
s(:str, " y\n z\n")))
|
4221
|
+
s(:evstr, s(:lit, 42).line(3)).line(3),
|
4222
|
+
s(:str, " y\n z\n").line(3)))
|
4210
4223
|
|
4211
4224
|
assert_parse rb, pt
|
4212
4225
|
end
|
@@ -4324,7 +4337,7 @@ module TestRubyParserShared23Plus
|
|
4324
4337
|
|
4325
4338
|
def test_safe_call_operator
|
4326
4339
|
rb = "a&.> 1"
|
4327
|
-
pt = s(:safe_call, s(:call, nil, :a), :>, s(:lit, 1))
|
4340
|
+
pt = s(:safe_call, s(:call, nil, :a), :>, s(:lit, 1))
|
4328
4341
|
|
4329
4342
|
assert_parse rb, pt
|
4330
4343
|
end
|
@@ -4345,14 +4358,15 @@ module TestRubyParserShared23Plus
|
|
4345
4358
|
|
4346
4359
|
def test_safe_op_asgn
|
4347
4360
|
rb = "a&.b += x 1"
|
4348
|
-
pt = s(:safe_op_asgn, s(:call, nil, :a), s(:call, nil, :x, s(:lit, 1)), :b, :+)
|
4361
|
+
pt = s(:safe_op_asgn, s(:call, nil, :a), s(:call, nil, :x, s(:lit, 1)), :b, :+)
|
4349
4362
|
|
4350
4363
|
assert_parse rb, pt
|
4351
4364
|
end
|
4352
4365
|
|
4353
4366
|
def test_safe_op_asgn2
|
4354
4367
|
rb = "a&.b ||=\nx;"
|
4355
|
-
pt = s(:safe_op_asgn2,
|
4368
|
+
pt = s(:safe_op_asgn2,
|
4369
|
+
s(:call, nil, :a), :b=, :"||", s(:call, nil, :x).line(2))
|
4356
4370
|
|
4357
4371
|
assert_parse rb, pt
|
4358
4372
|
end
|
@@ -4367,11 +4381,11 @@ a + b
|
|
4367
4381
|
)
|
4368
4382
|
|
4369
4383
|
pt = s(:block,
|
4370
|
-
s(:call, nil, :puts, s(:str, "hello my dear friend")
|
4384
|
+
s(:call, nil, :puts, s(:str, "hello my dear friend")),
|
4371
4385
|
s(:call, s(:call, nil, :a).line(6),
|
4372
4386
|
:+,
|
4373
4387
|
s(:call, nil, :b).line(6)).line(6)
|
4374
|
-
)
|
4388
|
+
)
|
4375
4389
|
|
4376
4390
|
assert_parse rb, pt
|
4377
4391
|
end
|
@@ -4429,8 +4443,8 @@ module TestRubyParserShared26Plus
|
|
4429
4443
|
def test_symbol_list
|
4430
4444
|
rb = '%I[#{a} #{b}]'
|
4431
4445
|
pt = s(:array,
|
4432
|
-
s(:dsym, "", s(:evstr, s(:call, nil, :a))
|
4433
|
-
s(:dsym, "", s(:evstr, s(:call, nil, :b))
|
4446
|
+
s(:dsym, "", s(:evstr, s(:call, nil, :a))),
|
4447
|
+
s(:dsym, "", s(:evstr, s(:call, nil, :b)))).line 1
|
4434
4448
|
|
4435
4449
|
assert_parse rb, pt
|
4436
4450
|
end
|
@@ -4451,9 +4465,9 @@ module TestPatternMatching
|
|
4451
4465
|
puts rb
|
4452
4466
|
end
|
4453
4467
|
|
4454
|
-
pt = s(:case, s(:lit, :a)
|
4468
|
+
pt = s(:case, s(:lit, :a),
|
4455
4469
|
s(:in, exp_pt, nil).line(2),
|
4456
|
-
nil)
|
4470
|
+
nil)
|
4457
4471
|
|
4458
4472
|
assert_parse rb, pt
|
4459
4473
|
end
|
@@ -4507,11 +4521,11 @@ module TestPatternMatching
|
|
4507
4521
|
|
4508
4522
|
def test_case_in_31?
|
4509
4523
|
rb = "case :a\nin [:b, *c]\n :d\nend"
|
4510
|
-
pt = s(:case, s(:lit, :a)
|
4524
|
+
pt = s(:case, s(:lit, :a),
|
4511
4525
|
s(:in,
|
4512
4526
|
s(:array_pat, nil, s(:lit, :b).line(2), :"*c").line(2),
|
4513
4527
|
s(:lit, :d).line(3)).line(2),
|
4514
|
-
nil)
|
4528
|
+
nil)
|
4515
4529
|
|
4516
4530
|
assert_parse rb, pt
|
4517
4531
|
end
|
@@ -4550,7 +4564,7 @@ module TestPatternMatching
|
|
4550
4564
|
|
4551
4565
|
def test_case_in_37
|
4552
4566
|
rb = "case :a\nin { b: [Hash, *] }\n :c\nend"
|
4553
|
-
pt = s(:case, s(:lit, :a)
|
4567
|
+
pt = s(:case, s(:lit, :a),
|
4554
4568
|
s(:in,
|
4555
4569
|
s(:hash_pat,
|
4556
4570
|
nil,
|
@@ -4558,14 +4572,14 @@ module TestPatternMatching
|
|
4558
4572
|
s(:array_pat, nil, s(:const, :Hash).line(2), :"*").line(2)
|
4559
4573
|
).line(2),
|
4560
4574
|
s(:lit, :c).line(3)).line(2),
|
4561
|
-
nil)
|
4575
|
+
nil)
|
4562
4576
|
|
4563
4577
|
assert_parse rb, pt
|
4564
4578
|
end
|
4565
4579
|
|
4566
4580
|
def test_case_in_42
|
4567
4581
|
rb = "case :a\nin :b, *_ then nil\nend"
|
4568
|
-
pt = s(:case, s(:lit, :a)
|
4582
|
+
pt = s(:case, s(:lit, :a),
|
4569
4583
|
s(:in,
|
4570
4584
|
s(:array_pat,
|
4571
4585
|
nil,
|
@@ -4573,20 +4587,20 @@ module TestPatternMatching
|
|
4573
4587
|
:"*_",
|
4574
4588
|
).line(2),
|
4575
4589
|
s(:nil).line(2)).line(2),
|
4576
|
-
nil)
|
4590
|
+
nil)
|
4577
4591
|
|
4578
4592
|
assert_parse rb, pt
|
4579
4593
|
end
|
4580
4594
|
|
4581
4595
|
def test_case_in_42_2
|
4582
4596
|
rb = "case :a\nin A(*list) then nil\nend"
|
4583
|
-
pt = s(:case, s(:lit, :a)
|
4597
|
+
pt = s(:case, s(:lit, :a),
|
4584
4598
|
s(:in,
|
4585
4599
|
s(:array_pat,
|
4586
4600
|
s(:const, :A).line(2),
|
4587
4601
|
:"*list").line(2),
|
4588
4602
|
s(:nil).line(2)).line(2),
|
4589
|
-
nil)
|
4603
|
+
nil)
|
4590
4604
|
|
4591
4605
|
assert_parse rb, pt
|
4592
4606
|
end
|
@@ -4601,12 +4615,12 @@ module TestPatternMatching
|
|
4601
4615
|
|
4602
4616
|
def test_case_in_47
|
4603
4617
|
rb = "case :a\nin [*, :b, :c]\n :d\nend"
|
4604
|
-
pt = s(:case, s(:lit, :a)
|
4618
|
+
pt = s(:case, s(:lit, :a),
|
4605
4619
|
s(:in,
|
4606
4620
|
s(:array_pat, nil, :*,
|
4607
4621
|
s(:lit, :b).line(2), s(:lit, :c).line(2)).line(2),
|
4608
4622
|
s(:lit, :d).line(3)).line(2),
|
4609
|
-
nil)
|
4623
|
+
nil)
|
4610
4624
|
|
4611
4625
|
assert_parse rb, pt
|
4612
4626
|
end
|
@@ -4614,10 +4628,10 @@ module TestPatternMatching
|
|
4614
4628
|
def test_case_in_67
|
4615
4629
|
rb = "case :a\nin 1.. then nil\nend"
|
4616
4630
|
pt = s(:case,
|
4617
|
-
s(:lit, :a)
|
4631
|
+
s(:lit, :a),
|
4618
4632
|
s(:in, s(:dot2, s(:lit, 1).line(2), nil).line(2),
|
4619
4633
|
s(:nil).line(2)).line(2),
|
4620
|
-
nil)
|
4634
|
+
nil)
|
4621
4635
|
|
4622
4636
|
assert_parse rb, pt
|
4623
4637
|
end
|
@@ -4674,14 +4688,14 @@ module TestPatternMatching
|
|
4674
4688
|
def test_case_in_86
|
4675
4689
|
rb = "case [:a, :b]\nin ::NilClass, * then nil\nend"
|
4676
4690
|
pt = s(:case,
|
4677
|
-
s(:array, s(:lit, :a)
|
4691
|
+
s(:array, s(:lit, :a), s(:lit, :b)),
|
4678
4692
|
s(:in,
|
4679
4693
|
s(:array_pat,
|
4680
4694
|
nil,
|
4681
4695
|
s(:colon3, :NilClass).line(2),
|
4682
4696
|
:*).line(2),
|
4683
4697
|
s(:nil).line(2)).line(2),
|
4684
|
-
nil)
|
4698
|
+
nil)
|
4685
4699
|
|
4686
4700
|
assert_parse rb, pt
|
4687
4701
|
end
|
@@ -4689,60 +4703,60 @@ module TestPatternMatching
|
|
4689
4703
|
def test_case_in_86_2
|
4690
4704
|
rb = "case [:a, :b]\nin *, ::NilClass then nil\nend"
|
4691
4705
|
pt = s(:case,
|
4692
|
-
s(:array, s(:lit, :a)
|
4706
|
+
s(:array, s(:lit, :a), s(:lit, :b)),
|
4693
4707
|
s(:in,
|
4694
4708
|
s(:array_pat,
|
4695
4709
|
nil,
|
4696
4710
|
:*,
|
4697
4711
|
s(:colon3, :NilClass).line(2)).line(2),
|
4698
4712
|
s(:nil).line(2)).line(2),
|
4699
|
-
nil)
|
4713
|
+
nil)
|
4700
4714
|
|
4701
4715
|
assert_parse rb, pt
|
4702
4716
|
end
|
4703
4717
|
|
4704
4718
|
def test_case_in_array_pat_const
|
4705
4719
|
rb = "case :a\nin B[c]\n :d\nend"
|
4706
|
-
pt = s(:case, s(:lit, :a)
|
4720
|
+
pt = s(:case, s(:lit, :a),
|
4707
4721
|
s(:in,
|
4708
4722
|
s(:array_pat,
|
4709
4723
|
s(:const, :B).line(2),
|
4710
4724
|
s(:lvar, :c).line(2)).line(2),
|
4711
4725
|
s(:lit, :d).line(3)).line(2),
|
4712
|
-
nil)
|
4726
|
+
nil)
|
4713
4727
|
|
4714
4728
|
assert_parse rb, pt
|
4715
4729
|
end
|
4716
4730
|
|
4717
4731
|
def test_case_in_array_pat_const2
|
4718
4732
|
rb = "case :a\nin B::C[d]\n :e\nend"
|
4719
|
-
pt = s(:case, s(:lit, :a)
|
4733
|
+
pt = s(:case, s(:lit, :a),
|
4720
4734
|
s(:in,
|
4721
4735
|
s(:array_pat,
|
4722
4736
|
s(:const, s(:colon2, s(:const, :B).line(2), :C).line(2)).line(2),
|
4723
4737
|
s(:lvar, :d).line(2)).line(2),
|
4724
4738
|
s(:lit, :e).line(3)).line(2),
|
4725
|
-
nil)
|
4739
|
+
nil)
|
4726
4740
|
|
4727
4741
|
assert_parse rb, pt
|
4728
4742
|
end
|
4729
4743
|
|
4730
4744
|
def test_case_in_array_pat_paren_assign
|
4731
4745
|
rb = "case :a\nin B(C => d)\n :d\nend"
|
4732
|
-
pt = s(:case, s(:lit, :a)
|
4746
|
+
pt = s(:case, s(:lit, :a),
|
4733
4747
|
s(:in,
|
4734
4748
|
s(:array_pat,
|
4735
4749
|
s(:const, :B).line(2),
|
4736
4750
|
s(:lasgn, :d, s(:const, :C).line(2)).line(2)).line(2),
|
4737
4751
|
s(:lit, :d).line(3)).line(2),
|
4738
|
-
nil)
|
4752
|
+
nil)
|
4739
4753
|
|
4740
4754
|
assert_parse rb, pt
|
4741
4755
|
end
|
4742
4756
|
|
4743
4757
|
def test_case_in_const
|
4744
4758
|
rb = "case Array\nin Class\n :b\nend"
|
4745
|
-
pt = s(:case, s(:const, :Array)
|
4759
|
+
pt = s(:case, s(:const, :Array),
|
4746
4760
|
s(:in, s(:const, :Class).line(2),
|
4747
4761
|
s(:lit, :b).line(3)).line(2),
|
4748
4762
|
nil).line 1
|
@@ -4752,7 +4766,7 @@ module TestPatternMatching
|
|
4752
4766
|
|
4753
4767
|
def test_case_in_else
|
4754
4768
|
rb = "case Array\nin Class\n :b\nelse\n :c\nend\n"
|
4755
|
-
pt = s(:case, s(:const, :Array)
|
4769
|
+
pt = s(:case, s(:const, :Array),
|
4756
4770
|
s(:in, s(:const, :Class).line(2),
|
4757
4771
|
s(:lit, :b).line(3)).line(2),
|
4758
4772
|
s(:lit, :c).line(5)).line 1
|
@@ -4762,7 +4776,7 @@ module TestPatternMatching
|
|
4762
4776
|
|
4763
4777
|
def test_case_in_hash_pat
|
4764
4778
|
rb = "case :a\nin { b: 'c', d: \"e\" } then\n :f\nend\n"
|
4765
|
-
pt = s(:case, s(:lit, :a)
|
4779
|
+
pt = s(:case, s(:lit, :a),
|
4766
4780
|
s(:in,
|
4767
4781
|
s(:hash_pat,
|
4768
4782
|
nil,
|
@@ -4770,14 +4784,14 @@ module TestPatternMatching
|
|
4770
4784
|
s(:lit, :d).line(2), s(:str, "e").line(2)).line(2),
|
4771
4785
|
s(:lit, :f).line(3)
|
4772
4786
|
).line(2),
|
4773
|
-
nil)
|
4787
|
+
nil)
|
4774
4788
|
|
4775
4789
|
assert_parse rb, pt
|
4776
4790
|
end
|
4777
4791
|
|
4778
4792
|
def test_case_in_hash_pat_assign
|
4779
4793
|
rb = "case :a\nin { b: Integer => x, d: \"e\", f: } then\n :g\nend"
|
4780
|
-
pt = s(:case, s(:lit, :a)
|
4794
|
+
pt = s(:case, s(:lit, :a),
|
4781
4795
|
s(:in,
|
4782
4796
|
s(:hash_pat,
|
4783
4797
|
nil,
|
@@ -4786,33 +4800,33 @@ module TestPatternMatching
|
|
4786
4800
|
s(:lit, :d).line(2), s(:str, "e").line(2),
|
4787
4801
|
s(:lit, :f).line(2), nil).line(2),
|
4788
4802
|
s(:lit, :g).line(3)).line(2),
|
4789
|
-
nil)
|
4803
|
+
nil)
|
4790
4804
|
|
4791
4805
|
assert_parse rb, pt
|
4792
4806
|
end
|
4793
4807
|
|
4794
4808
|
def test_case_in_hash_pat_paren_assign
|
4795
4809
|
rb = "case :a\nin B(a: 42)\n :d\nend"
|
4796
|
-
pt = s(:case, s(:lit, :a)
|
4810
|
+
pt = s(:case, s(:lit, :a),
|
4797
4811
|
s(:in,
|
4798
4812
|
s(:hash_pat,
|
4799
4813
|
s(:const, :B).line(2),
|
4800
4814
|
s(:lit, :a).line(2), s(:lit, 42).line(2)).line(2),
|
4801
4815
|
s(:lit, :d).line(3)).line(2),
|
4802
|
-
nil)
|
4816
|
+
nil)
|
4803
4817
|
|
4804
4818
|
assert_parse rb, pt
|
4805
4819
|
end
|
4806
4820
|
|
4807
4821
|
def test_case_in_hash_pat_paren_true
|
4808
4822
|
rb = "case :a\nin b: true then\n :c\nend\n"
|
4809
|
-
pt = s(:case, s(:lit, :a)
|
4823
|
+
pt = s(:case, s(:lit, :a),
|
4810
4824
|
s(:in,
|
4811
4825
|
s(:hash_pat,
|
4812
4826
|
nil,
|
4813
4827
|
s(:lit, :b).line(2), s(:true).line(2)).line(2),
|
4814
4828
|
s(:lit, :c).line(3)).line(2),
|
4815
|
-
nil)
|
4829
|
+
nil)
|
4816
4830
|
|
4817
4831
|
assert_parse rb, pt
|
4818
4832
|
end
|
@@ -4820,7 +4834,7 @@ module TestPatternMatching
|
|
4820
4834
|
def test_case_in_hash_pat_rest
|
4821
4835
|
rb = "case :a\nin b: c, **rest then :d\nend"
|
4822
4836
|
pt = s(:case,
|
4823
|
-
s(:lit, :a)
|
4837
|
+
s(:lit, :a),
|
4824
4838
|
s(:in,
|
4825
4839
|
s(:hash_pat,
|
4826
4840
|
nil,
|
@@ -4828,7 +4842,7 @@ module TestPatternMatching
|
|
4828
4842
|
s(:lvar, :c).line(2),
|
4829
4843
|
s(:kwrest, :"**rest").line(2)).line(2),
|
4830
4844
|
s(:lit, :d).line(2)).line(2),
|
4831
|
-
nil)
|
4845
|
+
nil)
|
4832
4846
|
|
4833
4847
|
assert_parse rb, pt
|
4834
4848
|
end
|
@@ -4836,13 +4850,13 @@ module TestPatternMatching
|
|
4836
4850
|
def test_case_in_hash_pat_rest_solo
|
4837
4851
|
rb = "case :a\nin **rest then :d\nend"
|
4838
4852
|
pt = s(:case,
|
4839
|
-
s(:lit, :a)
|
4853
|
+
s(:lit, :a),
|
4840
4854
|
s(:in,
|
4841
4855
|
s(:hash_pat,
|
4842
4856
|
nil,
|
4843
4857
|
s(:kwrest, :"**rest").line(2)).line(2),
|
4844
4858
|
s(:lit, :d).line(2)).line(2),
|
4845
|
-
nil)
|
4859
|
+
nil)
|
4846
4860
|
|
4847
4861
|
assert_parse rb, pt
|
4848
4862
|
end
|
@@ -4850,14 +4864,14 @@ module TestPatternMatching
|
|
4850
4864
|
def test_case_in_if_unless_post_mod
|
4851
4865
|
rb = "case :a\nin A if true\n :C\nin D unless false\n :E\nend"
|
4852
4866
|
pt = s(:case,
|
4853
|
-
s(:lit, :a)
|
4867
|
+
s(:lit, :a),
|
4854
4868
|
s(:in,
|
4855
4869
|
s(:if, s(:true).line(2), s(:const, :A).line(2), nil).line(2),
|
4856
4870
|
s(:lit, :C).line(3)).line(2),
|
4857
4871
|
s(:in,
|
4858
4872
|
s(:if, s(:false).line(4), nil, s(:const, :D).line(4)).line(4),
|
4859
4873
|
s(:lit, :E).line(5)).line(4),
|
4860
|
-
nil)
|
4874
|
+
nil)
|
4861
4875
|
|
4862
4876
|
assert_parse rb, pt
|
4863
4877
|
end
|
@@ -4865,37 +4879,37 @@ module TestPatternMatching
|
|
4865
4879
|
def test_case_in_multiple
|
4866
4880
|
rb = "case :a\nin A::B\n :C\nin D::E\n :F\nend"
|
4867
4881
|
pt = s(:case,
|
4868
|
-
s(:lit, :a)
|
4882
|
+
s(:lit, :a),
|
4869
4883
|
s(:in,
|
4870
4884
|
s(:const, s(:colon2, s(:const, :A).line(2), :B).line(2)).line(2),
|
4871
4885
|
s(:lit, :C).line(3)).line(2),
|
4872
4886
|
s(:in,
|
4873
4887
|
s(:const, s(:colon2, s(:const, :D).line(4), :E).line(4)).line(4),
|
4874
4888
|
s(:lit, :F).line(5)).line(4),
|
4875
|
-
nil)
|
4889
|
+
nil)
|
4876
4890
|
|
4877
4891
|
assert_parse rb, pt
|
4878
4892
|
end
|
4879
4893
|
|
4880
4894
|
def test_case_in_or
|
4881
4895
|
rb = "case :a\nin B | C\n :d\nend\n"
|
4882
|
-
pt = s(:case, s(:lit, :a)
|
4896
|
+
pt = s(:case, s(:lit, :a),
|
4883
4897
|
s(:in,
|
4884
4898
|
s(:or,
|
4885
4899
|
s(:const, :B).line(2),
|
4886
4900
|
s(:const, :C).line(2)).line(2),
|
4887
4901
|
s(:lit, :d).line(3)).line(2),
|
4888
|
-
nil)
|
4902
|
+
nil)
|
4889
4903
|
|
4890
4904
|
assert_parse rb, pt
|
4891
4905
|
end
|
4892
4906
|
|
4893
4907
|
def test_in_expr_no_case
|
4894
4908
|
rb = "'woot' in String"
|
4895
|
-
pt = s(:case, s(:str, "woot")
|
4896
|
-
s(:in, s(:const, :String)
|
4897
|
-
nil)
|
4898
|
-
nil)
|
4909
|
+
pt = s(:case, s(:str, "woot"),
|
4910
|
+
s(:in, s(:const, :String),
|
4911
|
+
nil),
|
4912
|
+
nil)
|
4899
4913
|
|
4900
4914
|
assert_parse rb, pt
|
4901
4915
|
end
|
@@ -4909,10 +4923,10 @@ module TestPatternMatching
|
|
4909
4923
|
RUBY
|
4910
4924
|
|
4911
4925
|
pt = s(:case,
|
4912
|
-
s(:lit, 0)
|
4926
|
+
s(:lit, 0),
|
4913
4927
|
s(:in, s(:dot2, s(:lit, -1).line(2), s(:lit, 1).line(2)).line(2),
|
4914
4928
|
s(:true).line(3)).line(2),
|
4915
|
-
nil)
|
4929
|
+
nil)
|
4916
4930
|
|
4917
4931
|
assert_parse rb, pt
|
4918
4932
|
end
|
@@ -4925,10 +4939,10 @@ module TestPatternMatching
|
|
4925
4939
|
end
|
4926
4940
|
RUBY
|
4927
4941
|
pt = s(:case,
|
4928
|
-
s(:call, nil, :obj)
|
4942
|
+
s(:call, nil, :obj),
|
4929
4943
|
s(:in, s(:array_pat, s(:const, :Object).line(2)).line(2),
|
4930
4944
|
s(:true).line(3)).line(2),
|
4931
|
-
nil)
|
4945
|
+
nil)
|
4932
4946
|
|
4933
4947
|
assert_parse rb, pt
|
4934
4948
|
end
|
@@ -4942,9 +4956,9 @@ module TestPatternMatching
|
|
4942
4956
|
RUBY
|
4943
4957
|
pt = s(:case,
|
4944
4958
|
s(:array,
|
4945
|
-
s(:lit, 0)
|
4946
|
-
s(:lit, 1)
|
4947
|
-
s(:lit, 2)
|
4959
|
+
s(:lit, 0),
|
4960
|
+
s(:lit, 1),
|
4961
|
+
s(:lit, 2)),
|
4948
4962
|
s(:in,
|
4949
4963
|
s(:array_pat,
|
4950
4964
|
nil,
|
@@ -4952,7 +4966,7 @@ module TestPatternMatching
|
|
4952
4966
|
s(:lit, 1).line(2),
|
4953
4967
|
:*).line(666),
|
4954
4968
|
s(:true).line(3)).line(2),
|
4955
|
-
nil)
|
4969
|
+
nil)
|
4956
4970
|
|
4957
4971
|
assert_parse rb, pt
|
4958
4972
|
end
|
@@ -4966,15 +4980,15 @@ module TestPatternMatching
|
|
4966
4980
|
RUBY
|
4967
4981
|
pt = s(:case,
|
4968
4982
|
s(:hash,
|
4969
|
-
s(:lit, :a)
|
4970
|
-
s(:lit, 0)
|
4983
|
+
s(:lit, :a),
|
4984
|
+
s(:lit, 0)),
|
4971
4985
|
s(:in,
|
4972
4986
|
s(:hash_pat, nil, s(:lit, :a).line(2), nil,
|
4973
4987
|
s(:kwrest, :"**rest").line(2)).line(2),
|
4974
4988
|
s(:array,
|
4975
4989
|
s(:lvar, :a).line(3),
|
4976
4990
|
s(:lvar, :rest).line(3)).line(3)).line(2),
|
4977
|
-
nil)
|
4991
|
+
nil)
|
4978
4992
|
|
4979
4993
|
assert_parse rb, pt
|
4980
4994
|
end
|
@@ -4988,14 +5002,14 @@ module TestPatternMatching
|
|
4988
5002
|
RUBY
|
4989
5003
|
pt = s(:case,
|
4990
5004
|
s(:hash,
|
4991
|
-
s(:lit, :a)
|
4992
|
-
s(:lit, 0)
|
5005
|
+
s(:lit, :a),
|
5006
|
+
s(:lit, 0)),
|
4993
5007
|
s(:in,
|
4994
5008
|
s(:hash_pat, nil, s(:lit, :a).line(2), nil,
|
4995
5009
|
s(:kwrest, :"**").line(2)).line(2),
|
4996
5010
|
s(:array,
|
4997
5011
|
s(:lvar, :a).line(3)).line(3)).line(2),
|
4998
|
-
nil)
|
5012
|
+
nil)
|
4999
5013
|
|
5000
5014
|
assert_parse rb, pt
|
5001
5015
|
end
|
@@ -5008,12 +5022,12 @@ module TestPatternMatching
|
|
5008
5022
|
end
|
5009
5023
|
RUBY
|
5010
5024
|
pt = s(:case,
|
5011
|
-
s(:lit, :a)
|
5025
|
+
s(:lit, :a),
|
5012
5026
|
s(:in,
|
5013
5027
|
s(:hash_pat, s(:const, :Object).line(2),
|
5014
5028
|
s(:lit, :b).line(2), s(:lit, 1).line(2)).line(2),
|
5015
5029
|
s(:lit, 1).line(3)).line(2),
|
5016
|
-
nil)
|
5030
|
+
nil)
|
5017
5031
|
|
5018
5032
|
|
5019
5033
|
assert_parse rb, pt
|
@@ -5027,24 +5041,24 @@ module TestPatternMatching
|
|
5027
5041
|
end
|
5028
5042
|
RUBY
|
5029
5043
|
pt = s(:case,
|
5030
|
-
s(:hash, s(:lit, :a)
|
5044
|
+
s(:hash, s(:lit, :a), s(:lit, 1)),
|
5031
5045
|
s(:in,
|
5032
5046
|
s(:hash_pat, nil,
|
5033
5047
|
s(:lit, :a).line(2), s(:lit, 1).line(2),
|
5034
5048
|
s(:kwrest, :"**nil").line(2)).line(2),
|
5035
5049
|
s(:true).line(3)).line(2),
|
5036
|
-
nil)
|
5050
|
+
nil)
|
5037
5051
|
|
5038
5052
|
assert_parse rb, pt
|
5039
5053
|
end
|
5040
5054
|
|
5041
5055
|
# def test_case_in_TEMPLATE
|
5042
5056
|
# rb = "case :a\nin XXX then\n YYY\nend\n"
|
5043
|
-
# pt = s(:case, s(:lit, :a)
|
5057
|
+
# pt = s(:case, s(:lit, :a),
|
5044
5058
|
# s(:in,
|
5045
5059
|
# ZZZ,
|
5046
5060
|
# WWW).line(2),
|
5047
|
-
# nil)
|
5061
|
+
# nil)
|
5048
5062
|
#
|
5049
5063
|
# assert_parse rb, pt
|
5050
5064
|
# end
|
@@ -5089,7 +5103,7 @@ module TestRubyParserShared27Plus
|
|
5089
5103
|
s(:call, nil, :f),
|
5090
5104
|
s(:args, :"**nil"))
|
5091
5105
|
|
5092
|
-
|
5106
|
+
assert_parse rb, pt
|
5093
5107
|
end
|
5094
5108
|
|
5095
5109
|
def test_defn_forward_args
|
@@ -5097,7 +5111,7 @@ module TestRubyParserShared27Plus
|
|
5097
5111
|
pt = s(:defn, :a, s(:args, s(:forward_args)),
|
5098
5112
|
s(:call, nil, :b, s(:forward_args)))
|
5099
5113
|
|
5100
|
-
|
5114
|
+
assert_parse rb, pt
|
5101
5115
|
end
|
5102
5116
|
|
5103
5117
|
def test_defn_arg_forward_args
|
@@ -5105,7 +5119,7 @@ module TestRubyParserShared27Plus
|
|
5105
5119
|
pt = s(:defn, :a, s(:args, :x, s(:forward_args)),
|
5106
5120
|
s(:call, nil, :b, s(:lvar, :x), s(:forward_args)))
|
5107
5121
|
|
5108
|
-
|
5122
|
+
assert_parse rb, pt
|
5109
5123
|
end
|
5110
5124
|
|
5111
5125
|
def test_defn_args_forward_args
|
@@ -5114,7 +5128,7 @@ module TestRubyParserShared27Plus
|
|
5114
5128
|
s(:call, nil, :b, s(:lit, :get), s(:lvar, :z),
|
5115
5129
|
s(:forward_args)))
|
5116
5130
|
|
5117
|
-
|
5131
|
+
assert_parse rb, pt
|
5118
5132
|
end
|
5119
5133
|
|
5120
5134
|
def test_defn_no_kwargs
|
@@ -5132,10 +5146,10 @@ module TestRubyParserShared27Plus
|
|
5132
5146
|
# z arg: 42 # $!: wrong number of arguments (given 1, expected 0) (ArgumentError)
|
5133
5147
|
|
5134
5148
|
rb = "def x(**nil); end"
|
5135
|
-
pt = s(:defn, :x, s(:args, :"**nil")
|
5136
|
-
s(:nil)
|
5149
|
+
pt = s(:defn, :x, s(:args, :"**nil"),
|
5150
|
+
s(:nil))
|
5137
5151
|
|
5138
|
-
|
5152
|
+
assert_parse rb, pt
|
5139
5153
|
end
|
5140
5154
|
|
5141
5155
|
def test_call_forward_args_outside_method_definition
|
@@ -5179,8 +5193,8 @@ module TestRubyParserShared30Plus
|
|
5179
5193
|
def test_rhs_asgn
|
5180
5194
|
rb = "42 => n"
|
5181
5195
|
pt = s(:case,
|
5182
|
-
s(:lit, 42)
|
5183
|
-
s(:in, s(:lvar, :n)
|
5196
|
+
s(:lit, 42),
|
5197
|
+
s(:in, s(:lvar, :n), nil), nil)
|
5184
5198
|
|
5185
5199
|
assert_parse rb, pt
|
5186
5200
|
end
|
@@ -5188,14 +5202,14 @@ module TestRubyParserShared30Plus
|
|
5188
5202
|
def test_case_in_find
|
5189
5203
|
rb = "case :a\n in *a, :+, *b\nend"
|
5190
5204
|
pt = s(:case,
|
5191
|
-
s(:lit, :a)
|
5205
|
+
s(:lit, :a),
|
5192
5206
|
s(:in,
|
5193
5207
|
s(:find_pat, nil,
|
5194
5208
|
:"*a",
|
5195
5209
|
s(:array_pat, s(:lit, :+).line(2)).line(2),
|
5196
5210
|
:"*b").line(2),
|
5197
5211
|
nil).line(2),
|
5198
|
-
nil)
|
5212
|
+
nil)
|
5199
5213
|
|
5200
5214
|
assert_parse rb, pt
|
5201
5215
|
end
|
@@ -5203,22 +5217,38 @@ module TestRubyParserShared30Plus
|
|
5203
5217
|
def test_case_in_find_array
|
5204
5218
|
rb = "case :a\nin [*, :b, c, *]\nend"
|
5205
5219
|
pt = s(:case,
|
5206
|
-
s(:lit, :a)
|
5220
|
+
s(:lit, :a),
|
5207
5221
|
s(:in,
|
5208
5222
|
s(:find_pat, nil,
|
5209
5223
|
:*,
|
5210
5224
|
s(:array_pat, s(:lit, :b).line(2), s(:lvar, :c).line(2)).line(2),
|
5211
5225
|
:*).line(2),
|
5212
5226
|
nil).line(2),
|
5213
|
-
nil)
|
5227
|
+
nil)
|
5214
5228
|
|
5215
5229
|
assert_parse rb, pt
|
5216
5230
|
end
|
5217
5231
|
|
5218
5232
|
def test_defn_oneliner
|
5219
5233
|
rb = "def exec(cmd) = system(cmd)"
|
5220
|
-
pt = s(:defn, :exec, s(:args, :cmd)
|
5221
|
-
s(:call, nil, :system, s(:lvar, :cmd)
|
5234
|
+
pt = s(:defn, :exec, s(:args, :cmd),
|
5235
|
+
s(:call, nil, :system, s(:lvar, :cmd)))
|
5236
|
+
|
5237
|
+
assert_parse rb, pt
|
5238
|
+
end
|
5239
|
+
|
5240
|
+
def test_defn_oneliner_noargs_parentheses
|
5241
|
+
rb = "def exec() = system"
|
5242
|
+
pt = s(:defn, :exec, s(:args),
|
5243
|
+
s(:call, nil, :system))
|
5244
|
+
|
5245
|
+
assert_parse rb, pt
|
5246
|
+
end
|
5247
|
+
|
5248
|
+
def test_defn_oneliner_noargs
|
5249
|
+
rb = "def exec = system"
|
5250
|
+
pt = s(:defn, :exec, s(:args),
|
5251
|
+
s(:call, nil, :system))
|
5222
5252
|
|
5223
5253
|
assert_parse rb, pt
|
5224
5254
|
end
|
@@ -5227,24 +5257,23 @@ module TestRubyParserShared30Plus
|
|
5227
5257
|
rb = "def exec(cmd)\n system(cmd)\nrescue\n nil\nend\n"
|
5228
5258
|
pt = s(:defn, :exec, s(:args, :cmd),
|
5229
5259
|
s(:rescue,
|
5230
|
-
s(:call, nil, :system, s(:lvar, :cmd)),
|
5231
|
-
|
5260
|
+
s(:call, nil, :system, s(:lvar, :cmd).line(2)).line(2),
|
5261
|
+
s(:resbody, s(:array).line(3),
|
5262
|
+
s(:nil).line(4)).line(3)).line(2))
|
5263
|
+
|
5232
5264
|
assert_parse rb, pt
|
5233
5265
|
|
5234
5266
|
rb = "def exec(cmd)\n system(cmd) rescue nil\nend\n"
|
5235
|
-
assert_parse rb, pt
|
5267
|
+
assert_parse rb, pt.deep_each { |s| s.line = 2 if s.line && s.line > 1 }
|
5236
5268
|
|
5237
5269
|
rb = "def exec(cmd) = system(cmd) rescue nil"
|
5238
|
-
assert_parse rb, pt
|
5270
|
+
assert_parse rb, pt.deep_each { |s| s.line = 1 }
|
5239
5271
|
end
|
5240
5272
|
|
5241
5273
|
def test_defs_oneliner
|
5242
5274
|
rb = "def self.exec(cmd) = system(cmd)"
|
5243
|
-
pt = s(:defs,
|
5244
|
-
s(:
|
5245
|
-
:exec,
|
5246
|
-
s(:args, :cmd).line(1),
|
5247
|
-
s(:call, nil, :system, s(:lvar, :cmd).line(1)).line(1)).line(1)
|
5275
|
+
pt = s(:defs, s(:self), :exec, s(:args, :cmd),
|
5276
|
+
s(:call, nil, :system, s(:lvar, :cmd)))
|
5248
5277
|
|
5249
5278
|
assert_parse rb, pt
|
5250
5279
|
end
|
@@ -5253,15 +5282,15 @@ module TestRubyParserShared30Plus
|
|
5253
5282
|
rb = "def self.exec(cmd)\n system(cmd)\nrescue\n nil\nend\n"
|
5254
5283
|
pt = s(:defs, s(:self), :exec, s(:args, :cmd),
|
5255
5284
|
s(:rescue,
|
5256
|
-
s(:call, nil, :system, s(:lvar, :cmd)),
|
5257
|
-
s(:resbody, s(:array), s(:nil))))
|
5285
|
+
s(:call, nil, :system, s(:lvar, :cmd).line(2)).line(2),
|
5286
|
+
s(:resbody, s(:array).line(3), s(:nil).line(4)).line(3)).line(2))
|
5258
5287
|
assert_parse rb, pt
|
5259
5288
|
|
5260
5289
|
rb = "def self.exec(cmd)\n system(cmd) rescue nil\nend\n"
|
5261
|
-
assert_parse rb, pt
|
5290
|
+
assert_parse rb, pt.deep_each { |s| s.line = 2 if s.line && s.line > 1 }
|
5262
5291
|
|
5263
5292
|
rb = "def self.exec(cmd) = system(cmd) rescue nil"
|
5264
|
-
assert_parse rb, pt
|
5293
|
+
assert_parse rb, pt.deep_each { |s| s.line = 1 }
|
5265
5294
|
end
|
5266
5295
|
|
5267
5296
|
def test_defn_oneliner_setter
|
@@ -5341,13 +5370,16 @@ class RubyParserTestCase < ParseTreeTestCase
|
|
5341
5370
|
super
|
5342
5371
|
end
|
5343
5372
|
|
5373
|
+
attr_accessor :assert_parse_ran
|
5374
|
+
|
5344
5375
|
def assert_parse rb, pt
|
5376
|
+
self.processor.reset if assert_parse_ran # allows multiple calls
|
5377
|
+
self.assert_parse_ran = true
|
5378
|
+
|
5345
5379
|
timeout = (ENV["RP_TIMEOUT"] || 10).to_i
|
5346
5380
|
|
5347
|
-
|
5348
|
-
|
5349
|
-
pt.line ||= 1
|
5350
|
-
end
|
5381
|
+
pt.deep_each { |s| s.line ||= 1 }
|
5382
|
+
pt.line ||= 1
|
5351
5383
|
|
5352
5384
|
self.result = processor.parse rb, "(string)", timeout
|
5353
5385
|
assert_equal pt, result
|
@@ -5368,16 +5400,6 @@ class RubyParserTestCase < ParseTreeTestCase
|
|
5368
5400
|
end
|
5369
5401
|
end
|
5370
5402
|
|
5371
|
-
def assert_parse_line rb, pt, line
|
5372
|
-
old_env = ENV["VERBOSE"]
|
5373
|
-
ENV["VERBOSE"] = "1"
|
5374
|
-
|
5375
|
-
assert_parse rb, pt
|
5376
|
-
assert_equal line, result.line, "call should have line number"
|
5377
|
-
ensure
|
5378
|
-
ENV["VERBOSE"] = old_env
|
5379
|
-
end
|
5380
|
-
|
5381
5403
|
def assert_syntax_error rb, emsg, klass = RubyParser::SyntaxError
|
5382
5404
|
e = nil
|
5383
5405
|
assert_silent do
|
@@ -5483,11 +5505,10 @@ class TestRubyParserV25 < RubyParserTestCase
|
|
5483
5505
|
rb = "proc do\n :begin\nensure\n :ensure\nend.call"
|
5484
5506
|
pt = s(:call,
|
5485
5507
|
s(:iter,
|
5486
|
-
s(:call, nil, :proc),
|
5487
|
-
0,
|
5508
|
+
s(:call, nil, :proc), 0,
|
5488
5509
|
s(:ensure,
|
5489
|
-
s(:lit, :begin),
|
5490
|
-
s(:lit, :ensure))),
|
5510
|
+
s(:lit, :begin).line(2),
|
5511
|
+
s(:lit, :ensure).line(4)).line(2)),
|
5491
5512
|
:call)
|
5492
5513
|
|
5493
5514
|
assert_parse rb, pt
|
@@ -5496,16 +5517,14 @@ class TestRubyParserV25 < RubyParserTestCase
|
|
5496
5517
|
def test_rescue_do_end_no_raise
|
5497
5518
|
rb = "tap do\n :begin\nrescue\n :rescue\nelse\n :else\nensure\n :ensure\nend"
|
5498
5519
|
pt = s(:iter,
|
5499
|
-
s(:call, nil, :tap),
|
5500
|
-
0,
|
5520
|
+
s(:call, nil, :tap), 0,
|
5501
5521
|
s(:ensure,
|
5502
5522
|
s(:rescue,
|
5503
|
-
s(:lit, :begin),
|
5504
|
-
s(:resbody,
|
5505
|
-
s(:
|
5506
|
-
|
5507
|
-
|
5508
|
-
s(:lit, :ensure)))
|
5523
|
+
s(:lit, :begin).line(2),
|
5524
|
+
s(:resbody, s(:array).line(3),
|
5525
|
+
s(:lit, :rescue).line(4)).line(3),
|
5526
|
+
s(:lit, :else).line(6)).line(2),
|
5527
|
+
s(:lit, :ensure).line(8)).line(2))
|
5509
5528
|
|
5510
5529
|
assert_parse rb, pt
|
5511
5530
|
end
|
@@ -5513,11 +5532,10 @@ class TestRubyParserV25 < RubyParserTestCase
|
|
5513
5532
|
def test_rescue_do_end_raised
|
5514
5533
|
rb = "tap do\n raise\nensure\n :ensure\nend"
|
5515
5534
|
pt = s(:iter,
|
5516
|
-
s(:call, nil, :tap),
|
5517
|
-
0,
|
5535
|
+
s(:call, nil, :tap), 0,
|
5518
5536
|
s(:ensure,
|
5519
|
-
s(:call, nil, :raise),
|
5520
|
-
s(:lit, :ensure)))
|
5537
|
+
s(:call, nil, :raise).line(2),
|
5538
|
+
s(:lit, :ensure).line(4)).line(2))
|
5521
5539
|
|
5522
5540
|
assert_parse rb, pt
|
5523
5541
|
end
|
@@ -5529,12 +5547,12 @@ class TestRubyParserV25 < RubyParserTestCase
|
|
5529
5547
|
0,
|
5530
5548
|
s(:ensure,
|
5531
5549
|
s(:rescue,
|
5532
|
-
s(:call, nil, :raise),
|
5550
|
+
s(:call, nil, :raise).line(2),
|
5533
5551
|
s(:resbody,
|
5534
|
-
s(:array),
|
5535
|
-
s(:lit, :rescue)),
|
5536
|
-
s(:lit, :else)),
|
5537
|
-
s(:lit, :ensure)))
|
5552
|
+
s(:array).line(3),
|
5553
|
+
s(:lit, :rescue).line(4)).line(3),
|
5554
|
+
s(:lit, :else).line(6)).line(2),
|
5555
|
+
s(:lit, :ensure).line(8)).line(2))
|
5538
5556
|
|
5539
5557
|
assert_parse rb, pt
|
5540
5558
|
end
|
@@ -5542,9 +5560,11 @@ class TestRubyParserV25 < RubyParserTestCase
|
|
5542
5560
|
def test_rescue_in_block
|
5543
5561
|
rb = "blah do\nrescue\n stuff\nend"
|
5544
5562
|
pt = s(:iter,
|
5545
|
-
s(:call, nil, :blah),
|
5546
|
-
|
5547
|
-
|
5563
|
+
s(:call, nil, :blah), 0,
|
5564
|
+
s(:rescue,
|
5565
|
+
s(:resbody, s(:array).line(2),
|
5566
|
+
s(:call, nil, :stuff).line(3)).line(2)).line(2))
|
5567
|
+
|
5548
5568
|
assert_parse rb, pt
|
5549
5569
|
end
|
5550
5570
|
end
|
@@ -5561,21 +5581,21 @@ class TestRubyParserV26 < RubyParserTestCase
|
|
5561
5581
|
def test_parse_line_dot2_open
|
5562
5582
|
rb = "0..\n; a..\n; c"
|
5563
5583
|
pt = s(:block,
|
5564
|
-
s(:dot2, s(:lit, 0)
|
5584
|
+
s(:dot2, s(:lit, 0), nil),
|
5565
5585
|
s(:dot2, s(:call, nil, :a).line(2), nil).line(2),
|
5566
|
-
s(:call, nil, :c).line(3))
|
5586
|
+
s(:call, nil, :c).line(3))
|
5567
5587
|
|
5568
|
-
|
5588
|
+
assert_parse rb, pt
|
5569
5589
|
end
|
5570
5590
|
|
5571
5591
|
def test_parse_line_dot3_open
|
5572
5592
|
rb = "0...\n; a...\n; c"
|
5573
5593
|
pt = s(:block,
|
5574
|
-
s(:dot3, s(:lit, 0)
|
5594
|
+
s(:dot3, s(:lit, 0), nil),
|
5575
5595
|
s(:dot3, s(:call, nil, :a).line(2), nil).line(2),
|
5576
|
-
s(:call, nil, :c).line(3))
|
5596
|
+
s(:call, nil, :c).line(3))
|
5577
5597
|
|
5578
|
-
|
5598
|
+
assert_parse rb, pt
|
5579
5599
|
end
|
5580
5600
|
end
|
5581
5601
|
|
@@ -5593,21 +5613,21 @@ class TestRubyParserV27 < RubyParserTestCase
|
|
5593
5613
|
def test_bdot2
|
5594
5614
|
rb = "..10\n; ..a\n; c"
|
5595
5615
|
pt = s(:block,
|
5596
|
-
s(:dot2, nil, s(:lit, 10)
|
5616
|
+
s(:dot2, nil, s(:lit, 10)),
|
5597
5617
|
s(:dot2, nil, s(:call, nil, :a).line(2)).line(2),
|
5598
|
-
s(:call, nil, :c).line(3))
|
5618
|
+
s(:call, nil, :c).line(3))
|
5599
5619
|
|
5600
|
-
|
5620
|
+
assert_parse rb, pt
|
5601
5621
|
end
|
5602
5622
|
|
5603
5623
|
def test_bdot3
|
5604
5624
|
rb = "...10\n; ...a\n; c"
|
5605
5625
|
pt = s(:block,
|
5606
|
-
s(:dot3, nil, s(:lit, 10)
|
5626
|
+
s(:dot3, nil, s(:lit, 10)),
|
5607
5627
|
s(:dot3, nil, s(:call, nil, :a).line(2)).line(2),
|
5608
|
-
s(:call, nil, :c).line(3))
|
5628
|
+
s(:call, nil, :c).line(3))
|
5609
5629
|
|
5610
|
-
|
5630
|
+
assert_parse rb, pt
|
5611
5631
|
end
|
5612
5632
|
end
|
5613
5633
|
|