"""Tests para extract_or_make_uid. Puros, deterministas, sin I/O."""

import sys

import infra.extract_or_make_uid  # noqa: F401

mod = sys.modules["infra.extract_or_make_uid"]
extract = mod.extract_or_make_uid


def test_uid_presente_se_extrae():
    txt = "BEGIN:VEVENT\r\nUID:abc-123@google.com\r\nSUMMARY:x\r\nEND:VEVENT"
    assert extract(txt) == "abc-123@google.com"


def test_sin_uid_genera_determinista():
    txt = "BEGIN:VCARD\r\nFN:Ada\r\nEND:VCARD"
    uid = extract(txt)
    assert uid.startswith("goog-")
    assert len(uid) == len("goog-") + 16


def test_mismo_texto_mismo_uid_sintetico():
    txt = "BEGIN:VCARD\r\nFN:Ada\r\nEND:VCARD"
    assert extract(txt) == extract(txt)


def test_prefix_personalizado():
    txt = "BEGIN:VCARD\r\nFN:Ada\r\nEND:VCARD"
    uid = extract(txt, prefix="mig-")
    assert uid.startswith("mig-")


def test_uid_con_espacios_se_stripea():
    txt = "BEGIN:VCARD\nUID:  spaced-uid  \nEND:VCARD"
    assert extract(txt) == "spaced-uid"
