"""Tests for direct lookup functions."""

from ars25.search.lookup import sanitize_section, _section_sort_key


def test_sanitize_valid():
    assert sanitize_section("25-403") == "25-403"
    assert sanitize_section("25-403.01") == "25-403.01"
    assert sanitize_section("25-101") == "25-101"


def test_sanitize_strips_prefix():
    assert sanitize_section("§ 25-403") == "25-403"
    assert sanitize_section("A.R.S. 25-403") == "25-403"
    assert sanitize_section("ARS 25-403") == "25-403"


def test_sanitize_rejects_injection():
    assert sanitize_section("25-403; DROP TABLE") is None
    assert sanitize_section("anything") is None
    assert sanitize_section("") is None
    assert sanitize_section("26-100") is None


def test_section_sort_key():
    assert _section_sort_key("25-101") == (101, 0)
    assert _section_sort_key("25-403.01") == (403, 1)
    assert _section_sort_key("25-403") < _section_sort_key("25-411")
