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

import sys

import infra.split_vcards  # noqa: F401

mod = sys.modules["infra.split_vcards"]
split_vcards = mod.split_vcards

_TWO = (
    "BEGIN:VCARD\r\nVERSION:3.0\r\nFN:Ada Lovelace\r\nEND:VCARD\r\n"
    "BEGIN:VCARD\r\nVERSION:3.0\r\nFN:Alan Turing\r\nEND:VCARD\r\n"
)


def test_dos_vcards_devuelve_dos():
    cards = split_vcards(_TWO)
    assert len(cards) == 2


def test_vcard_unico():
    cards = split_vcards("BEGIN:VCARD\nFN:Solo\nEND:VCARD\n")
    assert len(cards) == 1
    assert "Solo" in cards[0]


def test_input_vacio_devuelve_lista_vacia():
    assert split_vcards("") == []
    assert split_vcards("ruido sin tarjetas") == []


def test_crlf_se_tolera():
    lf = _TWO.replace("\r\n", "\n")
    assert len(split_vcards(lf)) == 2


def test_cada_card_es_begin_end():
    for c in split_vcards(_TWO):
        assert c.startswith("BEGIN:VCARD")
        assert c.endswith("END:VCARD")
