from __future__ import annotations

from pathlib import Path
import sys
import unittest


SRC_ROOT = Path(__file__).resolve().parents[2] / "src"

if str(SRC_ROOT) not in sys.path:
    sys.path.insert(0, str(SRC_ROOT))


from ffx.iso_language import IsoLanguage  # noqa: E402


class IsoLanguageTests(unittest.TestCase):
    def test_language_constant_set_covers_iso_639_1_plus_filipino_alias(self):
        languages = [language for language in IsoLanguage if language is not IsoLanguage.UNDEFINED]

        self.assertEqual(184, len(languages))
        self.assertEqual(183, len({language.twoLetter() for language in languages}))

    def test_primary_three_letter_code_is_returned_first(self):
        self.assertEqual("sqi", IsoLanguage.ALBANIAN.threeLetter())
        self.assertEqual("deu", IsoLanguage.GERMAN.threeLetter())
        self.assertEqual("cym", IsoLanguage.WELSH.threeLetter())

    def test_secondary_three_letter_codes_still_resolve_to_the_same_language(self):
        self.assertIs(IsoLanguage.ALBANIAN, IsoLanguage.findThreeLetter("alb"))
        self.assertIs(IsoLanguage.GERMAN, IsoLanguage.findThreeLetter("ger"))
        self.assertIs(IsoLanguage.WELSH, IsoLanguage.findThreeLetter("wel"))

    def test_newly_added_languages_and_media_aliases_resolve(self):
        self.assertIs(IsoLanguage.ASSAMESE, IsoLanguage.find("Assamese"))
        self.assertIs(IsoLanguage.YORUBA, IsoLanguage.findThreeLetter("yor"))
        self.assertIs(IsoLanguage.FILIPINO, IsoLanguage.findThreeLetter("fil"))


if __name__ == "__main__":
    unittest.main()
