Пример #1
0
 def test_function_declaration_args(self):
     r = self.parse('''
         def foo(a0, a1) {
         }
         ''')
     expected = ast.Program([
         ast.Function('foo', [ast.Var('a0', ast.NoTypeDecl(), None),
                              ast.Var('a1', ast.NoTypeDecl(), None)], [
         ], lineno=1)
     ])
     assert r == expected
Пример #2
0
 def test_var(self):
     r = self.parse('''
         let x;
         x = 3;
         x = x + 1;
         ''')
     assert r == [
         ast.VarDeclaration([ast.Var('x', ast.NoTypeDecl(), None)]),
         ast.Assignment('x', ast.Number(3)),
         ast.Assignment('x', ast.BinOp('+', ast.Identifier('x'),
                                       ast.Number(1), oppos=(46, 47)))]
Пример #3
0
 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'))]
Пример #4
0
    def test_function_declaration(self):
        r = self.parse('''
            def foo() {
                let x;
            }

            def main() {
            }
            ''')
        expected = ast.Program([
            ast.Function('foo', [], [
                ast.VarDeclaration([ast.Var('x', ast.NoTypeDecl(), None)])
            ], lineno=1),
            ast.Function('main', [], [], lineno=4)
        ])
        assert r == expected
Пример #5
0
 def type_decl_empty(state, p):
     return ast.NoTypeDecl(srcpos=(0, 0))