"""Pure unit tests for the stated-page parser (FC-6.2)."""

from backend.app.services.page_number_parser import parse_page_range


def test_explicit_ranges():
    assert parse_page_range("pages 9-12") == (9, 12)
    assert parse_page_range("pg 9–12") == (9, 12)        # en-dash
    assert parse_page_range("pp. 9 - 12") == (9, 12)
    assert parse_page_range("Chapter 2 (pages 1-4)") == (1, 4)


def test_reversed_range_is_normalized():
    assert parse_page_range("pages 12-9") == (9, 12)


def test_single_page():
    assert parse_page_range("Page 5") == (5, 5)
    assert parse_page_range("pg 5") == (5, 5)


def test_fraction_forms_take_the_numerator():
    assert parse_page_range("[3/8]") == (3, 3)
    assert parse_page_range("(3/8)") == (3, 3)
    assert parse_page_range("page 3 of 8") == (3, 3)
    assert parse_page_range("pg 3/8") == (3, 3)


def test_no_page_keyword_is_none():
    # Bare numbers / non-page words must not match (false positives are worse).
    assert parse_page_range("My Comic Part Three") is None
    assert parse_page_range("Episode 5") is None
    assert parse_page_range("Released 2024") is None
    assert parse_page_range("Part 3") is None


def test_empty_and_none():
    assert parse_page_range("") is None
    assert parse_page_range(None) is None
