Distinguish pre-condition and post-condition loops
This commit is contained in:
parent
39336a4210
commit
c4bad9f74e
3
ast.c
3
ast.c
@ -374,7 +374,8 @@ node_children(rb_ast_t *ast, NODE *node)
|
|||||||
goto loop;
|
goto loop;
|
||||||
case NODE_UNTIL:
|
case NODE_UNTIL:
|
||||||
loop:
|
loop:
|
||||||
return rb_ary_new_from_node_args(ast, 2, node->nd_cond, node->nd_body);
|
return rb_ary_push(rb_ary_new_from_node_args(ast, 2, node->nd_cond, node->nd_body),
|
||||||
|
(node->nd_state ? Qtrue : Qfalse));
|
||||||
case NODE_ITER:
|
case NODE_ITER:
|
||||||
case NODE_FOR:
|
case NODE_FOR:
|
||||||
return rb_ary_new_from_node_args(ast, 2, node->nd_iter, node->nd_body);
|
return rb_ary_new_from_node_args(ast, 2, node->nd_iter, node->nd_body);
|
||||||
|
@ -278,4 +278,16 @@ class TestAst < Test::Unit::TestCase
|
|||||||
assert_equal(:LIT, body.type)
|
assert_equal(:LIT, body.type)
|
||||||
assert_equal([1], body.children)
|
assert_equal([1], body.children)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_while
|
||||||
|
node = RubyVM::AbstractSyntaxTree.parse('1 while 1')
|
||||||
|
_, _, body = *node.children
|
||||||
|
assert_equal(:WHILE, body.type)
|
||||||
|
type1 = body.children[2]
|
||||||
|
node = RubyVM::AbstractSyntaxTree.parse('begin 1 end while 1')
|
||||||
|
_, _, body = *node.children
|
||||||
|
assert_equal(:WHILE, body.type)
|
||||||
|
type2 = body.children[2]
|
||||||
|
assert_not_equal(type1, type2)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user