From 44f631c9a58af1a18ac6c06148f241892c9a33f1 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Wed, 3 Jun 2026 10:59:57 -0400 Subject: [PATCH] test(markdown): add GFM table parser failing tests --- src/markdown_table.py | 10 ++++++++++ tests/test_markdown_table.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/markdown_table.py create mode 100644 tests/test_markdown_table.py diff --git a/src/markdown_table.py b/src/markdown_table.py new file mode 100644 index 00000000..aa36ebc2 --- /dev/null +++ b/src/markdown_table.py @@ -0,0 +1,10 @@ +from dataclasses import dataclass + +@dataclass(frozen=True) +class TableBlock: + headers: list[str] + rows: list[list[str]] + span: tuple[int, int] + +def parse_tables(text: str) -> list[TableBlock]: + return [] diff --git a/tests/test_markdown_table.py b/tests/test_markdown_table.py new file mode 100644 index 00000000..183ff2a2 --- /dev/null +++ b/tests/test_markdown_table.py @@ -0,0 +1,28 @@ +from src.markdown_table import parse_tables + +def test_parses_simple_two_column_table(): + text = ( + "| Name | Type |\n" + "|-------|------|\n" + "| foo | int |\n" + "| bar | str |\n" + ) + blocks = parse_tables(text) + assert len(blocks) == 1 + block = blocks[0] + assert block.headers == ["Name", "Type"] + assert block.rows == [["foo", "int"], ["bar", "str"]] + +def test_ignores_tables_inside_code_fence(): + text = ( + "```\n" + "| not | a table |\n" + "| --- | ------- |\n" + "| x | y |\n" + "```\n" + ) + assert parse_tables(text) == [] + +def test_returns_empty_for_plain_markdown(): + text = "# Heading\n\nSome **bold** text.\n" + assert parse_tables(text) == []