import unittest
import util

from hutn_compiler.compiler import main
import json

def compile_file(obj, filename):
    result = main(util.get_code_path(filename), "grammars/modelling.g", "M", [])
    try:
        expected = json.loads(open(util.get_expected_path(filename)).read())
    except:
        #f = open(util.get_expected_path(filename), 'w')
        #f.write(json.dumps(result))
        #f.close()
        pass
    assert result == expected

class TestCompile(unittest.TestCase):
    def test_PetriNets(self):
        compile_file(self, "petrinets.mvc")

    def test_PetriNetsInstance(self):
        compile_file(self, "my_petrinet.mvc")

    def test_SimpleClassDiagrams(self):
        compile_file(self, "simpleclassdiagrams.mvc")

    def test_PetriNetsBoth(self):
        compile_file(self, "my_petrinet_with_MM.mvc")

    def test_PetriNets_constraints(self):
        compile_file(self, "petrinets_constraints.mvc")

