aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2020-10-24 23:42:04 -0600
committerMelody Horn <melody@boringcactus.com>2020-10-24 23:42:04 -0600
commitaa8d8ba55bfd302707e7c84ab50fc7a7caa4d6b1 (patch)
treefdaaf7c808e7fbc10daac479410667b74c847a09 /tests
parent87ef87fb8074e27c91f44b39f5584fe5d1e341a9 (diff)
downloadreference-compiler-aa8d8ba55bfd302707e7c84ab50fc7a7caa4d6b1.tar.gz
reference-compiler-aa8d8ba55bfd302707e7c84ab50fc7a7caa4d6b1.zip
compile "hello, world" at least
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()