"""Tests for CSV parser."""

from ars25.ingestion.csv_parser import load_csv


def test_load_csv(sample_csv):
    records = load_csv(sample_csv)
    assert len(records) == 3


def test_csv_fields(sample_csv):
    records = load_csv(sample_csv)
    r = records[0]
    assert r.chapter_number == 1
    assert r.chapter_title == "MARRIAGE"
    assert r.article_number == 1
    assert r.section == "25-101"
    assert r.title == "Void and prohibited marriages"
    assert r.url.startswith("https://")


def test_csv_handles_quotes(sample_csv):
    records = load_csv(sample_csv)
    # The third record has a quoted chapter_title with commas
    r = records[2]
    assert r.section == "25-403"
    assert r.chapter_number == 4


def test_csv_empty_file(tmp_path):
    empty = tmp_path / "empty.csv"
    empty.write_text(
        "chapter_number,chapter_title,chapter_section_range,article_number,"
        "article_title,ars_section,ars_title,ars_url\n",
        encoding="utf-8",
    )
    records = load_csv(str(empty))
    assert records == []
