import pytest
from app.parsers.markdown_parser import MarkdownParser


@pytest.fixture
def parser():
    return MarkdownParser()


def test_parse_intro_and_headings(parser):
    content = "Preamble text.\n\n# Overview\nSome overview.\n\n## Details\nMore details."
    sections = parser.parse_sections(content)
    assert sections[0] == ("Introduction", 0, "Preamble text.")
    assert sections[1][0] == "Overview"
    assert sections[1][1] == 1
    assert sections[2][0] == "Details"
    assert sections[2][1] == 2


def test_parse_no_headings(parser):
    content = "Just plain text with no headings."
    sections = parser.parse_sections(content)
    assert len(sections) == 1
    assert sections[0][0] == "Introduction"


def test_parse_empty(parser):
    sections = parser.parse_sections("")
    assert sections == []


def test_parse_heading_only(parser):
    content = "# Title\n"
    sections = parser.parse_sections(content)
    assert sections[0][0] == "Title"
    assert sections[0][2] == ""
