from pathlib import Path from linkki_poster.models import Language from linkki_poster.scanner import scan_directory def write_file(path: Path, text: str = "x") -> None: path.write_text(text, encoding="utf-8") def test_global_prefix_first_family_wins(tmp_path: Path) -> None: write_file(tmp_path / "Kuva1.jpg") write_file(tmp_path / "Image1.jpg") write_file(tmp_path / "Suomi.md", "hello") result = scan_directory(tmp_path) assert [path.name for path in result.global_images] == ["Kuva1.jpg"] def test_numeric_suffix_rule_and_case_insensitive_matching(tmp_path: Path) -> None: write_file(tmp_path / "KuvaA.jpg") write_file(tmp_path / "Kuva2.jpg") write_file(tmp_path / "sUoMi.MD", "hello") write_file(tmp_path / "sUoMi10.PNG") write_file(tmp_path / "sUoMi2.jpg") result = scan_directory(tmp_path) assert [path.name for path in result.global_images] == ["Kuva2.jpg"] assert len(result.languages) == 1 assert result.languages[0].language == Language.FI assert [path.name for path in result.languages[0].images] == ["sUoMi2.jpg", "sUoMi10.PNG"] def test_natural_sort_and_text_precedence(tmp_path: Path) -> None: write_file(tmp_path / "English.md", "right") write_file(tmp_path / "english10.png") write_file(tmp_path / "english9.webp") write_file(tmp_path / "english9.jpg") write_file(tmp_path / "english.jpg") result = scan_directory(tmp_path) assert len(result.languages) == 1 assets = result.languages[0] assert assets.text_file.name == "English.md" assert [path.name for path in assets.images] == [ "english.jpg", "english9.jpg", "english9.webp", "english10.png", ] def test_empty_text_file_is_skipped_as_missing_language(tmp_path: Path) -> None: write_file(tmp_path / "Suomi.md", "Hei") write_file(tmp_path / "Svenska.md", " \n\t") write_file(tmp_path / "English.md", "") result = scan_directory(tmp_path) assert [assets.language for assets in result.languages] == [Language.FI]