import unittest
from parameterized import parameterized
from poc.util.fplutil import Utils
from poc.fplinterpreter import FplInterpreter
import os
import re

"""
Tests of FPL related (interpreter) errors.
Note: FPL parser is autogenerated through the TatSu package. Therefore, we do not test any FPL syntax errors.
"""


class TypeTests(unittest.TestCase):
    maxDiff = None
    path = None
    path_to_grammar = None
    path_to_usecases = None
    fpl_parser = None
    util = None

    @classmethod
    def setUpClass(cls):
        cls.path = os.path.normpath(os.path.abspath(__file__))
        if os.path.isfile(cls.path):
            cls.path = os.path.dirname(cls.path)
        cls.path_to_grammar = os.path.join(cls.path, "../../../grammar")
        cls.path_to_usecases = os.path.join(cls.path)
        cls.util = Utils()
        cls.fpl_parser = cls.util.get_parser(cls.path_to_grammar + "/fpl_tatsu_format.ebnf")

    @parameterized.expand([
        "test_Types_class_capsid",
        "test_Types_class_capsid_star",
        "test_Types_class_capsid_plus",
        "test_Types_class_obj",
        "test_Types_class_obj_star",
        "test_Types_class_obj_plus",
        "test_Types_class_objN_M",
        "test_Types_class_object",
    ])
    def test_possibilities(self, use_case):
        interpreter = FplInterpreter(self.fpl_parser)
        result = Utils.get_code_and_expected(self.path_to_usecases, use_case)
        interpreter.syntax_analysis(use_case, result[0])
        self.assertEqual(result[1].strip(), self.util.remove_object_references_from_string(
            interpreter.symbol_table_to_str().strip()))
