From b2838bef693db39960ca5e326e61408b4721b7bb Mon Sep 17 00:00:00 2001 From: ydah Date: Thu, 24 Jul 2025 23:39:39 +0900 Subject: [PATCH] Add NODE_DEFINED tests for cases with parentheses to test_ast.rb --- ast.c | 8 ++++---- test/ruby/test_ast.rb | 13 ++++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ast.c b/ast.c index 8b7ed10307..04f2d1384c 100644 --- a/ast.c +++ b/ast.c @@ -822,6 +822,10 @@ node_locations(VALUE ast_value, const NODE *node) location_new(nd_code_loc(node)), location_new(&RNODE_COLON3(node)->delimiter_loc), location_new(&RNODE_COLON3(node)->name_loc)); + case NODE_DEFINED: + return rb_ary_new_from_args(2, + location_new(nd_code_loc(node)), + location_new(&RNODE_DEFINED(node)->keyword_loc)); case NODE_DOT2: return rb_ary_new_from_args(2, location_new(nd_code_loc(node)), @@ -948,10 +952,6 @@ node_locations(VALUE ast_value, const NODE *node) location_new(&RNODE_YIELD(node)->keyword_loc), location_new(&RNODE_YIELD(node)->lparen_loc), location_new(&RNODE_YIELD(node)->rparen_loc)); - case NODE_DEFINED: - return rb_ary_new_from_args(2, - location_new(nd_code_loc(node)), - location_new(&RNODE_DEFINED(node)->keyword_loc)); case NODE_ARGS_AUX: case NODE_LAST: break; diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb index d716fde519..5524fa7146 100644 --- a/test/ruby/test_ast.rb +++ b/test/ruby/test_ast.rb @@ -1415,6 +1415,14 @@ dummy assert_locations(node.children[-1].children[0].locations, [[1, 0, 1, 3], [1, 0, 1, 2], [1, 2, 1, 3]]) end + def test_defined_locations + node = ast_parse("defined? x") + assert_locations(node.children[-1].locations, [[1, 0, 1, 10], [1, 0, 1, 8]]) + + node = ast_parse("defined?(x)") + assert_locations(node.children[-1].locations, [[1, 0, 1, 11], [1, 0, 1, 8]]) + end + def test_dot2_locations node = ast_parse("1..2") assert_locations(node.children[-1].locations, [[1, 0, 1, 4], [1, 1, 1, 3]]) @@ -1655,11 +1663,6 @@ dummy assert_locations(node.children[-1].children[-1].children[-1].locations, [[1, 9, 1, 20], [1, 9, 1, 14], [1, 14, 1, 15], [1, 19, 1, 20]]) end - def test_defined_locations - node = ast_parse("defined? x") - assert_locations(node.children[-1].locations, [[1, 0, 1, 10], [1, 0, 1, 8]]) - end - private def ast_parse(src, **options) begin