import { describe, expect, test } from "bun:test";
import { parse, type PropDecl } from "../src/parser.ts";

const compact = (source: string) =>
  parse(source).props.map(({ name, default: value }: PropDecl) => ({ name, value }));

describe("inline props", () => {
  test("parses multiple props declared on one line", () => {
    expect(
      compact(
        `component Example { props { eyebrow = "" title = "" description = "" align = "start" class = "" } view { <div></div> } }`,
      ),
    ).toEqual([
      { name: "eyebrow", value: '""' },
      { name: "title", value: '""' },
      { name: "description", value: '""' },
      { name: "align", value: '"start"' },
      { name: "class", value: '""' },
    ]);
  });

  test("preserves nested object and array defaults", () => {
    expect(
      compact(
        `component Example { props { items = [{ label: "A" }, { label: "B" }] options = { gap: 4, dense: false } class = "" } view { <div></div> } }`,
      ),
    ).toEqual([
      { name: "items", value: '[{ label: "A" }, { label: "B" }]' },
      { name: "options", value: "{ gap: 4, dense: false }" },
      { name: "class", value: '""' },
    ]);
  });
});
