import unittest
import util
from postproc import postproc

from hutn_compiler.compiler import main

def compile_file(obj, filename):
    result = main(util.get_code_path(filename), "grammars/actionlanguage.g", "PS", [])
    expected = open(util.get_expected_path(filename)).read()
    print(result)
    result = postproc(result)
    expected = postproc(expected)
    if result != expected:
        #f = open(util.get_expected_path(filename), 'w')
        #f.write(result)
        #f.close()
        pass
    assert result == expected

class TestCompile(unittest.TestCase):
    def test_assign(self):
        compile_file(self, "assign.al")

    def test_vardecl(self):
        compile_file(self, "vardecl.al")

    def test_funccall(self):
        compile_file(self, "funccall.al")

    def test_ifelse(self):
        compile_file(self, "ifelse.al")

    def test_while(self):
        compile_file(self, "while.al")

    def test_funcdef_params(self):
        compile_file(self, "funcdef_params.al")

    def test_funccall_params(self):
        compile_file(self, "funccall_params.al")

    def test_action(self):
        compile_file(self, "action.al")

    def test_types(self):
        compile_file(self, "types.al")

    def test_mutual_recursion(self):
        compile_file(self, "mutual_recursion.al")

    def test_global(self):
        compile_file(self, "global.al")

    def test_include(self):
        compile_file(self, "include.al")

    def test_multi_include(self):
        compile_file(self, "multi_include.al")

    def test_dict_access(self):
        compile_file(self, "dict_access.al")

    def test_fibonacci(self):
        compile_file(self, "fibonacci.al")

    def test_fibonacci_smart(self):
        compile_file(self, "fibonacci_smart.al")

    def test_factorial(self):
        compile_file(self, "factorial.al")

