From 68c303c285032e2f0398352b70eb79736a72296f Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Wed, 4 Nov 2020 14:38:39 -0700 Subject: add ability to extract declarations from file --- tests/test_declarations.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/test_declarations.py (limited to 'tests') diff --git a/tests/test_declarations.py b/tests/test_declarations.py new file mode 100644 index 0000000..3fd6683 --- /dev/null +++ b/tests/test_declarations.py @@ -0,0 +1,38 @@ +import unittest + +from crowbar_reference_compiler import compile_to_ssa, load_declarations, parse_header, parse_implementation, scan + + +class TestDeclarationLoading(unittest.TestCase): + def test_kitchen_sink(self): + code = r""" +struct normal { + bool fake; +} + +opaque struct ope; + +enum sample { + Testing, +} + +union robust { + enum sample tag; + + switch (tag) { + case Testing: bool testPassed; + } +} + +fragile union not_robust { + int8 sample; + bool nope; +} +""" + tokens = scan(code) + parse_tree = parse_header(tokens) + decls = load_declarations(parse_tree) + self.assertListEqual(decls, ['struct normal', 'struct ope', 'enum sample', 'union robust', 'union not_robust']) + +if __name__ == '__main__': + unittest.main() -- cgit v1.2.3