import unittest
try:
    import util #needed for Python2
except ImportError:
    import test.modelling_language.util as 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())
        assert result == expected
    except:
        #f = open(util.get_expected_path(filename), 'w')
        #f.write(json.dumps(result))
        #f.close()
        assert False

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_PetriNets_constraints(self):
        compile_file(self, "petrinets_constraints.mvc")

    def test_multiline(self):
        compile_file(self, "multiline.mvc")
