diff options
author | Simon Lindholm <simon.lindholm10@gmail.com> | 2019-03-06 14:52:00 +0100 |
---|---|---|
committer | Eli Bendersky <eliben@users.noreply.github.com> | 2019-03-06 05:52:00 -0800 |
commit | 992715f12aef69eb1351308f14fb5f1ff972ce57 (patch) | |
tree | 8528b62e2c635ae935022660af88851fd8a0027d /tests | |
parent | 139fc1ab7c9e6a6f310f5e7f723b6680cd029f6c (diff) | |
download | pycparser-992715f12aef69eb1351308f14fb5f1ff972ce57.tar.gz |
Fix crash when file starts with a semicolon (#310)
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test_c_parser.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/test_c_parser.py b/tests/test_c_parser.py index 34c1f1e..c09e04d 100755 --- a/tests/test_c_parser.py +++ b/tests/test_c_parser.py @@ -136,6 +136,15 @@ class TestCParser_fundamentals(TestCParser_base): ['Decl', 'foo', ['TypeDecl', ['IdentifierType', ['int']]]]) + def test_initial_semi(self): + t = self.parse(';') + self.assertEqual(len(t.ext), 0) + t = self.parse(';int foo;') + self.assertEqual(len(t.ext), 1) + self.assertEqual(expand_decl(t.ext[0]), + ['Decl', 'foo', + ['TypeDecl', ['IdentifierType', ['int']]]]) + def test_coords(self): """ Tests the "coordinates" of parsed elements - file name, line and column numbers, with modification @@ -828,6 +837,19 @@ class TestCParser_fundamentals(TestCParser_base): ['Decl', 'd', ['TypeDecl', ['IdentifierType', ['char']]]]]]]]) + def test_struct_with_initial_semi(self): + s1 = """ + struct { + ;int a; + } foo; + """ + s1_ast = self.parse(s1) + self.assertEqual(expand_decl(s1_ast.ext[0]), + ['Decl', 'foo', + ['TypeDecl', ['Struct', None, + [['Decl', 'a', + ['TypeDecl', ['IdentifierType', ['int']]]]]]]]) + def test_anonymous_struct_union(self): s1 = """ union |