def test_variable_declaration(self): decl = parse_statement('int a').accept(statements.Declaration) assdecl = parse_statement('int a=3').accept(statements.Declaration) self.assertEqual(decl.identifier.name, 'a') self.assertEqual(decl.type_.name, 'int') self.assertEqual(assdecl.identifier.name, 'a') self.assertEqual(assdecl.type_.name, 'int') self.assertEqual(assdecl.expression.value, '3')
def test_tolerate_whitespace(self): s1 = parse_statement('int a = 3') self.assertIsInstance(s1, statements.Declaration) s2 = parse_statement('b = \n\t6\r') self.assertIsInstance(s2, statements.Assignment) e1 = parse_expression('a + 5 + 9') self.assertIsInstance(e1, expressions.Sum) e2 = parse_expression('- 4') self.assertIsInstance(e2, expressions.Minus)
def test_assignment(self): ass = parse_statement('a=3').accept(statements.Assignment) self.assertEqual(ass.assignee.name, 'a') self.assertEqual(ass.expression.value, '3')
def test_empty_statement(self): nostmt = parse_statement('') self.assertIsInstance(nostmt, statements.EmptyStatement)
def test_namespaces(self): 'test namespace references in identifiers and assignments' stmt1 = parse_statement('int a') self.assertIsInstance(stmt1.get_namespace(), Namespace)
def test_function(self): blk = parse_statement('int a(){}') self.assertIsInstance(blk, functions.FunctionDefinition)