def run(filename):
    fp = os.open(filename, os.O_RDONLY, 0o777)
    source = ""
    while True:
        data = os.read(fp, 4096)
        if len(data) == 0:
            break

        source += data
    os.close(fp)

    c = Cursor(filename)
    p = Parser()

    found, node = p.type_definition(source, c)
    if not found:
        print("Unable to parse '%s'" % filename)
        return

    scope = typeinfo.new_scope()
    udt = typeinfo.UserDefinedType(node)
    if udt.check(scope):
        print("Program type checks.")
    else:
        print("Program failed type checking.")
    def test_type_definition(self):
        c = Cursor("test_data")
        p = Parser()
        data = "type SomeType Int"
        found, node = p.type_definition(data, c)

        self.assertTrue(found)
        self.assertEqual("SomeType", node.alias_name)
        self.assertEqual("Int", node.type_name)
    def test_adt_type_definition(self):
        c = Cursor("test_data")
        p = Parser()
        data = "type SomeType:\n" "  I Int\n" "  S String\n"

        found, node = p.type_definition(data, c)
        self.assertTrue(found)

        scope = typeinfo.new_scope()
        udt = typeinfo.UserDefinedType(node)
        self.assertTrue(udt.check(scope))
    def test_function_signature(self):
        c = Cursor("test_data")
        p = Parser()
        data = "do_something :: Int String = Float"
        found, node = p.function_signature(data, c)

        self.assertTrue(found)
        self.assertIsNotNone(node)

        self.assertEqual("do_something", node.name)
        self.assertEqual(2, len(node.inputs))
        self.assertEqual(1, len(node.outputs))
    def test_adt_type_definition(self):
        c = Cursor("test_data")
        p = Parser()
        data = "type SomeType:\n" \
               "  I Int\n" \
               "  F Float\n" \
               "  S String\n"

        found, node = p.type_definition(data, c)
        self.assertTrue(found)
        self.assertEqual(3, len(node.members))