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_basic_types(self):
self.assertEqual(parse_type_name('char'), BasicTypeName('char'))
self.assertEqual(parse_type_name('int'), BasicTypeName('int'))
self.assertEqual(parse_type_name('float'), BasicTypeName('float'))
self.assertEqual(parse_type_name('double'), BasicTypeName('double'))
self.assertEqual(parse_type_name('_Bool'), BasicTypeName('_Bool'))
def test_size(self):
self.assertEqual(parse_type_name('long int'), BasicTypeName('long'))
self.assertEqual(parse_type_name('long'), BasicTypeName('long'))
self.assertEqual(parse_type_name('int long'), BasicTypeName('long'))
self.assertEqual(parse_type_name('long long int'),
BasicTypeName('long long'))
self.assertEqual(parse_type_name('long long'),
BasicTypeName('long long'))
self.assertEqual(parse_type_name('int long long'),
BasicTypeName('long long'))
self.assertEqual(parse_type_name('long int long'),
BasicTypeName('long long'))
self.assertEqual(parse_type_name('short int'), BasicTypeName('short'))
self.assertEqual(parse_type_name('short'), BasicTypeName('short'))
self.assertEqual(parse_type_name('int short'), BasicTypeName('short'))
self.assertEqual(parse_type_name('long double'),
BasicTypeName('long double'))
self.assertEqual(parse_type_name('double long'),
BasicTypeName('long double'))
self.assertRaises(ValueError, parse_type_name, 'short long int')
self.assertRaises(ValueError, parse_type_name, 'long long long int')
self.assertRaises(ValueError, parse_type_name, 'short double')
self.assertRaises(ValueError, parse_type_name, 'double short')
self.assertRaises(ValueError, parse_type_name, 'long long double')
self.assertRaises(ValueError, parse_type_name, 'long double long')
self.assertRaises(ValueError, parse_type_name, 'double long long')
self.assertRaises(ValueError, parse_type_name, 'long char')
self.assertRaises(ValueError, parse_type_name, 'char long')
def test_basic_types(self):
self.assertEqual(parse_type_name('char'), BasicTypeName('char'))
self.assertEqual(parse_type_name('int'), BasicTypeName('int'))
self.assertEqual(parse_type_name('float'), BasicTypeName('float'))
self.assertEqual(parse_type_name('double'), BasicTypeName('double'))
self.assertEqual(parse_type_name('_Bool'), BasicTypeName('_Bool'))
def test_sign(self):
self.assertEqual(parse_type_name('signed int'), BasicTypeName('int'))
self.assertEqual(parse_type_name('signed'), BasicTypeName('int'))
self.assertEqual(parse_type_name('int signed'), BasicTypeName('int'))
self.assertEqual(parse_type_name('unsigned'),
BasicTypeName('unsigned int'))
self.assertEqual(parse_type_name('unsigned int'),
BasicTypeName('unsigned int'))
self.assertEqual(parse_type_name('unsigned'),
BasicTypeName('unsigned int'))
self.assertEqual(parse_type_name('int unsigned'),
BasicTypeName('unsigned int'))
self.assertEqual(parse_type_name('signed char'),
BasicTypeName('signed char'))
self.assertEqual(parse_type_name('char signed'),
BasicTypeName('signed char'))
self.assertEqual(parse_type_name('unsigned char'),
BasicTypeName('unsigned char'))
self.assertEqual(parse_type_name('char unsigned'),
BasicTypeName('unsigned char'))
def test_size(self):
self.assertEqual(parse_type_name('long int'), BasicTypeName('long'))
self.assertEqual(parse_type_name('long'), BasicTypeName('long'))
self.assertEqual(parse_type_name('int long'), BasicTypeName('long'))
self.assertEqual(parse_type_name('long long int'),
BasicTypeName('long long'))
self.assertEqual(parse_type_name('long long'),
BasicTypeName('long long'))
self.assertEqual(parse_type_name('int long long'),
BasicTypeName('long long'))
self.assertEqual(parse_type_name('long int long'),
BasicTypeName('long long'))
self.assertEqual(parse_type_name('short int'), BasicTypeName('short'))
self.assertEqual(parse_type_name('short'), BasicTypeName('short'))
self.assertEqual(parse_type_name('int short'), BasicTypeName('short'))
self.assertEqual(parse_type_name('long double'),
BasicTypeName('long double'))
self.assertEqual(parse_type_name('double long'),
BasicTypeName('long double'))
self.assertRaises(ValueError, parse_type_name, 'short long int')
def test_tagged_type(self):
self.assertEqual(parse_type_name('struct point'),
StructTypeName('point'))
self.assertEqual(parse_type_name('union value'),
UnionTypeName('value'))
self.assertEqual(parse_type_name('enum color'), EnumTypeName('color'))
def test_sign(self):
self.assertEqual(parse_type_name('signed int'), BasicTypeName('int'))
self.assertEqual(parse_type_name('signed'), BasicTypeName('int'))
self.assertEqual(parse_type_name('int signed'), BasicTypeName('int'))
self.assertEqual(parse_type_name('unsigned'),
BasicTypeName('unsigned int'))
self.assertEqual(parse_type_name('unsigned int'),
BasicTypeName('unsigned int'))
self.assertEqual(parse_type_name('unsigned'),
BasicTypeName('unsigned int'))
self.assertEqual(parse_type_name('int unsigned'),
BasicTypeName('unsigned int'))
self.assertEqual(parse_type_name('signed char'),
BasicTypeName('signed char'))
self.assertEqual(parse_type_name('char signed'),
BasicTypeName('signed char'))
self.assertEqual(parse_type_name('unsigned char'),
BasicTypeName('unsigned char'))
self.assertEqual(parse_type_name('char unsigned'),
def test_array_of_pointers(self):
self.assertEqual(parse_type_name('int *[2][3]'),
ArrayTypeName(ArrayTypeName(PointerTypeName(BasicTypeName('int')), 3), 2))
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'})))
self.assertEqual(parse_type_name('unsigned'),
BasicTypeName('unsigned int'))
self.assertEqual(parse_type_name('unsigned int'),
BasicTypeName('unsigned int'))
self.assertEqual(parse_type_name('unsigned'),
BasicTypeName('unsigned int'))
self.assertEqual(parse_type_name('int unsigned'),
BasicTypeName('unsigned int'))
self.assertEqual(parse_type_name('signed char'),
BasicTypeName('signed char'))
self.assertEqual(parse_type_name('char signed'),
BasicTypeName('signed char'))
self.assertEqual(parse_type_name('unsigned char'),
BasicTypeName('unsigned char'))
self.assertEqual(parse_type_name('char unsigned'),
BasicTypeName('unsigned char'))
self.assertRaises(ValueError, parse_type_name, 'signed unsigned int')
self.assertRaises(ValueError, parse_type_name, 'signed _Bool')
self.assertRaises(ValueError, parse_type_name, '_Bool signed')