def test_class_var_declaration_multiple(self): """ ('static' | 'field' ) type varName (',' varName)* ';' """ tokens = ( Token('keyword', 'static'), Token('keyword', 'int'), # Dummy type Token('identifier', 'foo'), Token('symbol', ','), Token('identifier', 'bar'), Token('symbol', ','), Token('identifier', 'baz'), Token('symbol', ';'), ) expected = Token('classVarDec', [ Token('keyword', 'static'), Token('dummy', 'dummy'), Token('identifier', 'foo'), Token('symbol', ','), Token('identifier', 'bar'), Token('symbol', ','), Token('identifier', 'baz'), Token('symbol', ';'), ]) parser = Parser(tokens) parser.parse_type = self._mock_parse(parser) actual = parser.parse_class_var_declaration() self.assertEqual(expected, actual)
def test_class_with_body(self): """ 'class' className '{' classVarDec* subroutineDec* '}' """ tokens = ( Token('keyword', 'class'), Token('identifier', 'Main'), Token('symbol', '{'), Token('keyword', 'static'), # Dummy class var declaration Token('keyword', 'function'), # Dummy subroutine declaration Token('symbol', '}'), ) expected = Token('class', [ Token('keyword', 'class'), Token('identifier', 'Main'), Token('symbol', '{'), Token('dummy', 'dummy'), Token('dummy', 'dummy'), Token('symbol', '}'), ]) parser = Parser(tokens) parser.parse_class_var_declaration = self._mock_parse(parser) parser.parse_subroutine_declaration = self._mock_parse(parser) actual = parser.parse_class() self.assertEqual(expected, actual)