Add NODE_DEFINED tests for cases with parentheses to test_ast.rb

This commit is contained in:
ydah 2025-07-24 23:39:39 +09:00 committed by Yudai Takada
parent 5ef20b3a27
commit b2838bef69
2 changed files with 12 additions and 9 deletions

8
ast.c
View file

@ -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;

View file

@ -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