aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2020-11-04 19:24:09 -0700
committerMelody Horn <melody@boringcactus.com>2020-11-04 19:24:09 -0700
commit35979953a534bcdb2185de0a934e7937f319d687 (patch)
treebe860937aae0aa46c486222e77d1e6db61d58206 /tests
parenteaf789901101b8958c2555a0af300d7471707fea (diff)
downloadreference-compiler-35979953a534bcdb2185de0a934e7937f319d687.tar.gz
reference-compiler-35979953a534bcdb2185de0a934e7937f319d687.zip
switch from specific declarations to generic AST
Diffstat (limited to 'tests')
-rw-r--r--tests/test_ast.py54
-rw-r--r--tests/test_declarations.py53
2 files changed, 54 insertions, 53 deletions
diff --git a/tests/test_ast.py b/tests/test_ast.py
new file mode 100644
index 0000000..b2c592d
--- /dev/null
+++ b/tests/test_ast.py
@@ -0,0 +1,54 @@
+import unittest
+
+from crowbar_reference_compiler import build_ast, parse_header, scan
+from crowbar_reference_compiler.ast import ArrayType, BasicType, ConstantExpression, EnumDeclaration, HeaderFile, \
+ PointerType, StructDeclaration, UnionDeclaration, VariableDeclaration, VariableExpression
+
+
+class TestAST(unittest.TestCase):
+ def test_kitchen_sink(self):
+ code = r"""
+struct normal {
+ bool fake;
+ (uint8[3])* data;
+}
+
+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 = build_ast(parse_tree, [])
+ normal = StructDeclaration('normal', [
+ VariableDeclaration('fake', BasicType('bool')),
+ VariableDeclaration('data', PointerType(ArrayType(BasicType('uint8'), ConstantExpression('3')))),
+ ])
+ ope = StructDeclaration('ope', None)
+ sample = EnumDeclaration('sample', [('Testing', None)])
+ robust = UnionDeclaration('robust', VariableDeclaration('tag', BasicType('enum sample')),
+ [(VariableExpression('Testing'), VariableDeclaration('testPassed', BasicType('bool')))])
+ not_robust = UnionDeclaration('not_robust', None, [
+ VariableDeclaration('sample', BasicType('int8')),
+ VariableDeclaration('nope', BasicType('bool')),
+ ])
+ self.assertEqual(decls, HeaderFile([], [normal, ope, sample, robust, not_robust]))
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tests/test_declarations.py b/tests/test_declarations.py
deleted file mode 100644
index 9eaf488..0000000
--- a/tests/test_declarations.py
+++ /dev/null
@@ -1,53 +0,0 @@
-import unittest
-
-from crowbar_reference_compiler import compile_to_ssa, load_declarations, parse_header, parse_implementation, scan
-from crowbar_reference_compiler.declarations import ArrayType, BasicType, EnumDeclaration, PointerType, \
- StructDeclaration, UnionDeclaration, VariableDeclaration
-
-
-class TestDeclarationLoading(unittest.TestCase):
- def test_kitchen_sink(self):
- code = r"""
-struct normal {
- bool fake;
- (uint8[3])* data;
-}
-
-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, [])
- normal = StructDeclaration('normal', [
- VariableDeclaration('fake', BasicType('bool'), None),
- VariableDeclaration('data', PointerType(ArrayType(BasicType('uint8'), 3)), None),
- ])
- ope = StructDeclaration('ope', None)
- sample = EnumDeclaration('sample', [('Testing', None)])
- robust = UnionDeclaration('robust', VariableDeclaration('tag', BasicType('enum sample'), None),
- [('Testing', VariableDeclaration('testPassed', BasicType('bool'), None))])
- not_robust = UnionDeclaration('not_robust', None,
- [VariableDeclaration('sample', BasicType('int8'), None),
- VariableDeclaration('nope', BasicType('bool'), None)])
- self.assertListEqual(decls, [normal, ope, sample, robust, not_robust])
-
-
-if __name__ == '__main__':
- unittest.main()