from app.email_identity_extraction_service import _sanitize_company_mention, is_plausible_company_mention
from app.fiscal_enrichment_service import _company_name_matches_mention


def test_rejects_tld_and_domain_fragments_as_company_mentions():
    for value in ["pt", "com", "www", "sementenergias.pt", "http", "email"]:
        assert _sanitize_company_mention(value) == ""
        assert not is_plausible_company_mention(value)


def test_keeps_valid_portuguese_company_mentions():
    assert _sanitize_company_mention("SEMENTENERGIAS, UNIPESSOAL, LDA")
    assert is_plausible_company_mention("Dietimport S.A")


def test_short_mentions_do_not_match_inside_company_names():
    assert not _company_name_matches_mention("pt", "planetoption lda")
    assert not _company_name_matches_mention("pt", "sementenergias unipessoal lda")
    assert _company_name_matches_mention("sementenergias unipessoal lda", "sementenergias unipessoal lda")
    assert _company_name_matches_mention("dietimport s a", "dietimport s a")
