Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_pointer_to_function_returning_pointer_to_const(self):
self.assertEqual(str(PointerTypeName(FunctionTypeName(PointerTypeName(BasicTypeName('int', qualifiers={'const'})), [(BasicTypeName('int'), None)]))),
'const int *(*)(int)')
def test_pointer_to_function_with_no_parameters(self):
self.assertEqual(str(PointerTypeName(FunctionTypeName(BasicTypeName('int'), []))),
'int (*)(void)')
def test_pointer_to_variadic_function(self):
self.assertEqual(str(PointerTypeName(FunctionTypeName(BasicTypeName('int'), [(BasicTypeName('int'), None)], variadic=True))),
'int (*)(int, ...)')
def test_pointer(self):
self.assertEqual(parse_type_name('int *'),
PointerTypeName(BasicTypeName('int')))
self.assertEqual(parse_type_name('int * const'),
PointerTypeName(BasicTypeName('int'),
qualifiers={'const'}))
self.assertEqual(parse_type_name('struct point *'),
PointerTypeName(StructTypeName('point')))
self.assertEqual(parse_type_name('int **'),
PointerTypeName(PointerTypeName(BasicTypeName('int'))))
self.assertEqual(parse_type_name('int *((*))'),
PointerTypeName(PointerTypeName(BasicTypeName('int'))))
self.assertEqual(parse_type_name('int * const *'),
PointerTypeName(PointerTypeName(BasicTypeName('int'),
qualifiers={'const'})))
def test_pointer_to_function_returning_pointer(self):
self.assertEqual(str(PointerTypeName(FunctionTypeName(PointerTypeName(BasicTypeName('int')), [(BasicTypeName('int'), None)]))),
'int *(*)(int)')
self.assertEqual(str(PointerTypeName(FunctionTypeName(PointerTypeName(BasicTypeName('int')), [(PointerTypeName(BasicTypeName('int')), None)]))),
'int *(*)(int *)')
def test_pointer(self):
self.assertEqual(str(PointerTypeName(BasicTypeName('int'))), 'int *')
self.assertEqual(str(PointerTypeName(BasicTypeName('int'), qualifiers={'const'})),
'int * const')
self.assertEqual(str(PointerTypeName(BasicTypeName('struct point'))),
'struct point *')
self.assertEqual(str(PointerTypeName(PointerTypeName(BasicTypeName('int')))),
'int **')
self.assertEqual(str(PointerTypeName(PointerTypeName(BasicTypeName('int'),
qualifiers={'const'}))),
'int * const *')
def test_pointer(self):
self.assertEqual(str(PointerTypeName(BasicTypeName('int'))), 'int *')
self.assertEqual(str(PointerTypeName(BasicTypeName('int'), qualifiers={'const'})),
'int * const')
self.assertEqual(str(PointerTypeName(BasicTypeName('struct point'))),
'struct point *')
self.assertEqual(str(PointerTypeName(PointerTypeName(BasicTypeName('int')))),
'int **')
self.assertEqual(str(PointerTypeName(PointerTypeName(BasicTypeName('int'),
qualifiers={'const'}))),
'int * const *')
def type_name(self) -> PointerTypeName:
return PointerTypeName(self.type.type_name(), self.qualifiers)
def _parse_pointer(self, type_name: TypeName) -> Tuple[TypeName, Optional[PointerTypeName]]:
if self._lexer.peek().kind != 'ASTERISK':
raise ValueError("expected '*'")
inner_type = None
while self._lexer.peek().kind == 'ASTERISK':
self._lexer.pop()
qualifiers = self._parse_optional_type_qualifier_list()
type_name = PointerTypeName(type_name, qualifiers)
if inner_type is None:
inner_type = type_name
return type_name, inner_type