aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2020-11-04 14:38:39 -0700
committerMelody Horn <melody@boringcactus.com>2020-11-04 14:38:39 -0700
commit68c303c285032e2f0398352b70eb79736a72296f (patch)
tree8d283c7c12b4db0570073423cdfe0e5a2fba336e /tests
parentab58859a49b819954fddd00d6364c56ca4dc651a (diff)
downloadreference-compiler-68c303c285032e2f0398352b70eb79736a72296f.tar.gz
reference-compiler-68c303c285032e2f0398352b70eb79736a72296f.zip
add ability to extract declarations from file
Diffstat (limited to 'tests')
-rw-r--r--tests/test_declarations.py38
1 files changed, 38 insertions, 0 deletions
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()