import { describe, expect, it } from "vitest";
import { parseMarkdownTable } from "./parse-markdown-table";

describe("parseMarkdownTable", () => {
  it("parses a table under the given heading", () => {
    const md = `## My Section

| Name | Value |
|------|-------|
| foo  | 1     |
| bar  | 2     |
`;
    const rows = parseMarkdownTable(md, "## My Section");
    expect(rows).toEqual([
      ["foo", "1"],
      ["bar", "2"],
    ]);
  });

  it("returns empty array when heading not found", () => {
    const md = `## Other

| A | B |
|---|---|
| x | y |
`;
    expect(parseMarkdownTable(md, "## Missing")).toEqual([]);
  });

  it("stops at the next heading", () => {
    const md = `## First

| A |
|---|
| x |

## Second

| B |
|---|
| y |
`;
    expect(parseMarkdownTable(md, "## First")).toEqual([["x"]]);
  });
});
