from clarabot_nano.indexer.language import LanguageDetector


def test_indexer_language():
    en_short = "Go there"
    en_long = "I can't take this anymore, put that cookie down"
    hu_short = "Menj oda"
    hu_long = "Ezt nem bírom tovább, tedd le azt a sütit"
    ru_short = "Иди туда"
    ru_short_latn = "Idi tuda"
    ru_long = "Я больше не могу этого выносить, отложи это печенье"
    ru_long_latn = "YA bol'she ne mogu etogo vynosit', otlozhi eto pechen'ye"
    zh_short_simp = "去那边"
    zh_long_simp = "我不能这样继续下去了，把那个饼干降"
    zh_short_trad = "去那邊"
    zh_long_trad = "我不能這樣繼續下去了，把那個餅乾降"
    for kwargs, tests in [
        (
            {"allow_guess": True},
            [
                (en_short, None),
                (en_long, "en"),
                (hu_short, None),
                (hu_long, "hu"),
                (ru_short, None),
                (ru_long, "ru"),
                (ru_short_latn, None),
                (ru_long_latn, None),
                (zh_short_simp, None),
                (zh_long_simp, "zh"),
                (zh_short_trad, None),
                (zh_long_trad, "zh"),
            ],
        ),
        (
            {"allow_guess": False},
            [
                (en_short, None),
                (en_long, "en"),
                (hu_short, None),
                (hu_long, "hu"),
                (ru_short, None),
                (ru_long, "ru"),
                (ru_short_latn, None),
                (ru_long_latn, None),
                (zh_short_simp, None),
                (zh_long_simp, "zh"),
                (zh_short_trad, None),
                (zh_long_trad, "zh"),
            ],
        ),
    ]:
        ld = LanguageDetector(**kwargs)
        for text, result in tests:
            assert ld.get_primary_language(text) == result, f"{kwargs}: {text} -> {result}"
