"""Tests for table extraction."""
from paper2md.types import Table
from paper2md.extractors.tables import table_to_pipe


def test_table_to_pipe():
    table = Table(cells=[
        ["Header 1", "Header 2"],
        ["Data 1", "Data 2"],
        ["Data 3", "Data 4"],
    ])
    result = table_to_pipe(table)
    lines = result.split("\n")
    assert len(lines) == 4
    assert lines[0].startswith("| Header 1")
    assert "---" in lines[1]
    assert "Data 1" in lines[2]


def test_table_to_pipe_ragged():
    table = Table(cells=[
        ["A", "B", "C"],
        ["1", "2"],
    ])
    result = table_to_pipe(table)
    lines = result.split("\n")
    assert len(lines) == 3
    # Second row should be padded
    assert lines[2].count("|") == lines[0].count("|")
