aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_hello_world.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/test_hello_world.py b/tests/test_hello_world.py
new file mode 100644
index 0000000..ec1ccdd
--- /dev/null
+++ b/tests/test_hello_world.py
@@ -0,0 +1,32 @@
+import unittest
+
+from crowbar_reference_compiler import compile_to_ssa, parse_header, parse_implementation, scan
+
+
+class TestHelloWorld(unittest.TestCase):
+ def test_ssa(self):
+ code = r"""
+include "stdio.hro";
+
+int main() {
+ printf("Hello, world!\n");
+ return 0;
+}
+"""
+ tokens = scan(code)
+ parse_tree = parse_implementation(tokens)
+ actual_ssa = compile_to_ssa(parse_tree)
+ expected_ssa = r"""
+data $data0 = { b "Hello, world!\n", b 0 }
+
+export function w $main() {
+@start
+ call $printf(l $data0, ...)
+ ret 0
+}
+""".strip()
+ self.assertEqual(expected_ssa, actual_ssa)
+
+
+if __name__ == '__main__':
+ unittest.main()