import unittest
import util

from hutn_compiler.compiler import main

def compile_file(obj, filename):
    try:
        result = main(util.get_code_path(filename), "grammars/actionlanguage.g", "S", [])
        if result:
            return False
        else:
            return True
    except:
        return True

class TestInvalidTypes(unittest.TestCase):
    def test_assign_invalid(self):
        self.assertTrue(compile_file(self, "assign_invalid.al"))

    def test_if_invalid(self):
        self.assertTrue(compile_file(self, "ifelse_invalid.al"))

    def test_while_invalid(self):
        self.assertTrue(compile_file(self, "while_invalid.al"))

    def test_return_invalid(self):
        self.assertTrue(compile_file(self, "return_invalid.al"))

    def test_return_invalid_void(self):
        self.assertTrue(compile_file(self, "return_invalid_void.al"))

    def test_funccall_invalid_void(self):
        self.assertTrue(compile_file(self, "funccall_invalid_void.al"))

    def test_funccall_invalid_params(self):
        self.assertTrue(compile_file(self, "funccall_invalid_params.al"))
