def test_while_loop(self): r = self.parse(''' let i, s; i = 0; while i < 10 { i = i + 1; s = s + i; } return s; ''') assert r == [ ast.VarDeclaration([ast.Var('i', ast.NoTypeDecl(), None), ast.Var('s', ast.NoTypeDecl(), None)]), ast.Assignment('i', ast.Number(0)), ast.While( ast.BinOp('<', ast.Identifier('i'), ast.Number(10), oppos=(51, 52)), [ ast.Assignment('i', ast.BinOp( '+', ast.Identifier('i'), ast.Number(1), oppos=(72, 73))), ast.Assignment('s', ast.BinOp( '+', ast.Identifier('s'), ast.Identifier('i'), oppos=(91, 92)))]), ast.Return(ast.Identifier('s'))]
def test_while_loop(self): r = self.parse(''' var i, s; i = 0; while i < 10 { i = i + 1; s = s + i; } return s; ''') assert r == [ ast.VarDeclaration(['i', 's']), ast.Assignment('i', ast.Number(0)), ast.While(ast.BinOp('<', ast.Identifier('i'), ast.Number(10)), [ ast.Assignment( 'i', ast.BinOp('+', ast.Identifier('i'), ast.Number(1))), ast.Assignment( 's', ast.BinOp('+', ast.Identifier('s'), ast.Identifier('i'))) ]), ast.Return(ast.Identifier('s')) ]
def statement_while_loop(state, p): return ast.While(p[1], p[3].get_element_list(), srcpos=sr(p))