ruby_parser 3.1.3 → 3.2.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.
- data.tar.gz.sig +0 -0
- data/.autotest +16 -3
- data/History.txt +66 -0
- data/Manifest.txt +2 -0
- data/Rakefile +25 -15
- data/bin/ruby_parse_extract_error +22 -2
- data/lib/ruby18_parser.rb +27 -15
- data/lib/ruby18_parser.y +27 -16
- data/lib/ruby19_parser.rb +2296 -2265
- data/lib/ruby19_parser.y +54 -35
- data/lib/ruby20_parser.rb +6593 -0
- data/lib/ruby20_parser.y +2290 -0
- data/lib/ruby_lexer.rb +161 -93
- data/lib/ruby_parser.rb +1 -1
- data/lib/ruby_parser_extras.rb +95 -27
- data/test/test_ruby_lexer.rb +476 -29
- data/test/test_ruby_parser.rb +1141 -147
- data/test/test_ruby_parser_extras.rb +2 -3
- metadata +30 -14
- metadata.gz.sig +1 -1
data/test/test_ruby_parser.rb
CHANGED
@@ -4,7 +4,6 @@
|
|
4
4
|
# ENV['VERBOSE'] = "1"
|
5
5
|
|
6
6
|
require 'rubygems'
|
7
|
-
gem "minitest"
|
8
7
|
require 'minitest/autorun'
|
9
8
|
require 'ruby_parser'
|
10
9
|
|
@@ -676,6 +675,22 @@ module TestRubyParserShared
|
|
676
675
|
assert_parse rb, pt
|
677
676
|
end
|
678
677
|
|
678
|
+
def test_parse_line_heredoc_regexp_chars
|
679
|
+
rb = <<-CODE
|
680
|
+
string = <<-"^D"
|
681
|
+
very long string
|
682
|
+
^D
|
683
|
+
puts string
|
684
|
+
CODE
|
685
|
+
|
686
|
+
pt = s(:block,
|
687
|
+
s(:lasgn, :string,
|
688
|
+
s(:str, " very long string\n").line(1)).line(1),
|
689
|
+
s(:call, nil, :puts, s(:lvar, :string).line(4)).line(4)).line(1)
|
690
|
+
|
691
|
+
assert_parse rb, pt
|
692
|
+
end
|
693
|
+
|
679
694
|
def test_parse_line_newlines
|
680
695
|
rb = "true\n\n"
|
681
696
|
pt = s(:true)
|
@@ -758,10 +773,14 @@ module TestRubyParserShared
|
|
758
773
|
Ruby19Parser === self.processor
|
759
774
|
end
|
760
775
|
|
776
|
+
def ruby20
|
777
|
+
Ruby20Parser === self.processor
|
778
|
+
end
|
779
|
+
|
761
780
|
def test_bug_comma
|
762
781
|
val = if ruby18 then
|
763
782
|
s(:lit, 100)
|
764
|
-
elsif ruby19 then
|
783
|
+
elsif ruby19 or ruby20 then
|
765
784
|
s(:str, "d")
|
766
785
|
else
|
767
786
|
raise "wtf"
|
@@ -785,201 +804,1005 @@ module TestRubyParserShared
|
|
785
804
|
assert_parse rb, pt
|
786
805
|
end
|
787
806
|
|
788
|
-
def test_bug_masgn_right
|
789
|
-
rb = "f { |a, (b, c)| }"
|
790
|
-
pt = s(:iter,
|
791
|
-
s(:call, nil, :f),
|
792
|
-
s(:args, :a, s(:masgn, :b, :c)))
|
807
|
+
def test_bug_masgn_right
|
808
|
+
rb = "f { |a, (b, c)| }"
|
809
|
+
pt = s(:iter,
|
810
|
+
s(:call, nil, :f),
|
811
|
+
s(:args, :a, s(:masgn, :b, :c)))
|
812
|
+
|
813
|
+
assert_parse rb, pt
|
814
|
+
end
|
815
|
+
|
816
|
+
def test_when_splat
|
817
|
+
rb = "case a; when *b then; end"
|
818
|
+
pt = s(:case, s(:call, nil, :a),
|
819
|
+
s(:when, s(:array, s(:splat, s(:call, nil, :b))), nil),
|
820
|
+
nil)
|
821
|
+
|
822
|
+
assert_parse rb, pt
|
823
|
+
end
|
824
|
+
|
825
|
+
def test_if_symbol
|
826
|
+
rb = "if f :x; end"
|
827
|
+
pt = s(:if, s(:call, nil, :f, s(:lit, :x)), nil, nil)
|
828
|
+
|
829
|
+
assert_parse rb, pt
|
830
|
+
end
|
831
|
+
|
832
|
+
|
833
|
+
def test_bug_not_parens
|
834
|
+
rb = "not(a)"
|
835
|
+
pt = if ruby18 then
|
836
|
+
s(:not, s(:call, nil, :a))
|
837
|
+
elsif ruby19 or ruby20 then
|
838
|
+
s(:call, s(:call, nil, :a), :"!")
|
839
|
+
else
|
840
|
+
raise "wtf"
|
841
|
+
end
|
842
|
+
|
843
|
+
assert_parse rb, pt
|
844
|
+
end
|
845
|
+
|
846
|
+
def test_pipe_space
|
847
|
+
rb = "a.b do | | end"
|
848
|
+
pt = s(:iter, s(:call, s(:call, nil, :a), :b), 0)
|
849
|
+
|
850
|
+
assert_parse rb, pt
|
851
|
+
end
|
852
|
+
|
853
|
+
def test_cond_unary_minus
|
854
|
+
rb = "if -1; end"
|
855
|
+
pt = s(:if, s(:lit, -1), nil, nil)
|
856
|
+
|
857
|
+
assert_parse rb, pt
|
858
|
+
end
|
859
|
+
|
860
|
+
def test_bug_op_asgn_rescue
|
861
|
+
rb = "a ||= b rescue nil"
|
862
|
+
pt = s(:rescue,
|
863
|
+
s(:op_asgn_or, s(:lvar, :a), s(:lasgn, :a, s(:call, nil, :b))),
|
864
|
+
s(:resbody, s(:array), s(:nil)))
|
865
|
+
|
866
|
+
assert_parse rb, pt
|
867
|
+
end
|
868
|
+
|
869
|
+
def test_magic_encoding_comment
|
870
|
+
rb = "# encoding: utf-8\nclass ExampleUTF8ClassNameVarietà; def self.è; così = :però; end\nend\n"
|
871
|
+
|
872
|
+
rb.force_encoding "ASCII-8BIT" if rb.respond_to? :force_encoding
|
873
|
+
|
874
|
+
# TODO: class vars
|
875
|
+
# TODO: odd-ternary: a ?bb : c
|
876
|
+
# TODO: globals
|
877
|
+
|
878
|
+
pt = s(:class, :"ExampleUTF8ClassNameVariet\303\240", nil,
|
879
|
+
s(:defs, s(:self), :"\303\250", s(:args),
|
880
|
+
s(:lasgn, :"cos\303\254", s(:lit, :"per\303\262"))))
|
881
|
+
|
882
|
+
err = RUBY_VERSION =~ /^1\.8/ ? "Skipping magic encoding comment\n" : ""
|
883
|
+
|
884
|
+
assert_output "", err do
|
885
|
+
assert_parse rb, pt
|
886
|
+
end
|
887
|
+
end
|
888
|
+
|
889
|
+
def test_iter_args_1
|
890
|
+
rb = "f { |a,b| }"
|
891
|
+
pt = s(:iter, s(:call, nil, :f), s(:args, :a, :b))
|
892
|
+
|
893
|
+
assert_parse rb, pt
|
894
|
+
end
|
895
|
+
|
896
|
+
def test_iter_args_3
|
897
|
+
rb = "f { |a, (b, c), d| }"
|
898
|
+
pt = s(:iter, s(:call, nil, :f), s(:args, :a, s(:masgn, :b, :c), :d))
|
899
|
+
|
900
|
+
assert_parse rb, pt
|
901
|
+
end
|
902
|
+
|
903
|
+
def test_str_heredoc_interp
|
904
|
+
rb = "<<\"\"\n\#{x}\nblah2\n\n"
|
905
|
+
pt = s(:dstr, "", s(:evstr, s(:call, nil, :x)), s(:str, "\nblah2\n"))
|
906
|
+
|
907
|
+
assert_parse rb, pt
|
908
|
+
end
|
909
|
+
|
910
|
+
def test_i_fucking_hate_line_numbers
|
911
|
+
rb = <<-END.gsub(/^ {6}/, '')
|
912
|
+
if true
|
913
|
+
p 1
|
914
|
+
a.b 2
|
915
|
+
c.d 3, 4
|
916
|
+
e.f 5
|
917
|
+
g.h 6, 7
|
918
|
+
p(1)
|
919
|
+
a.b(2)
|
920
|
+
c.d(3, 4)
|
921
|
+
e.f(5)
|
922
|
+
g.h(6, 7)
|
923
|
+
end
|
924
|
+
END
|
925
|
+
|
926
|
+
pt = s(:if, s(:true).line(1),
|
927
|
+
s(:block,
|
928
|
+
s(:call, nil, :p, s(:lit, 1).line(2)).line(2),
|
929
|
+
s(:call, s(:call, nil, :a).line(3), :b,
|
930
|
+
s(:lit, 2).line(3)).line(3),
|
931
|
+
s(:call, s(:call, nil, :c).line(4), :d,
|
932
|
+
s(:lit, 3).line(4), s(:lit, 4).line(4)).line(4),
|
933
|
+
s(:call, s(:call, nil, :e).line(5), :f,
|
934
|
+
s(:lit, 5).line(5)).line(5),
|
935
|
+
s(:call, s(:call, nil, :g).line(6), :h,
|
936
|
+
s(:lit, 6).line(6), s(:lit, 7).line(6)).line(6),
|
937
|
+
s(:call, nil, :p, s(:lit, 1).line(7)).line(7),
|
938
|
+
s(:call, s(:call, nil, :a).line(8), :b,
|
939
|
+
s(:lit, 2).line(8)).line(8),
|
940
|
+
s(:call, s(:call, nil, :c).line(9), :d,
|
941
|
+
s(:lit, 3).line(9), s(:lit, 4).line(9)).line(9),
|
942
|
+
s(:call, s(:call, nil, :e).line(10), :f,
|
943
|
+
s(:lit, 5).line(10)).line(10),
|
944
|
+
s(:call, s(:call, nil, :g).line(11), :h,
|
945
|
+
s(:lit, 6).line(11), s(:lit, 7).line(11)).line(11)).line(2),
|
946
|
+
nil).line(1)
|
947
|
+
|
948
|
+
assert_parse rb, pt
|
949
|
+
end
|
950
|
+
|
951
|
+
def test_i_fucking_hate_line_numbers2
|
952
|
+
rb = <<-EOM.gsub(/^ {6}/, '')
|
953
|
+
if true then
|
954
|
+
p('a')
|
955
|
+
b = 1
|
956
|
+
p b
|
957
|
+
c =1
|
958
|
+
end
|
959
|
+
a
|
960
|
+
EOM
|
961
|
+
|
962
|
+
pt = s(:block,
|
963
|
+
s(:if, s(:true).line(1),
|
964
|
+
s(:block,
|
965
|
+
s(:call, nil, :p, s(:str, "a").line(2)).line(2),
|
966
|
+
s(:lasgn, :b, s(:lit, 1).line(3)).line(3),
|
967
|
+
s(:call, nil, :p, s(:lvar, :b).line(4)).line(4),
|
968
|
+
s(:lasgn, :c, s(:lit, 1).line(5)).line(5)).line(2), # TODO line 2?
|
969
|
+
nil).line(1),
|
970
|
+
s(:call, nil, :a).line(7)).line(1)
|
971
|
+
|
972
|
+
assert_parse rb, pt
|
973
|
+
end
|
974
|
+
|
975
|
+
def test_parse_comments
|
976
|
+
p = RubyParser.new
|
977
|
+
sexp = p.parse <<-CODE
|
978
|
+
# class comment
|
979
|
+
class Inline
|
980
|
+
def show
|
981
|
+
# woot
|
982
|
+
end
|
983
|
+
|
984
|
+
# Returns a list of things
|
985
|
+
def list
|
986
|
+
# woot
|
987
|
+
end
|
988
|
+
end
|
989
|
+
CODE
|
990
|
+
|
991
|
+
assert_equal "# class comment\n", sexp.comments
|
992
|
+
act = sexp.find_nodes(:defn).map(&:comments)
|
993
|
+
exp = ["", "# Returns a list of things\n"]
|
994
|
+
|
995
|
+
assert_equal exp, act
|
996
|
+
assert_equal [], processor.comments
|
997
|
+
assert_equal "", processor.lexer.comments
|
998
|
+
end
|
999
|
+
|
1000
|
+
def test_call_pipe
|
1001
|
+
rb = "1 | 2"
|
1002
|
+
pt = s(:call, s(:lit, 1), :|, s(:lit, 2))
|
1003
|
+
|
1004
|
+
assert_parse rb, pt
|
1005
|
+
end
|
1006
|
+
|
1007
|
+
def test_lasgn_command
|
1008
|
+
rb = "a = b.c 1"
|
1009
|
+
pt = s(:lasgn, :a, s(:call, s(:call, nil, :b), :c, s(:lit, 1)))
|
1010
|
+
|
1011
|
+
assert_parse rb, pt
|
1012
|
+
end
|
1013
|
+
|
1014
|
+
def test_call_args_command
|
1015
|
+
rb = "a.b c.d 1"
|
1016
|
+
pt = s(:call, s(:call, nil, :a), :b,
|
1017
|
+
s(:call, s(:call, nil, :c), :d,
|
1018
|
+
s(:lit, 1)))
|
1019
|
+
|
1020
|
+
assert_parse rb, pt
|
1021
|
+
end
|
1022
|
+
|
1023
|
+
def test_defined_eh_parens
|
1024
|
+
rb = "defined?(42)"
|
1025
|
+
pt = s(:defined, s(:lit, 42))
|
1026
|
+
|
1027
|
+
assert_parse rb, pt
|
1028
|
+
end
|
1029
|
+
|
1030
|
+
def test_if_elsif
|
1031
|
+
rb = "if 1; elsif 2; end"
|
1032
|
+
pt = s(:if, s(:lit, 1), nil, s(:if, s(:lit, 2), nil, nil))
|
1033
|
+
|
1034
|
+
assert_parse rb, pt
|
1035
|
+
end
|
1036
|
+
|
1037
|
+
def test_call_gt
|
1038
|
+
rb = "1 > 2"
|
1039
|
+
pt = s(:call, s(:lit, 1), :>, s(:lit, 2))
|
1040
|
+
|
1041
|
+
assert_parse rb, pt
|
1042
|
+
end
|
1043
|
+
|
1044
|
+
def test_call_lt
|
1045
|
+
rb = "1 < 2"
|
1046
|
+
pt = s(:call, s(:lit, 1), :<, s(:lit, 2))
|
1047
|
+
|
1048
|
+
assert_parse rb, pt
|
1049
|
+
end
|
1050
|
+
|
1051
|
+
def test_call_lte
|
1052
|
+
rb = "1 <= 2"
|
1053
|
+
pt = s(:call, s(:lit, 1), :<=, s(:lit, 2))
|
1054
|
+
|
1055
|
+
assert_parse rb, pt
|
1056
|
+
end
|
1057
|
+
|
1058
|
+
def test_call_spaceship
|
1059
|
+
rb = "1 <=> 2"
|
1060
|
+
pt = s(:call, s(:lit, 1), :<=>, s(:lit, 2))
|
1061
|
+
|
1062
|
+
assert_parse rb, pt
|
1063
|
+
end
|
1064
|
+
|
1065
|
+
def test_call_and
|
1066
|
+
rb = "1 & 2"
|
1067
|
+
pt = s(:call, s(:lit, 1), :&, s(:lit, 2))
|
1068
|
+
|
1069
|
+
assert_parse rb, pt
|
1070
|
+
end
|
1071
|
+
|
1072
|
+
def test_call_star2
|
1073
|
+
rb = "1 ** 2"
|
1074
|
+
pt = s(:call, s(:lit, 1), :"**", s(:lit, 2))
|
1075
|
+
|
1076
|
+
assert_parse rb, pt
|
1077
|
+
end
|
1078
|
+
|
1079
|
+
def test_call_colon2
|
1080
|
+
rb = "A::b"
|
1081
|
+
pt = s(:call, s(:const, :A), :b)
|
1082
|
+
|
1083
|
+
assert_parse rb, pt
|
1084
|
+
end
|
1085
|
+
|
1086
|
+
def test_call_star
|
1087
|
+
rb = "1 * 2"
|
1088
|
+
pt = s(:call, s(:lit, 1), :"*", s(:lit, 2))
|
1089
|
+
|
1090
|
+
assert_parse rb, pt
|
1091
|
+
end
|
1092
|
+
|
1093
|
+
def test_yield_arg
|
1094
|
+
rb = "yield 42"
|
1095
|
+
pt = s(:yield, s(:lit, 42))
|
1096
|
+
|
1097
|
+
assert_parse rb, pt
|
1098
|
+
end
|
1099
|
+
|
1100
|
+
def test_call_div
|
1101
|
+
rb = "1 / 2"
|
1102
|
+
pt = s(:call, s(:lit, 1), :/, s(:lit, 2))
|
1103
|
+
|
1104
|
+
assert_parse rb, pt
|
1105
|
+
end
|
1106
|
+
|
1107
|
+
def test_call_eq3
|
1108
|
+
rb = "1 === 2"
|
1109
|
+
pt = s(:call, s(:lit, 1), :===, s(:lit, 2))
|
1110
|
+
|
1111
|
+
assert_parse rb, pt
|
1112
|
+
end
|
1113
|
+
|
1114
|
+
def test_call_carat
|
1115
|
+
rb = "1 ^ 2"
|
1116
|
+
pt = s(:call, s(:lit, 1), :^, s(:lit, 2))
|
1117
|
+
|
1118
|
+
assert_parse rb, pt
|
1119
|
+
end
|
1120
|
+
|
1121
|
+
def test_call_rshift
|
1122
|
+
rb = "1 >> 2"
|
1123
|
+
pt = s(:call, s(:lit, 1), :>>, s(:lit, 2))
|
1124
|
+
|
1125
|
+
assert_parse rb, pt
|
1126
|
+
end
|
1127
|
+
|
1128
|
+
def test_lasgn_arg_rescue_arg
|
1129
|
+
rb = "a = 1 rescue 2"
|
1130
|
+
pt = s(:lasgn, :a, s(:rescue, s(:lit, 1), s(:resbody, s(:array), s(:lit, 2))))
|
1131
|
+
|
1132
|
+
assert_parse rb, pt
|
1133
|
+
end
|
1134
|
+
|
1135
|
+
def test_call_bang_squiggle
|
1136
|
+
rb = "1 !~ 2"
|
1137
|
+
pt = s(:not, s(:call, s(:lit, 1), :=~, s(:lit, 2))) # TODO: check for 1.9+
|
1138
|
+
|
1139
|
+
assert_parse rb, pt
|
1140
|
+
end
|
1141
|
+
|
1142
|
+
def test_super_arg
|
1143
|
+
rb = "super 42"
|
1144
|
+
pt = s(:super, s(:lit, 42))
|
1145
|
+
|
1146
|
+
assert_parse rb, pt
|
1147
|
+
end
|
1148
|
+
|
1149
|
+
def test_defns_reserved
|
1150
|
+
rb = "def self.return; end"
|
1151
|
+
pt = s(:defs, s(:self), :return, s(:args))
|
1152
|
+
|
1153
|
+
assert_parse rb, pt
|
1154
|
+
end
|
1155
|
+
|
1156
|
+
def test_unary_minus
|
1157
|
+
rb = "-a"
|
1158
|
+
pt = s(:call, s(:call, nil, :a), :"-@")
|
1159
|
+
|
1160
|
+
assert_parse rb, pt
|
1161
|
+
end
|
1162
|
+
|
1163
|
+
def test_masgn_command_call
|
1164
|
+
rb = "a, = b.c 1"
|
1165
|
+
pt = s(:masgn,
|
1166
|
+
s(:array, s(:lasgn, :a)),
|
1167
|
+
s(:to_ary, s(:call, s(:call, nil, :b), :c, s(:lit, 1))))
|
1168
|
+
|
1169
|
+
assert_parse rb, pt
|
1170
|
+
end
|
1171
|
+
|
1172
|
+
def test_uminus_float
|
1173
|
+
rb = "-0.0"
|
1174
|
+
pt = s(:lit, -0.0)
|
1175
|
+
|
1176
|
+
assert_parse rb, pt
|
1177
|
+
end
|
1178
|
+
|
1179
|
+
def test_op_asgn_command_call
|
1180
|
+
rb = "a ||= b.c 2"
|
1181
|
+
pt = s(:op_asgn_or,
|
1182
|
+
s(:lvar, :a),
|
1183
|
+
s(:lasgn, :a, s(:call, s(:call, nil, :b), :c, s(:lit, 2))))
|
1184
|
+
|
1185
|
+
assert_parse rb, pt
|
1186
|
+
end
|
1187
|
+
|
1188
|
+
def test_masgn_paren
|
1189
|
+
rb = "(a, b) = c.d"
|
1190
|
+
pt = s(:masgn,
|
1191
|
+
s(:array, s(:lasgn, :a), s(:lasgn, :b)),
|
1192
|
+
s(:to_ary, s(:call, s(:call, nil, :c), :d)))
|
1193
|
+
|
1194
|
+
assert_parse rb, pt
|
1195
|
+
end
|
1196
|
+
|
1197
|
+
def test_unary_tilde
|
1198
|
+
rb = "~a"
|
1199
|
+
pt = s(:call, s(:call, nil, :a), :~)
|
1200
|
+
|
1201
|
+
assert_parse rb, pt
|
1202
|
+
end
|
1203
|
+
|
1204
|
+
def test_unary_plus
|
1205
|
+
rb = "+a"
|
1206
|
+
pt = s(:call, s(:call, nil, :a), :+@)
|
1207
|
+
|
1208
|
+
assert_parse rb, pt
|
1209
|
+
end
|
1210
|
+
|
1211
|
+
def test_qwords_empty
|
1212
|
+
rb = "%w()"
|
1213
|
+
pt = s(:array)
|
1214
|
+
|
1215
|
+
assert_parse rb, pt
|
1216
|
+
end
|
1217
|
+
|
1218
|
+
def test_qWords_space
|
1219
|
+
rb = "%W( )"
|
1220
|
+
pt = s(:array)
|
1221
|
+
|
1222
|
+
assert_parse rb, pt
|
1223
|
+
end
|
1224
|
+
|
1225
|
+
def test_attr_asgn_colon_id
|
1226
|
+
rb = "A::b = 1"
|
1227
|
+
pt = s(:attrasgn, s(:const, :A), :b=, s(:lit, 1))
|
1228
|
+
|
1229
|
+
assert_parse rb, pt
|
1230
|
+
end
|
1231
|
+
|
1232
|
+
def test_aref_args_assocs
|
1233
|
+
rb = "[1 => 2]"
|
1234
|
+
pt = s(:array, s(:hash, s(:lit, 1), s(:lit, 2)))
|
1235
|
+
|
1236
|
+
assert_parse rb, pt
|
1237
|
+
end
|
1238
|
+
|
1239
|
+
def test_BEGIN
|
1240
|
+
rb = "BEGIN { 42 }"
|
1241
|
+
pt = s(:iter, s(:preexe), s(:args), s(:lit, 42))
|
1242
|
+
|
1243
|
+
assert_parse rb, pt
|
1244
|
+
end
|
1245
|
+
|
1246
|
+
def test_attrasgn_primary_dot_constant
|
1247
|
+
rb = "a.B = 1"
|
1248
|
+
pt = s(:attrasgn, s(:call, nil, :a), :"B=", s(:lit, 1))
|
1249
|
+
|
1250
|
+
assert_parse rb, pt
|
1251
|
+
end
|
1252
|
+
|
1253
|
+
def test_op_asgn_primary_colon_identifier
|
1254
|
+
rb = "A::b += 1"
|
1255
|
+
pt = s(:op_asgn, s(:const, :A), s(:lit, 1), :b, :+) # TODO: check? looks wack
|
1256
|
+
|
1257
|
+
assert_parse rb, pt
|
1258
|
+
end
|
1259
|
+
|
1260
|
+
def test_words_interp
|
1261
|
+
rb = '%W(#{1}b)'
|
1262
|
+
pt = s(:array, s(:dstr, "", s(:evstr, s(:lit, 1)), s(:str, "b")))
|
1263
|
+
|
1264
|
+
assert_parse rb, pt
|
1265
|
+
end
|
1266
|
+
|
1267
|
+
def test_op_asgn_index_command_call
|
1268
|
+
rb = "a[:b] ||= c 1, 2"
|
1269
|
+
pt = s(:op_asgn1, s(:call, nil, :a), s(:array, s(:lit, :b)),
|
1270
|
+
:"||",
|
1271
|
+
s(:call, nil, :c, s(:lit, 1), s(:lit, 2)))
|
1272
|
+
|
1273
|
+
assert_parse rb, pt
|
1274
|
+
end
|
1275
|
+
|
1276
|
+
def test_op_asgn_val_dot_ident_command_call
|
1277
|
+
rb = "a.b ||= c 1"
|
1278
|
+
pt = s(:op_asgn, s(:call, nil, :a), s(:call, nil, :c, s(:lit, 1)), :b, :"||")
|
1279
|
+
|
1280
|
+
assert_parse rb, pt
|
1281
|
+
end
|
1282
|
+
|
1283
|
+
def test_yield_empty_parens
|
1284
|
+
rb = "yield()"
|
1285
|
+
pt = s(:yield)
|
1286
|
+
|
1287
|
+
assert_parse rb, pt
|
1288
|
+
end
|
1289
|
+
|
1290
|
+
def test_masgn_lhs_splat
|
1291
|
+
rb = "*a = 1, 2, 3"
|
1292
|
+
pt = s(:masgn,
|
1293
|
+
s(:array, s(:splat, s(:lasgn, :a))),
|
1294
|
+
s(:array, s(:lit, 1), s(:lit, 2), s(:lit, 3)))
|
1295
|
+
|
1296
|
+
assert_parse rb, pt
|
1297
|
+
end
|
1298
|
+
|
1299
|
+
def test_block_decomp_arg_splat
|
1300
|
+
skip "not that smart yet" if ruby18 # HACK
|
1301
|
+
|
1302
|
+
rb = "a { |(b, *)| }"
|
1303
|
+
pt = s(:iter, s(:call, nil, :a), s(:args, s(:masgn, :b, :*)))
|
1304
|
+
|
1305
|
+
assert_parse rb, pt
|
1306
|
+
end
|
1307
|
+
|
1308
|
+
def test_masgn_arg_ident
|
1309
|
+
rb = "a, b.C = d"
|
1310
|
+
pt = s(:masgn,
|
1311
|
+
s(:array, s(:lasgn, :a), s(:attrasgn, s(:call, nil, :b), :"C=")),
|
1312
|
+
s(:to_ary, s(:call, nil, :d)))
|
1313
|
+
|
1314
|
+
assert_parse rb, pt
|
1315
|
+
end
|
1316
|
+
|
1317
|
+
def test_masgn_arg_colon_arg
|
1318
|
+
rb = "a, b::c = d"
|
1319
|
+
pt = s(:masgn,
|
1320
|
+
s(:array, s(:lasgn, :a), s(:attrasgn, s(:call, nil, :b), :c=)),
|
1321
|
+
s(:to_ary, s(:call, nil, :d)))
|
1322
|
+
|
1323
|
+
assert_parse rb, pt
|
1324
|
+
end
|
1325
|
+
|
1326
|
+
def test_masgn_star
|
1327
|
+
rb = "* = 1"
|
1328
|
+
pt = s(:masgn,
|
1329
|
+
s(:array, s(:splat)),
|
1330
|
+
s(:to_ary, s(:lit, 1)))
|
1331
|
+
|
1332
|
+
assert_parse rb, pt
|
1333
|
+
end
|
1334
|
+
|
1335
|
+
def test_op_asgn_dot_ident_command_call
|
1336
|
+
rb = "A.B ||= c 1"
|
1337
|
+
pt = s(:op_asgn, s(:const, :A), s(:call, nil, :c, s(:lit, 1)), :B, :"||")
|
1338
|
+
|
1339
|
+
assert_parse rb, pt
|
1340
|
+
end
|
1341
|
+
|
1342
|
+
def test_block_decomp_splat
|
1343
|
+
skip "not that smart yet" if ruby18 # HACK
|
1344
|
+
|
1345
|
+
rb = "f { |(*a)| }"
|
1346
|
+
pt = s(:iter, s(:call, nil, :f), s(:args, s(:masgn, :"*a")))
|
1347
|
+
|
1348
|
+
assert_parse rb, pt
|
1349
|
+
end
|
1350
|
+
|
1351
|
+
def test_masgn_colon3
|
1352
|
+
rb = "::A, ::B = 1, 2"
|
1353
|
+
pt = s(:masgn,
|
1354
|
+
s(:array, s(:const, nil, s(:colon3, :A)), s(:const, s(:colon3, :B))),
|
1355
|
+
s(:array, s(:lit, 1), s(:lit, 2)))
|
1356
|
+
|
1357
|
+
assert_parse rb, pt
|
1358
|
+
end
|
1359
|
+
|
1360
|
+
def test_masgn_colon2
|
1361
|
+
rb = "a, b::C = 1, 2"
|
1362
|
+
pt = s(:masgn,
|
1363
|
+
s(:array, s(:lasgn, :a), s(:const, s(:colon2, s(:call, nil, :b), :C))),
|
1364
|
+
s(:array, s(:lit, 1), s(:lit, 2)))
|
1365
|
+
|
1366
|
+
assert_parse rb, pt
|
1367
|
+
end
|
1368
|
+
|
1369
|
+
def test_alias_gvar_backref
|
1370
|
+
rb = "alias $MATCH $&"
|
1371
|
+
pt = s(:valias, :$MATCH, :$&)
|
1372
|
+
|
1373
|
+
assert_parse rb, pt
|
1374
|
+
end
|
1375
|
+
|
1376
|
+
def test_heredoc_broken_windows_theory_applies_to_microsoft_more_than_anything
|
1377
|
+
rb = "<<EOS\r\r\nEOS\r\r\n"
|
1378
|
+
pt = s(:str, "")
|
1379
|
+
|
1380
|
+
assert_parse rb, pt
|
1381
|
+
end
|
1382
|
+
|
1383
|
+
def test_heredoc_unicode
|
1384
|
+
rb = "<<OOTPÜT\n.\nOOTPÜT\n"
|
1385
|
+
pt = s(:str, ".\n")
|
1386
|
+
|
1387
|
+
assert_parse rb, pt
|
1388
|
+
end
|
1389
|
+
|
1390
|
+
def test_masgn_double_paren
|
1391
|
+
rb = "((a,b))=c" # TODO: blog
|
1392
|
+
pt = s(:masgn,
|
1393
|
+
s(:array, s(:masgn, s(:array, s(:lasgn, :a), s(:lasgn, :b)))),
|
1394
|
+
s(:to_ary, s(:call, nil, :c)))
|
1395
|
+
|
1396
|
+
assert_parse rb, pt
|
1397
|
+
end
|
1398
|
+
|
1399
|
+
def test_index_0_opasgn
|
1400
|
+
rb = "a[] += b"
|
1401
|
+
pt = s(:op_asgn1, s(:call, nil, :a), nil, :+, s(:call, nil, :b))
|
1402
|
+
|
1403
|
+
assert_parse rb, pt
|
1404
|
+
end
|
1405
|
+
|
1406
|
+
def test___ENCODING__
|
1407
|
+
# skip "lexer bug" if ruby18
|
1408
|
+
rb = "__ENCODING__"
|
1409
|
+
pt = if Ruby18Parser === processor then
|
1410
|
+
s(:call, nil, :__ENCODING__)
|
1411
|
+
else
|
1412
|
+
if defined? Encoding then
|
1413
|
+
if Ruby18Parser === processor then
|
1414
|
+
s(:call, nil, :__ENCODING__)
|
1415
|
+
else
|
1416
|
+
s(:colon2, s(:const, :Encoding), :UTF_8)
|
1417
|
+
end
|
1418
|
+
else
|
1419
|
+
s(:str, "Unsupported!")
|
1420
|
+
end
|
1421
|
+
end
|
1422
|
+
|
1423
|
+
assert_parse rb, pt
|
1424
|
+
end
|
1425
|
+
|
1426
|
+
def test_dstr_evstr_empty_end
|
1427
|
+
rb = ':"#{field}"'
|
1428
|
+
pt = s(:dsym, "", s(:evstr, s(:call, nil, :field)))
|
1429
|
+
|
1430
|
+
assert_parse rb, pt
|
1431
|
+
end
|
1432
|
+
end
|
1433
|
+
|
1434
|
+
module TestRubyParserShared1920
|
1435
|
+
def test_block_call_operation_dot
|
1436
|
+
rb = "a.b c do end.d"
|
1437
|
+
pt = s(:call,
|
1438
|
+
s(:iter,
|
1439
|
+
s(:call, s(:call, nil, :a), :b, s(:call, nil, :c)), s(:args)),
|
1440
|
+
:d)
|
1441
|
+
|
1442
|
+
assert_parse rb, pt
|
1443
|
+
end
|
1444
|
+
|
1445
|
+
def test_block_call_operation_colon
|
1446
|
+
rb = "a.b c do end::d"
|
1447
|
+
pt = s(:call,
|
1448
|
+
s(:iter,
|
1449
|
+
s(:call, s(:call, nil, :a), :b, s(:call, nil, :c)), s(:args)),
|
1450
|
+
:d)
|
1451
|
+
|
1452
|
+
assert_parse rb, pt
|
1453
|
+
end
|
1454
|
+
|
1455
|
+
def test_block_command_operation_dot
|
1456
|
+
rb = "a :b do end.c :d"
|
1457
|
+
pt = s(:call,
|
1458
|
+
s(:iter, s(:call, nil, :a, s(:lit, :b)), s(:args)),
|
1459
|
+
:c,
|
1460
|
+
s(:lit, :d))
|
1461
|
+
|
1462
|
+
assert_parse rb, pt
|
1463
|
+
end
|
1464
|
+
|
1465
|
+
def test_block_command_operation_colon
|
1466
|
+
rb = "a :b do end::c :d"
|
1467
|
+
pt = s(:call,
|
1468
|
+
s(:iter, s(:call, nil, :a, s(:lit, :b)), s(:args)),
|
1469
|
+
:c,
|
1470
|
+
s(:lit, :d))
|
1471
|
+
|
1472
|
+
assert_parse rb, pt
|
1473
|
+
end
|
1474
|
+
|
1475
|
+
def test_block_optarg
|
1476
|
+
rb = "a { |b = :c| }"
|
1477
|
+
pt = s(:iter, s(:call, nil, :a), s(:args, s(:lasgn, :b, s(:lit, :c))))
|
1478
|
+
|
1479
|
+
assert_parse rb, pt
|
1480
|
+
end
|
1481
|
+
|
1482
|
+
def test_block_reg_optarg
|
1483
|
+
rb = "a { |b, c = :d| }"
|
1484
|
+
pt = s(:iter, s(:call, nil, :a), s(:args, :b, s(:lasgn, :c, s(:lit, :d))))
|
1485
|
+
|
1486
|
+
assert_parse rb, pt
|
1487
|
+
end
|
1488
|
+
|
1489
|
+
def test_block_splat_reg
|
1490
|
+
rb = "a { |*b, c| }"
|
1491
|
+
pt = s(:iter, s(:call, nil, :a), s(:args, :"*b", :c))
|
1492
|
+
|
1493
|
+
assert_parse rb, pt
|
1494
|
+
end
|
1495
|
+
|
1496
|
+
def test_defn_opt_reg
|
1497
|
+
rb = "def f(a=nil, b) end"
|
1498
|
+
pt = s(:defn, :f, s(:args, s(:lasgn, :a, s(:nil)), :b), s(:nil))
|
1499
|
+
|
1500
|
+
assert_parse rb, pt
|
1501
|
+
end
|
1502
|
+
|
1503
|
+
def test_defn_reg_opt_reg
|
1504
|
+
rb = "def f(a, b = :c, d) end"
|
1505
|
+
pt = s(:defn, :f, s(:args, :a, s(:lasgn, :b, s(:lit, :c)), :d), s(:nil))
|
1506
|
+
|
1507
|
+
assert_parse rb, pt
|
1508
|
+
end
|
1509
|
+
|
1510
|
+
def test_defn_splat_arg
|
1511
|
+
rb = "def f(*, a) end"
|
1512
|
+
pt = s(:defn, :f, s(:args, :*, :a), s(:nil))
|
1513
|
+
|
1514
|
+
assert_parse rb, pt
|
1515
|
+
end
|
1516
|
+
|
1517
|
+
def test_defn_arg_asplat_arg
|
1518
|
+
rb = "def call(interp, *, args) end"
|
1519
|
+
pt = s(:defn, :call, s(:args, :interp, :*, :args), s(:nil))
|
1520
|
+
|
1521
|
+
assert_parse rb, pt
|
1522
|
+
end
|
1523
|
+
|
1524
|
+
def test_block_arg_scope
|
1525
|
+
rb = "a { |b; c| }"
|
1526
|
+
pt = s(:iter, s(:call, nil, :a), s(:args, :b, s(:shadow, :c)))
|
1527
|
+
|
1528
|
+
assert_parse rb, pt
|
1529
|
+
end
|
1530
|
+
|
1531
|
+
def test_block_arg_scope2
|
1532
|
+
rb = "a {|b; c, d| }"
|
1533
|
+
pt = s(:iter, s(:call, nil, :a), s(:args, :b, s(:shadow, :c, :d)))
|
1534
|
+
|
1535
|
+
assert_parse rb, pt
|
1536
|
+
end
|
1537
|
+
|
1538
|
+
def test_block_arg_splat_arg
|
1539
|
+
rb = "a { |b, *c, d| }"
|
1540
|
+
pt = s(:iter, s(:call, nil, :a), s(:args, :b, :"*c", :d))
|
1541
|
+
|
1542
|
+
assert_parse rb, pt
|
1543
|
+
end
|
1544
|
+
|
1545
|
+
def test_stabby_proc_scope
|
1546
|
+
rb = "->(a; b) {}"
|
1547
|
+
pt = s(:iter, s(:call, nil, :lambda), s(:args, :a, s(:shadow, :b)))
|
1548
|
+
|
1549
|
+
assert_parse rb, pt
|
1550
|
+
end
|
1551
|
+
|
1552
|
+
def test_stabby_arg_opt_splat_arg_block_omfg
|
1553
|
+
rb = "->(b, c=1, *d, e, &f){}"
|
1554
|
+
pt = s(:iter,
|
1555
|
+
s(:call, nil, :lambda),
|
1556
|
+
s(:args, :b, s(:lasgn, :c, s(:lit, 1)), :"*d", :e, :"&f"))
|
1557
|
+
|
1558
|
+
assert_parse rb, pt
|
1559
|
+
end
|
1560
|
+
|
1561
|
+
def test_block_arg_opt_splat_arg_block_omfg
|
1562
|
+
rb = "a { |b, c=1, *d, e, &f| }"
|
1563
|
+
pt = s(:iter,
|
1564
|
+
s(:call, nil, :a),
|
1565
|
+
s(:args, :b, s(:lasgn, :c, s(:lit, 1)), :"*d", :e, :"&f"))
|
1566
|
+
|
1567
|
+
assert_parse rb, pt
|
1568
|
+
end
|
1569
|
+
|
1570
|
+
def test_block_arg_opt_splat
|
1571
|
+
rb = "a { |b, c = 1, *d| }"
|
1572
|
+
pt = s(:iter, s(:call, nil, :a), s(:args, :b, s(:lasgn, :c, s(:lit, 1)), :"*d"))
|
1573
|
+
|
1574
|
+
assert_parse rb, pt
|
1575
|
+
end
|
1576
|
+
|
1577
|
+
def test_block_opt_splat
|
1578
|
+
rb = "a { |b = 1, *c| }"
|
1579
|
+
pt = s(:iter, s(:call, nil, :a), s(:args, s(:lasgn, :b, s(:lit, 1)), :"*c"))
|
1580
|
+
|
1581
|
+
assert_parse rb, pt
|
1582
|
+
end
|
1583
|
+
|
1584
|
+
def test_block_arg_opt_arg_block
|
1585
|
+
rb = "a { |b, c=1, d, &e| }"
|
1586
|
+
pt = s(:iter, s(:call, nil, :a), s(:args, :b, s(:lasgn, :c, s(:lit, 1)), :d, :"&e"))
|
1587
|
+
|
1588
|
+
assert_parse rb, pt
|
1589
|
+
end
|
1590
|
+
|
1591
|
+
def test_block_opt_arg
|
1592
|
+
rb = "a { |b=1, c| }"
|
1593
|
+
pt = s(:iter, s(:call, nil, :a), s(:args, s(:lasgn, :b, s(:lit, 1)), :c))
|
1594
|
+
|
1595
|
+
assert_parse rb, pt
|
1596
|
+
end
|
1597
|
+
|
1598
|
+
def test_defn_opt_splat_arg
|
1599
|
+
rb = "def f (a = 1, *b, c) end"
|
1600
|
+
pt = s(:defn, :f, s(:args, s(:lasgn, :a, s(:lit, 1)), :"*b", :c), s(:nil))
|
1601
|
+
|
1602
|
+
assert_parse rb, pt
|
1603
|
+
end
|
1604
|
+
|
1605
|
+
def test_block_opt_splat_arg_block_omfg
|
1606
|
+
rb = "a { |b=1, *c, d, &e| }"
|
1607
|
+
pt = s(:iter,
|
1608
|
+
s(:call, nil, :a),
|
1609
|
+
s(:args, s(:lasgn, :b, s(:lit, 1)), :"*c", :d, :"&e"))
|
1610
|
+
|
1611
|
+
assert_parse rb, pt
|
1612
|
+
end
|
1613
|
+
|
1614
|
+
def test_block_scope
|
1615
|
+
rb = "a { |;b| }"
|
1616
|
+
pt = s(:iter, s(:call, nil, :a), s(:args, s(:shadow, :b)))
|
1617
|
+
|
1618
|
+
assert_parse rb, pt
|
1619
|
+
end
|
1620
|
+
|
1621
|
+
def test_call_unary_bang
|
1622
|
+
rb = "!1"
|
1623
|
+
pt = s(:call, s(:lit, 1), :"!")
|
1624
|
+
|
1625
|
+
assert_parse rb, pt
|
1626
|
+
end
|
1627
|
+
|
1628
|
+
def test_assoc_label
|
1629
|
+
rb = "a(b:1)"
|
1630
|
+
pt = s(:call, nil, :a, s(:hash, s(:lit, :b), s(:lit, 1)))
|
1631
|
+
|
1632
|
+
assert_parse rb, pt
|
1633
|
+
end
|
1634
|
+
|
1635
|
+
def test_bang_eq
|
1636
|
+
rb = "1 != 2"
|
1637
|
+
pt = s(:call, s(:lit, 1), :"!=", s(:lit, 2))
|
1638
|
+
|
1639
|
+
assert_parse rb, pt
|
1640
|
+
end
|
1641
|
+
|
1642
|
+
def test_call_not
|
1643
|
+
rb = "not 42"
|
1644
|
+
pt = s(:call, s(:lit, 42), :"!")
|
1645
|
+
|
1646
|
+
assert_parse rb, pt
|
1647
|
+
end
|
1648
|
+
|
1649
|
+
def test_call_bang_command_call
|
1650
|
+
rb = "! a.b 1"
|
1651
|
+
pt = s(:call, s(:call, s(:call, nil, :a), :b, s(:lit, 1)), :"!")
|
1652
|
+
|
1653
|
+
assert_parse rb, pt
|
1654
|
+
end
|
1655
|
+
|
1656
|
+
def test_stabby_arg_no_paren
|
1657
|
+
rb = "->a{}"
|
1658
|
+
pt = s(:iter, s(:call, nil, :lambda), s(:args, :a))
|
1659
|
+
|
1660
|
+
assert_parse rb, pt
|
1661
|
+
end
|
1662
|
+
|
1663
|
+
def test_call_trailing_comma
|
1664
|
+
rb = "f(1,)"
|
1665
|
+
pt = s(:call, nil, :f, s(:lit, 1))
|
1666
|
+
|
1667
|
+
assert_parse rb, pt
|
1668
|
+
end
|
1669
|
+
|
1670
|
+
def test_call_assoc_trailing_comma
|
1671
|
+
rb = "f(1=>2,)"
|
1672
|
+
pt = s(:call, nil, :f, s(:hash, s(:lit, 1), s(:lit, 2)))
|
793
1673
|
|
794
1674
|
assert_parse rb, pt
|
795
1675
|
end
|
796
1676
|
|
797
|
-
def
|
798
|
-
rb = "
|
799
|
-
pt = s(:
|
800
|
-
s(:when, s(:array, s(:splat, s(:call, nil, :b))), nil),
|
801
|
-
nil)
|
1677
|
+
def test_call_args_assoc_trailing_comma
|
1678
|
+
rb = "f(1, 2=>3,)"
|
1679
|
+
pt = s(:call, nil, :f, s(:lit, 1), s(:hash, s(:lit, 2), s(:lit, 3)))
|
802
1680
|
|
803
1681
|
assert_parse rb, pt
|
804
1682
|
end
|
805
1683
|
|
806
|
-
def
|
807
|
-
rb = "
|
808
|
-
pt = s(:
|
1684
|
+
def test_do_lambda
|
1685
|
+
rb = "->() do end"
|
1686
|
+
pt = s(:iter, s(:call, nil, :lambda), 0)
|
809
1687
|
|
810
1688
|
assert_parse rb, pt
|
811
1689
|
end
|
812
1690
|
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
pt = if ruby18 then
|
817
|
-
s(:not, s(:call, nil, :a))
|
818
|
-
elsif ruby19 then
|
819
|
-
s(:call, s(:call, nil, :a), :"!")
|
820
|
-
else
|
821
|
-
raise "wtf"
|
822
|
-
end
|
1691
|
+
def test_call_dot_parens
|
1692
|
+
rb = "1.()"
|
1693
|
+
pt = s(:call, s(:lit, 1), :call)
|
823
1694
|
|
824
1695
|
assert_parse rb, pt
|
825
1696
|
end
|
826
1697
|
|
827
|
-
def
|
828
|
-
rb = "
|
829
|
-
pt = s(:
|
1698
|
+
def test_call_colon_parens
|
1699
|
+
rb = "1::()"
|
1700
|
+
pt = s(:call, s(:lit, 1), :call)
|
830
1701
|
|
831
1702
|
assert_parse rb, pt
|
832
1703
|
end
|
833
1704
|
|
834
|
-
def
|
835
|
-
rb = "
|
836
|
-
pt = s(:
|
1705
|
+
def test_block_args_opt2
|
1706
|
+
rb = "a { | b=1, c=2 | }"
|
1707
|
+
pt = s(:iter,
|
1708
|
+
s(:call, nil, :a),
|
1709
|
+
s(:args, s(:lasgn, :b, s(:lit, 1)), s(:lasgn, :c, s(:lit, 2))))
|
837
1710
|
|
838
1711
|
assert_parse rb, pt
|
839
1712
|
end
|
840
1713
|
|
841
|
-
def
|
842
|
-
rb = "a
|
843
|
-
pt = s(:
|
844
|
-
s(:op_asgn_or, s(:lvar, :a), s(:lasgn, :a, s(:call, nil, :b))),
|
845
|
-
s(:resbody, s(:array), s(:nil)))
|
1714
|
+
def test_block_paren_splat # TODO: rename # TODO: should work on 1.8
|
1715
|
+
rb = "a { |(b, *c)| }"
|
1716
|
+
pt = s(:iter, s(:call, nil, :a), s(:args, s(:masgn, :b, :"*c")))
|
846
1717
|
|
847
1718
|
assert_parse rb, pt
|
848
1719
|
end
|
849
1720
|
|
850
|
-
def
|
851
|
-
rb = "
|
1721
|
+
def test_masgn_anon_splat_arg
|
1722
|
+
rb = "*, a = b"
|
1723
|
+
pt = s(:masgn,
|
1724
|
+
s(:array, s(:splat), s(:lasgn, :a)),
|
1725
|
+
s(:to_ary, s(:call, nil, :b)))
|
852
1726
|
|
853
|
-
|
1727
|
+
assert_parse rb, pt
|
1728
|
+
end
|
854
1729
|
|
855
|
-
|
856
|
-
|
857
|
-
|
1730
|
+
def test_masgn_splat_arg
|
1731
|
+
rb = "*a, b = c"
|
1732
|
+
pt = s(:masgn,
|
1733
|
+
s(:array, s(:splat, s(:lasgn, :a)), s(:lasgn, :b)),
|
1734
|
+
s(:to_ary, s(:call, nil, :c)))
|
858
1735
|
|
859
|
-
|
860
|
-
|
861
|
-
s(:lasgn, :"cos\303\254", s(:lit, :"per\303\262"))))
|
1736
|
+
assert_parse rb, pt
|
1737
|
+
end
|
862
1738
|
|
863
|
-
|
1739
|
+
def test_lasgn_lasgn_command_call
|
1740
|
+
rb = "a = b = c 1"
|
1741
|
+
pt = s(:lasgn, :a, s(:lasgn, :b, s(:call, nil, :c, s(:lit, 1))))
|
864
1742
|
|
865
|
-
|
866
|
-
assert_parse rb, pt
|
867
|
-
end
|
1743
|
+
assert_parse rb, pt
|
868
1744
|
end
|
869
1745
|
|
870
|
-
def
|
871
|
-
rb = "
|
872
|
-
pt = s(:
|
1746
|
+
def test_masgn_arg_splat_arg
|
1747
|
+
rb = "a, *b, c = d"
|
1748
|
+
pt = s(:masgn,
|
1749
|
+
s(:array, s(:lasgn, :a), s(:splat, s(:lasgn, :b)), s(:lasgn, :c)),
|
1750
|
+
s(:to_ary, s(:call, nil, :d)))
|
873
1751
|
|
874
1752
|
assert_parse rb, pt
|
875
1753
|
end
|
876
1754
|
|
877
|
-
def
|
878
|
-
rb = "
|
879
|
-
pt = s(:
|
1755
|
+
def test_masgn_splat_arg_arg
|
1756
|
+
rb = "*a, b, c = d"
|
1757
|
+
pt = s(:masgn,
|
1758
|
+
s(:array, s(:splat, s(:lasgn, :a)), s(:lasgn, :b), s(:lasgn, :c)),
|
1759
|
+
s(:to_ary, s(:call, nil, :d)))
|
880
1760
|
|
881
1761
|
assert_parse rb, pt
|
882
1762
|
end
|
883
1763
|
|
884
|
-
def
|
885
|
-
rb = "
|
886
|
-
pt = s(:
|
1764
|
+
def test_block_decomp_anon_splat_arg
|
1765
|
+
rb = "f { |(*, a)| }"
|
1766
|
+
pt = s(:iter, s(:call, nil, :f), s(:args, s(:masgn, :*, :a)))
|
887
1767
|
|
888
1768
|
assert_parse rb, pt
|
889
1769
|
end
|
890
1770
|
|
891
|
-
def
|
892
|
-
rb =
|
893
|
-
|
894
|
-
p 1
|
895
|
-
a.b 2
|
896
|
-
c.d 3, 4
|
897
|
-
e.f 5
|
898
|
-
g.h 6, 7
|
899
|
-
p(1)
|
900
|
-
a.b(2)
|
901
|
-
c.d(3, 4)
|
902
|
-
e.f(5)
|
903
|
-
g.h(6, 7)
|
904
|
-
end
|
905
|
-
END
|
906
|
-
|
907
|
-
pt = s(:if, s(:true).line(1),
|
908
|
-
s(:block,
|
909
|
-
s(:call, nil, :p, s(:lit, 1).line(2)).line(2),
|
910
|
-
s(:call, s(:call, nil, :a).line(3), :b,
|
911
|
-
s(:lit, 2).line(3)).line(3),
|
912
|
-
s(:call, s(:call, nil, :c).line(4), :d,
|
913
|
-
s(:lit, 3).line(4), s(:lit, 4).line(4)).line(4),
|
914
|
-
s(:call, s(:call, nil, :e).line(5), :f,
|
915
|
-
s(:lit, 5).line(5)).line(5),
|
916
|
-
s(:call, s(:call, nil, :g).line(6), :h,
|
917
|
-
s(:lit, 6).line(6), s(:lit, 7).line(6)).line(6),
|
918
|
-
s(:call, nil, :p, s(:lit, 1).line(7)).line(7),
|
919
|
-
s(:call, s(:call, nil, :a).line(8), :b,
|
920
|
-
s(:lit, 2).line(8)).line(8),
|
921
|
-
s(:call, s(:call, nil, :c).line(9), :d,
|
922
|
-
s(:lit, 3).line(9), s(:lit, 4).line(9)).line(9),
|
923
|
-
s(:call, s(:call, nil, :e).line(10), :f,
|
924
|
-
s(:lit, 5).line(10)).line(10),
|
925
|
-
s(:call, s(:call, nil, :g).line(11), :h,
|
926
|
-
s(:lit, 6).line(11), s(:lit, 7).line(11)).line(11)).line(2),
|
927
|
-
nil).line(1)
|
1771
|
+
def test_block_decomp_arg_splat_arg
|
1772
|
+
rb = "f { |(a, *b, c)| }"
|
1773
|
+
pt = s(:iter, s(:call, nil, :f), s(:args, s(:masgn, :a, :"*b", :c)))
|
928
1774
|
|
929
1775
|
assert_parse rb, pt
|
930
1776
|
end
|
931
1777
|
|
932
|
-
def
|
933
|
-
|
934
|
-
if true then
|
935
|
-
p('a')
|
936
|
-
b = 1
|
937
|
-
p b
|
938
|
-
c =1
|
939
|
-
end
|
940
|
-
a
|
941
|
-
EOM
|
1778
|
+
def test_symbol_empty
|
1779
|
+
skip "can't do this in ruby 1.8" if RUBY_VERSION < "1.9"
|
942
1780
|
|
943
|
-
|
944
|
-
|
945
|
-
s(:block,
|
946
|
-
s(:call, nil, :p, s(:str, "a").line(2)).line(2),
|
947
|
-
s(:lasgn, :b, s(:lit, 1).line(3)).line(3),
|
948
|
-
s(:call, nil, :p, s(:lvar, :b).line(4)).line(4),
|
949
|
-
s(:lasgn, :c, s(:lit, 1).line(5)).line(5)).line(2), # TODO line 2?
|
950
|
-
nil).line(1),
|
951
|
-
s(:call, nil, :a).line(7)).line(1)
|
1781
|
+
rb = ":''"
|
1782
|
+
pt = s(:lit, "".to_sym)
|
952
1783
|
|
953
1784
|
assert_parse rb, pt
|
954
1785
|
end
|
955
1786
|
|
956
|
-
def
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
def show
|
962
|
-
# woot
|
963
|
-
end
|
1787
|
+
def test_masgn_var_star_var
|
1788
|
+
rb = "a, *, b = c" # TODO: blog
|
1789
|
+
pt = s(:masgn,
|
1790
|
+
s(:array, s(:lasgn, :a), s(:splat), s(:lasgn, :b)),
|
1791
|
+
s(:to_ary, s(:call, nil, :c)))
|
964
1792
|
|
965
|
-
|
966
|
-
|
967
|
-
# woot
|
968
|
-
end
|
969
|
-
end
|
970
|
-
CODE
|
1793
|
+
assert_parse rb, pt
|
1794
|
+
end
|
971
1795
|
|
972
|
-
|
973
|
-
|
974
|
-
|
1796
|
+
def test_mlhs_keyword
|
1797
|
+
skip "Breaks on 1.9 and 2.0 parser but valid" # HACK
|
1798
|
+
rb = "a.!=(true, true)"
|
1799
|
+
pt = 42
|
975
1800
|
|
976
|
-
|
977
|
-
assert_equal [], processor.comments
|
978
|
-
assert_equal "", processor.lexer.comments
|
1801
|
+
assert_parse rb, pt
|
979
1802
|
end
|
980
1803
|
end
|
981
1804
|
|
982
|
-
class TestRubyParser <
|
1805
|
+
class TestRubyParser < Minitest::Test
|
983
1806
|
def test_parse
|
984
1807
|
processor = RubyParser.new
|
985
1808
|
|
@@ -1175,10 +1998,39 @@ class TestRuby18Parser < RubyParserTestCase
|
|
1175
1998
|
|
1176
1999
|
assert_parse rb, pt.dup
|
1177
2000
|
end
|
2001
|
+
|
2002
|
+
def test_call_unary_bang
|
2003
|
+
rb = "!1"
|
2004
|
+
pt = s(:not, s(:lit, 1))
|
2005
|
+
|
2006
|
+
assert_parse rb, pt
|
2007
|
+
end
|
2008
|
+
|
2009
|
+
def test_bang_eq
|
2010
|
+
rb = "1 != 2"
|
2011
|
+
pt = s(:not, s(:call, s(:lit, 1), :"==", s(:lit, 2)))
|
2012
|
+
|
2013
|
+
assert_parse rb, pt
|
2014
|
+
end
|
2015
|
+
|
2016
|
+
def test_call_not
|
2017
|
+
rb = "not 42"
|
2018
|
+
pt = s(:not, s(:lit, 42))
|
2019
|
+
|
2020
|
+
assert_parse rb, pt
|
2021
|
+
end
|
2022
|
+
|
2023
|
+
def test_call_bang_command_call
|
2024
|
+
rb = "! a.b 1"
|
2025
|
+
pt = s(:not, s(:call, s(:call, nil, :a), :b, s(:lit, 1)))
|
2026
|
+
|
2027
|
+
assert_parse rb, pt
|
2028
|
+
end
|
1178
2029
|
end
|
1179
2030
|
|
1180
2031
|
class TestRuby19Parser < RubyParserTestCase
|
1181
2032
|
include TestRubyParserShared
|
2033
|
+
include TestRubyParserShared1920
|
1182
2034
|
|
1183
2035
|
def setup
|
1184
2036
|
super
|
@@ -1267,17 +2119,6 @@ class TestRuby19Parser < RubyParserTestCase
|
|
1267
2119
|
assert_parse rb, pt
|
1268
2120
|
end
|
1269
2121
|
|
1270
|
-
def test_encoding
|
1271
|
-
rb = '__ENCODING__'
|
1272
|
-
pt = if defined? Encoding then
|
1273
|
-
s(:const, Encoding::UTF_8)
|
1274
|
-
else
|
1275
|
-
s(:str, "Unsupported!")
|
1276
|
-
end
|
1277
|
-
|
1278
|
-
assert_parse rb, pt
|
1279
|
-
end
|
1280
|
-
|
1281
2122
|
def test_do_colon_19
|
1282
2123
|
rb = "while false : 42 end"
|
1283
2124
|
|
@@ -1377,7 +2218,7 @@ class TestRuby19Parser < RubyParserTestCase
|
|
1377
2218
|
|
1378
2219
|
def test_parse_opt_call_args_assocs_comma
|
1379
2220
|
rb = "1[2=>3,]"
|
1380
|
-
pt = s(:call, s(:lit, 1), :[], s(:lit, 2), s(:lit, 3))
|
2221
|
+
pt = s(:call, s(:lit, 1), :[], s(:hash, s(:lit, 2), s(:lit, 3)))
|
1381
2222
|
|
1382
2223
|
assert_parse rb, pt
|
1383
2224
|
end
|
@@ -1779,3 +2620,156 @@ class TestRuby19Parser < RubyParserTestCase
|
|
1779
2620
|
assert_parse rb, pt
|
1780
2621
|
end
|
1781
2622
|
end
|
2623
|
+
|
2624
|
+
class TestRuby20Parser < RubyParserTestCase
|
2625
|
+
include TestRubyParserShared
|
2626
|
+
include TestRubyParserShared1920
|
2627
|
+
|
2628
|
+
def setup
|
2629
|
+
super
|
2630
|
+
|
2631
|
+
self.processor = Ruby20Parser.new
|
2632
|
+
end
|
2633
|
+
|
2634
|
+
def test_defn_kwarg_val
|
2635
|
+
rb = "def f(a, b:1) end"
|
2636
|
+
pt = s(:defn, :f, s(:args, :a, s(:kwarg, :b, s(:lit, 1))), s(:nil))
|
2637
|
+
|
2638
|
+
assert_parse rb, pt
|
2639
|
+
end
|
2640
|
+
|
2641
|
+
def test_args_kw_block
|
2642
|
+
rb = "def f(a: 1, &b); end"
|
2643
|
+
pt = s(:defn, :f, s(:args, s(:kwarg, :a, s(:lit, 1)), :"&b"), s(:nil))
|
2644
|
+
|
2645
|
+
assert_parse rb, pt
|
2646
|
+
end
|
2647
|
+
|
2648
|
+
def test_defn_kwarg_kwarg
|
2649
|
+
rb = "def f(a, b: 1, c: 2) end"
|
2650
|
+
pt = s(:defn, :f, s(:args, :a,
|
2651
|
+
s(:kwarg, :b, s(:lit, 1)),
|
2652
|
+
s(:kwarg, :c, s(:lit, 2))),
|
2653
|
+
s(:nil))
|
2654
|
+
|
2655
|
+
assert_parse rb, pt
|
2656
|
+
end
|
2657
|
+
|
2658
|
+
def test_defn_powarg
|
2659
|
+
rb = "def f(**opts) end"
|
2660
|
+
pt = s(:defn, :f, s(:args, :"**opts"), s(:nil))
|
2661
|
+
|
2662
|
+
assert_parse rb, pt
|
2663
|
+
end
|
2664
|
+
|
2665
|
+
def test_block_arg_kwsplat
|
2666
|
+
rb = "a { |**b| }"
|
2667
|
+
pt = s(:iter, s(:call, nil, :a), s(:args, :"**b"))
|
2668
|
+
|
2669
|
+
assert_parse rb, pt
|
2670
|
+
end
|
2671
|
+
|
2672
|
+
def test_symbols
|
2673
|
+
rb = "%i(a b c)"
|
2674
|
+
pt = s(:array, s(:lit, :a), s(:lit, :b), s(:lit, :c))
|
2675
|
+
|
2676
|
+
assert_parse rb, pt
|
2677
|
+
end
|
2678
|
+
|
2679
|
+
def test_symbols_interp
|
2680
|
+
rb = '%i(a b#{1+1} c)'
|
2681
|
+
pt = s(:array, s(:lit, :a), s(:lit, :'b#{1+1}'), s(:lit, :c))
|
2682
|
+
|
2683
|
+
assert_parse rb, pt
|
2684
|
+
end
|
2685
|
+
|
2686
|
+
def test_symbols_empty_space
|
2687
|
+
rb = "%i( )"
|
2688
|
+
pt = s(:array)
|
2689
|
+
|
2690
|
+
assert_parse rb, pt
|
2691
|
+
end
|
2692
|
+
|
2693
|
+
def test_symbols_empty
|
2694
|
+
rb = "%i()"
|
2695
|
+
pt = s(:array)
|
2696
|
+
|
2697
|
+
assert_parse rb, pt
|
2698
|
+
end
|
2699
|
+
|
2700
|
+
def test_qsymbols
|
2701
|
+
rb = "%I(a b c)"
|
2702
|
+
pt = s(:array, s(:lit, :a), s(:lit, :b), s(:lit, :c))
|
2703
|
+
|
2704
|
+
assert_parse rb, pt
|
2705
|
+
end
|
2706
|
+
|
2707
|
+
def test_qsymbols_interp
|
2708
|
+
rb = '%I(a b#{1+1} c)'
|
2709
|
+
pt = s(:array,
|
2710
|
+
s(:lit, :a),
|
2711
|
+
s(:dsym, "b", s(:evstr, s(:call, s(:lit, 1), :+, s(:lit, 1)))),
|
2712
|
+
s(:lit, :c))
|
2713
|
+
|
2714
|
+
assert_parse rb, pt
|
2715
|
+
end
|
2716
|
+
|
2717
|
+
def test_qsymbols_empty
|
2718
|
+
rb = "%I()"
|
2719
|
+
pt = s(:array)
|
2720
|
+
|
2721
|
+
assert_parse rb, pt
|
2722
|
+
end
|
2723
|
+
|
2724
|
+
def test_qsymbols_empty_space
|
2725
|
+
rb = "%I( )"
|
2726
|
+
pt = s(:array)
|
2727
|
+
|
2728
|
+
assert_parse rb, pt
|
2729
|
+
end
|
2730
|
+
|
2731
|
+
def test_defn_unary_not # TODO: this needs to work on 1.9
|
2732
|
+
skip "Not yet"
|
2733
|
+
rb = "def !@; true; end" # I seriously HATE this
|
2734
|
+
pt = s(:defn, :"!@", s(:args), s(:true))
|
2735
|
+
|
2736
|
+
assert_parse rb, pt
|
2737
|
+
end
|
2738
|
+
|
2739
|
+
def test_defn_kwarg_kwsplat
|
2740
|
+
rb = "def a(b: 1, **c) end"
|
2741
|
+
pt = s(:defn, :a, s(:args, s(:kwarg, :b, s(:lit, 1)), :"**c"), s(:nil))
|
2742
|
+
|
2743
|
+
assert_parse rb, pt
|
2744
|
+
end
|
2745
|
+
|
2746
|
+
def test_call_arg_kwsplat
|
2747
|
+
rb = "a(b, **1)"
|
2748
|
+
pt = s(:call, nil, :a, s(:call, nil, :b), s(:kwsplat, s(:lit, 1)))
|
2749
|
+
|
2750
|
+
assert_parse rb, pt
|
2751
|
+
end
|
2752
|
+
|
2753
|
+
def test_iter_kwarg
|
2754
|
+
rb = "a { |b: 1| }"
|
2755
|
+
pt = s(:iter, s(:call, nil, :a), s(:args, s(:kwarg, :b, s(:lit, 1))))
|
2756
|
+
|
2757
|
+
assert_parse rb, pt
|
2758
|
+
end
|
2759
|
+
|
2760
|
+
def test_iter_kwarg_kwsplat
|
2761
|
+
rb = "a { |b: 1, **c| }"
|
2762
|
+
pt = s(:iter, s(:call, nil, :a), s(:args, s(:kwarg, :b, s(:lit, 1)), :"**c"))
|
2763
|
+
|
2764
|
+
assert_parse rb, pt
|
2765
|
+
end
|
2766
|
+
|
2767
|
+
def test_iter_array_curly
|
2768
|
+
rb = "f :a, [:b] { |c, d| }" # yes, this is bad code... that's their problem
|
2769
|
+
pt = s(:iter,
|
2770
|
+
s(:call, nil, :f, s(:lit, :a), s(:array, s(:lit, :b))),
|
2771
|
+
s(:args, :c, :d))
|
2772
|
+
|
2773
|
+
assert_parse rb, pt
|
2774
|
+
end
|
2775
|
+
end
|