mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
ast.c: refine AST#children
* ast.c (node_children): refined RubyVM::AST#children to include symbols (variables, methods, classes, etc). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63604 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
69e5eb35d3
commit
daf789b5a5
2 changed files with 88 additions and 38 deletions
|
|
@ -72,7 +72,7 @@ class TestAst < Test::Unit::TestCase
|
|||
|
||||
def validate_range0(node)
|
||||
beg_pos, end_pos = node.beg_pos, node.end_pos
|
||||
children = node.children.compact
|
||||
children = node.children.grep(RubyVM::AST)
|
||||
|
||||
return true if children.empty?
|
||||
# These NODE_D* has NODE_ARRAY as nd_next->nd_next whose last locations
|
||||
|
|
@ -100,7 +100,7 @@ class TestAst < Test::Unit::TestCase
|
|||
|
||||
def validate_not_cared0(node)
|
||||
beg_pos, end_pos = node.beg_pos, node.end_pos
|
||||
children = node.children.compact
|
||||
children = node.children.grep(RubyVM::AST)
|
||||
|
||||
@errors << { type: :first_lineno, node: node } if beg_pos.lineno == 0
|
||||
@errors << { type: :first_column, node: node } if beg_pos.column == -1
|
||||
|
|
@ -134,18 +134,18 @@ class TestAst < Test::Unit::TestCase
|
|||
def test_column_with_long_heredoc_identifier
|
||||
term = "A"*257
|
||||
ast = RubyVM::AST.parse("<<-#{term}\n""ddddddd\n#{term}\n")
|
||||
node = ast.children[1]
|
||||
node = ast.children[2]
|
||||
assert_equal("NODE_STR", node.type)
|
||||
assert_equal(0, node.first_column)
|
||||
end
|
||||
|
||||
def test_column_of_heredoc
|
||||
node = RubyVM::AST.parse("<<-SRC\nddddddd\nSRC\n").children[1]
|
||||
node = RubyVM::AST.parse("<<-SRC\nddddddd\nSRC\n").children[2]
|
||||
assert_equal("NODE_STR", node.type)
|
||||
assert_equal(0, node.first_column)
|
||||
assert_equal(6, node.last_column)
|
||||
|
||||
node = RubyVM::AST.parse("<<SRC\nddddddd\nSRC\n").children[1]
|
||||
node = RubyVM::AST.parse("<<SRC\nddddddd\nSRC\n").children[2]
|
||||
assert_equal("NODE_STR", node.type)
|
||||
assert_equal(0, node.first_column)
|
||||
assert_equal(5, node.last_column)
|
||||
|
|
@ -171,4 +171,11 @@ class TestAst < Test::Unit::TestCase
|
|||
end;
|
||||
end
|
||||
end
|
||||
|
||||
def test_scope_local_variables
|
||||
node = RubyVM::AST.parse("x = 0")
|
||||
lv, _, body = *node.children
|
||||
assert_equal([:x], lv)
|
||||
assert_equal("NODE_LASGN", body.type)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue