summaryrefslogtreecommitdiff
path: root/test/ripper
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-04 06:47:29 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-04 06:47:29 +0000
commit2afb729f57cfc0806e5a7734b53b20263cce2e58 (patch)
tree1bbaffbea057adc167fba1e465367183c5da9860 /test/ripper
parent3be412834d4f09eb0c2a705073ff10b1fd0d6e93 (diff)
parse.y: fix var_field
* parse.y (mlhs_node): dispatch var_field as well as lhs. * parse.y (lhs, var_hs): dispatch var_field before assignable check so it is inside assign_error at a wrong assignment, as well as backref_assign_error. * parse.y (var_field_gen): wrap var_field value with the variable ID. * parse.y (assignable_gen, const_decl_gen): return the callback result on a syntax error. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60116 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ripper')
-rw-r--r--test/ripper/test_parser_events.rb57
1 files changed, 39 insertions, 18 deletions
diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb
index ccebe2dbb7..cf118a49c2 100644
--- a/test/ripper/test_parser_events.rb
+++ b/test/ripper/test_parser_events.rb
@@ -194,7 +194,10 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
end
def test_assign_error
- # for test_coverage
+ thru_assign_error = false
+ result = parse('self = 1', :on_assign_error) {thru_assign_error = true}
+ assert_equal true, thru_assign_error
+ assert_equal '[assign(assign_error(var_field(self)),1)]', result
end
def test_assign_error_backref
@@ -208,29 +211,47 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
result =
parse('$`, _ = 1', :on_assign_error) {thru_assign_error = true}
assert_equal true, thru_assign_error
- assert_equal '[massign([assign_error(var_field($`)),_],1)]', result
+ assert_equal '[massign([assign_error(var_field($`)),var_field(_)],1)]', result
end
def test_assign_error_const_qualified
thru_assign_error = false
- parse('self::X = 1', :on_assign_error) {thru_assign_error = true}
+ result =
+ parse('self::X = 1', :on_assign_error) {thru_assign_error = true}
assert_equal false, thru_assign_error
- parse("def m\n self::X = 1\nend", :on_assign_error) {thru_assign_error = true}
+ assert_equal "[assign(const_path_field(ref(self),X),1)]", result
+
+ thru_assign_error = false
+ result =
+ parse("def m\n self::X = 1\nend", :on_assign_error) {thru_assign_error = true}
assert_equal true, thru_assign_error
+ assert_include result, "assign_error(const_path_field(ref(self),X))"
+
thru_assign_error = false
- parse("def m\n self::X, a = 1, 2\nend", :on_assign_error) {thru_assign_error = true}
+ result =
+ parse("def m\n self::X, a = 1, 2\nend", :on_assign_error) {thru_assign_error = true}
assert_equal true, thru_assign_error
+ assert_include result, "assign_error(const_path_field(ref(self),X))"
end
def test_assign_error_const
thru_assign_error = false
- parse('X = 1', :on_assign_error) {thru_assign_error = true}
+ result = parse('X = 1', :on_assign_error) {thru_assign_error = true}
+ assert_equal false, thru_assign_error
+ assert_equal "[assign(var_field(X),1)]", result
+
+ thru_assign_error = false
+ result = parse('X, a = 1, 2', :on_assign_error) {thru_assign_error = true}
assert_equal false, thru_assign_error
- parse("def m\n X = 1\nend", :on_assign_error) {thru_assign_error = true}
+ assert_include result, "massign([var_field(X),var_field(a)],"
+
+ result = parse("def m\n X = 1\nend", :on_assign_error) {thru_assign_error = true}
assert_equal true, thru_assign_error
+ assert_include result, "assign_error(var_field(X))"
thru_assign_error = false
- parse("def m\n X, a = 1, 2\nend", :on_assign_error) {thru_assign_error = true}
+ result = parse("def m\n X, a = 1, 2\nend", :on_assign_error) {thru_assign_error = true}
assert_equal true, thru_assign_error
+ assert_include result, "assign_error(var_field(X))"
end
def test_assign_error_const_toplevel
@@ -475,46 +496,46 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
thru_mlhs_add_star = false
tree = parse("a, *b = 1, 2", :on_mlhs_add_star) {thru_mlhs_add_star = true}
assert_equal true, thru_mlhs_add_star
- assert_include(tree, "massign([a,*b]")
+ assert_include(tree, "massign([var_field(a),*var_field(b)]")
thru_mlhs_add_star = false
tree = parse("a, *b, c = 1, 2", :on_mlhs_add_star) {thru_mlhs_add_star = true}
assert_equal true, thru_mlhs_add_star
- assert_include(tree, "massign([a,*b,c]", bug2232)
+ assert_include(tree, "massign([var_field(a),*var_field(b),var_field(c)]", bug2232)
thru_mlhs_add_star = false
tree = parse("a, *, c = 1, 2", :on_mlhs_add_star) {thru_mlhs_add_star = true}
assert_equal true, thru_mlhs_add_star
- assert_include(tree, "massign([a,*,c]", bug4364)
+ assert_include(tree, "massign([var_field(a),*,var_field(c)]", bug4364)
thru_mlhs_add_star = false
tree = parse("*b, c = 1, 2", :on_mlhs_add_star) {thru_mlhs_add_star = true}
assert_equal true, thru_mlhs_add_star
- assert_include(tree, "massign([*b,c]", bug4364)
+ assert_include(tree, "massign([*var_field(b),var_field(c)]", bug4364)
thru_mlhs_add_star = false
tree = parse("*, c = 1, 2", :on_mlhs_add_star) {thru_mlhs_add_star = true}
assert_equal true, thru_mlhs_add_star
- assert_include(tree, "massign([*,c],", bug4364)
+ assert_include(tree, "massign([*,var_field(c)],", bug4364)
end
def test_mlhs_add_post
thru_mlhs_add_post = false
tree = parse("a, *b = 1, 2", :on_mlhs_add_post) {thru_mlhs_add_post = true}
assert_equal false, thru_mlhs_add_post
- assert_include(tree, "massign([a,*b],")
+ assert_include(tree, "massign([var_field(a),*var_field(b)],")
thru_massign_add_post = false
tree = parse("a, *b, c = 1, 2", :on_mlhs_add_post) {thru_mlhs_add_post = true}
assert_equal true, thru_mlhs_add_post
- assert_include(tree, "massign([a,*b,c],")
+ assert_include(tree, "massign([var_field(a),*var_field(b),var_field(c)],")
thru_mlhs_add_post = false
tree = parse("a, *, c = 1, 2", :on_mlhs_add_post) {thru_mlhs_add_post = true}
assert_equal true, thru_mlhs_add_post
- assert_include(tree, "massign([a,*,c],")
+ assert_include(tree, "massign([var_field(a),*,var_field(c)],")
thru_mlhs_add_post = false
tree = parse("*b, c = 1, 2", :on_mlhs_add_post) {thru_mlhs_add_post = true}
assert_equal true, thru_mlhs_add_post
- assert_include(tree, "massign([*b,c],")
+ assert_include(tree, "massign([*var_field(b),var_field(c)],")
thru_mlhs_add_post = false
tree = parse("*, c = 1, 2", :on_mlhs_add_post) {thru_mlhs_add_post = true}
assert_equal true, thru_mlhs_add_post
- assert_include(tree, "massign([*,c],")
+ assert_include(tree, "massign([*,var_field(c)],")
end
def test_mlhs_new