diff options
-rw-r--r-- | pycparser/c_ast.py | 2 | ||||
-rwxr-xr-x | tests/test_c_parser.py | 18 |
2 files changed, 14 insertions, 6 deletions
diff --git a/pycparser/c_ast.py b/pycparser/c_ast.py index 66fadd9..b7bbbee 100644 --- a/pycparser/c_ast.py +++ b/pycparser/c_ast.py @@ -20,7 +20,7 @@ import sys def _repr(obj): """ - Get the representation of an object, with dedicated pprint-like format for lists and tuples. + Get the representation of an object, with dedicated pprint-like format for lists. """ if isinstance(obj, list): return '[' + (',\n '.join((_repr(e).replace('\n', '\n ') for e in obj))) + '\n]' diff --git a/tests/test_c_parser.py b/tests/test_c_parser.py index 35558cc..90df6c5 100755 --- a/tests/test_c_parser.py +++ b/tests/test_c_parser.py @@ -1010,10 +1010,10 @@ class TestCParser_fundamentals(TestCParser_base): def test_struct_empty(self): """ Tests that parsing an empty struct works. - + Empty structs do NOT follow C99 (See 6.2.5-20 of the C99 standard). - This is nevertheless supported by some compilers (clang, gcc), - especially when using FORTIFY code. + This is nevertheless supported by some compilers (clang, gcc), + especially when using FORTIFY code. Some compilers (visual) will fail to compile with an error. """ # an empty struct. This is NOT C99 compliant @@ -1022,10 +1022,18 @@ class TestCParser_fundamentals(TestCParser_base): """ parsed_struct = self.parse(s1).ext[0] + self.assertEqual(expand_decl(parsed_struct), + ['Decl', None, ['Struct', 'foo', []]]) + + s2 = """struct { } foo;""" + parsed_struct = self.parse(s2).ext[0] + self.assertEqual(expand_decl(parsed_struct), + ['Decl', 'foo', ['TypeDecl', ['Struct', None, []]]]) + s3 = """union { } foo;""" + parsed_struct = self.parse(s3).ext[0] self.assertEqual(expand_decl(parsed_struct), - ['Decl', None, ['Struct', 'foo', []]] - ) + ['Decl', 'foo', ['TypeDecl', ['Union', None, []]]]) def test_tags_namespace(self): """ Tests that the tags of structs/unions/enums reside in a separate namespace and |