summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-07 14:46:25 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-07 14:46:25 +0000
commitdaf789b5a5404d688ae46971f8c33ecdc434ee17 (patch)
treea7475f2839ae8ea6efc21efe765afa1fdbf760f9 /test
parent69e5eb35d364d233ee216952fa718020586e747d (diff)
downloadruby-daf789b5a5404d688ae46971f8c33ecdc434ee17.tar.gz
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
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_ast.rb17
1 files changed, 12 insertions, 5 deletions
diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb
index 4696472965..90c06fb5ce 100644
--- a/test/ruby/test_ast.rb
+++ b/test/ruby/test_ast.rb
@@ -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