From aa8d8ba55bfd302707e7c84ab50fc7a7caa4d6b1 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Sat, 24 Oct 2020 23:42:04 -0600 Subject: compile "hello, world" at least --- tests/test_hello_world.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/test_hello_world.py (limited to 'tests') 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() -- cgit v1.2.3