"""Unit tests for the mutagen tag-parsing helpers — pure, no files."""

from app.infrastructure.metadata.tags import _first, _parse_track_number, _parse_year


def test_first_takes_head_of_list() -> None:
    assert _first(["Pink Floyd", "other"]) == "Pink Floyd"
    assert _first("Solo") == "Solo"
    assert _first([]) is None
    assert _first(None) is None
    assert _first(["  "]) is None  # whitespace-only → None


def test_parse_year_extracts_four_digits() -> None:
    assert _parse_year(["1979"]) == 1979
    assert _parse_year(["1979-01-02"]) == 1979
    assert _parse_year("2021-12") == 2021
    assert _parse_year(["no year"]) is None
    assert _parse_year(None) is None


def test_parse_track_number_handles_slash_form() -> None:
    assert _parse_track_number(["3/12"]) == 3
    assert _parse_track_number(["7"]) == 7
    assert _parse_track_number("1/10") == 1
    assert _parse_track_number(["A1"]) is None
    assert _parse_track_number(None) is None
