from unittest.mock import patch
from src.markdown_table import parse_tables, render_table, TableBlock

def test_render_table_sets_up_columns_before_rows():
 block = TableBlock(headers=["A", "B", "C"], rows=[["1", "2", "3"], ["4", "5", "6"]], span=(0, 4))
 with patch("src.markdown_table.imgui") as mock_imgui:
  mock_imgui.TableFlags_ = type("T", (), {"borders": 1, "row_bg": 2, "resizable": 4})()
  mock_imgui.TableColumnFlags_ = type("C", (), {"width_stretch": 1, "width_fixed": 2})()
  mock_imgui.begin_table.return_value = True
  render_table(block)
  assert mock_imgui.table_setup_column.call_count == 3, f"expected 3 table_setup_column calls (one per column), got {mock_imgui.table_setup_column.call_count}"
  assert mock_imgui.table_next_column.call_count == 6, f"expected exactly 6 table_next_column calls (cells only — headers come from table_headers_row, not from an explicit loop), got {mock_imgui.table_next_column.call_count}"
  assert mock_imgui.table_next_row.call_count == 2, f"expected 2 table_next_row calls (one per data row, not counting the header row), got {mock_imgui.table_next_row.call_count}"
