"""Tests for reference extraction."""
from paper2md.extractors.references import (
    parse_reference, is_references_heading, references_to_markdown,
)


def test_is_references_heading():
    assert is_references_heading("References")
    assert is_references_heading("  references  ")
    assert is_references_heading("Bibliography")
    assert not is_references_heading("Introduction")


def test_parse_numbered():
    ref = parse_reference("[1] Smith, J. and Doe, A. (2023). A great paper. Nature, 1:2-3.")
    assert ref.number == 1
    assert ref.year == "2023"
    assert "Smith" in ref.authors
    assert "great paper" in ref.title


def test_parse_author_year():
    ref = parse_reference("Smith, J. (2020). Title here. Journal of X, 5:10.")
    assert ref.year == "2020"
    assert "Smith" in ref.authors
    assert "Title here" in ref.title


def test_references_to_markdown():
    from paper2md.types import Reference
    refs = [
        Reference(raw="test", number=1, authors="Smith", year="2020", title="A Paper", venue="Nature"),
        Reference(raw="test2", number=2, authors="Doe", year="2021", title="B Paper"),
    ]
    md = references_to_markdown(refs)
    assert "[1]" in md
    assert "[2]" in md
    assert "*A Paper*" in md
