import pytest from app.normalize.text import ( normalize, normalize_person, person_named_in, slugify, strip_accents, ) @pytest.mark.parametrize( ("raw", "expected"), [ ("Café Noir", "cafe noir"), ("naïve", "naive"), ("Łódź", "lodz"), ], ) def test_strip_accents_and_lower(raw: str, expected: str) -> None: assert normalize(raw) == expected def test_normalize_drops_leading_articles() -> None: assert normalize("The Big Lebowski") == "big lebowski" assert normalize("A Quick One") == "quick one" assert normalize("An Honest Take") == "honest take" def test_normalize_collapses_whitespace_and_punct() -> None: assert normalize("Hello, world!!!") == "hello world" assert normalize("foo--bar__baz") == "foo bar baz" def test_normalize_handles_none_and_empty() -> None: assert normalize(None) == "" assert normalize("") == "" assert normalize(" ") == "" def test_normalize_person_keeps_initials() -> None: # „Mia M." → „mia m" (kropka usunięta jako interpunkcja) assert normalize_person("Mia M.") == "mia m" assert normalize_person("Mia Malkova") == "mia malkova" def test_slugify_is_url_safe() -> None: assert slugify("Brazzers Network") == "brazzers-network" assert slugify("Mia Malkova") == "mia-malkova" assert slugify("") == "" def test_strip_accents_idempotent() -> None: once = strip_accents("naïve") twice = strip_accents(once) assert once == twice == "naive" @pytest.mark.parametrize( ("title", "person", "expected"), [ ("Savannah Bond Takes It All", "Savanna Bond", True), ("Jynx Maze Anal", "Jyn Maze", True), ("Julia Ann and Bridgette B", "Julia B.", False), ("Kim Gold Solo", "Goldy Kim", False), # Jednowyrazowe nazwisko: tylko co do znaku. „Thebdck" lapal kazde „the". ("Twins Sasha Paige Share the Dick ft. Martin Spell", "Thebdck", False), ("Twins Sasha Paige Share the Dick ft. Martin Spell", "Sashamalone", False), ("Twins Sasha Paige Share the Dick ft. Martin Spell", "Dickxy", False), ("Twins Sasha Paige Share the Dick ft. Martin Spell", "Sasha Paige", True), ("Mandingo Destroys Her", "Mandingo", True), # Zlepek sxyprn rowny sklejce sasiednich czlonow tytulu. ("Joanna Angel Rides Again", "JoannaAngel", True), ("Bonnie B Solo", "Bonnieb", True), ("Joanna Smith and Angel Dark", "JoannaAngel", False), ("Mandingos Best", "Mandingo", False), # Przedrostek z limitem dlugosci: wariant zapisu tak, doklejone slowo nie. ("Alexis Crystal Returns", "Alexis Crystalline", False), ("Sasha Grey Returns", "Sash Grey", True), ], ) def test_person_named_in(title: str, person: str, expected: bool) -> None: assert person_named_in(title, person) is expected