def test_parse_parameter_list(self): """ ( (type identifier) (',' type identifier)*)? """ tokens = ( Token('dummy', 'dummy'), # Dummy type Token('identifier', 'foo'), Token('symbol', ','), Token('dummy', 'dummy'), # Dummy type Token('identifier', 'bar'), ) expected = Token('parameterList', [ Token('dummy', 'dummy'), # Dummy type Token('identifier', 'foo'), Token('symbol', ','), Token('dummy', 'dummy'), # Dummy type Token('identifier', 'bar'), ]) parser = Parser(tokens) parser.parse_type = self._mock_parse(parser) actual = parser.parse_parameter_list() self.assertEqual(expected, actual)
def test_parse_subroutine_declaration(self): """ ('constructor'|'function'|'method') ('void'|type) identifier '('parameterList ')' subroutineBody """ tokens = ( Token('keyword', 'method'), Token('keyword', 'int'), # Dummy type Token('identifier', 'foo'), Token('symbol', '('), Token('dummy', 'dummy'), # Dummy parameterList Token('symbol', ')'), Token('dummy', 'dummy'), # Dummy subroutineBody ) expected = Token('subroutineDec', [ Token('keyword', 'method'), Token('dummy', 'dummy'), # Dummy type Token('identifier', 'foo'), Token('symbol', '('), Token('dummy', 'dummy'), # Dummy parameterList Token('symbol', ')'), Token('dummy', 'dummy'), # Dummy subroutineBody ]) parser = Parser(tokens) parser.parse_type = self._mock_parse(parser) parser.parse_parameter_list = self._mock_parse(parser) parser.parse_subroutine_body = self._mock_parse(parser) actual = parser.parse_subroutine_declaration() self.assertEqual(expected, actual)
def test_parse_parameter_list_empty(self): """ ( (type identifier) (',' type identifier)*)? """ tokens = (Token('symbol',')'), ) expected = Token('parameterList', []) parser = Parser(tokens) parser.parse_type = self._mock_parse(parser) actual = parser.parse_parameter_list() self.assertEqual(expected, actual)