"use strict"; const assert = require("node:assert"); const { test } = require("node:test"); const { formatWrn } = require("../src/formatter"); test("formats compact props blocks with one prop per line", () => { const source = `component Header {\nprops { eyebrow = "" title = "" description = "" align = "start" class = "" }\nview {
{title}
}\n}\n`; const expected = `component Header {\n props {\n eyebrow = ""\n title = ""\n description = ""\n align = "start"\n class = ""\n }\n view {
{title}
}\n}\n`; assert.equal(formatWrn(source, { insertSpaces: true, tabSize: 2 }), expected); }); test("preserves nested prop defaults while formatting", () => { const source = `component Grid {\nprops { items = [{ label: "A" }, { label: "B" }] options = { gap: 4, dense: false } class = "" }\nview {
}\n}\n`; const formatted = formatWrn(source, { insertSpaces: true, tabSize: 2 }); assert.match(formatted, /items = \[\{ label: "A" \}, \{ label: "B" \}\]/); assert.match(formatted, /options = \{ gap: 4, dense: false \}/); assert.equal(formatWrn(formatted, { insertSpaces: true, tabSize: 2 }), formatted); }); test("formats public event declarations as individual props members", () => { const source = `component Search {\nprops { value = "" @event search = function @event clear = function }\nview { }\n}\n`; const formatted = formatWrn(source, { insertSpaces: true, tabSize: 2 }); assert.match(formatted, / {4}@event search = function/); assert.match(formatted, / {4}@event clear = function/); assert.equal(formatWrn(formatted, { insertSpaces: true, tabSize: 2 }), formatted); }); test("keeps long inline-closing tags idempotent after multiline expansion", () => { const source = `component Status { view {
Loading
} } `; const options = { insertSpaces: true, tabSize: 2, printWidth: 100 }; const formatted = formatWrn(source, options); assert.equal(formatWrn(formatted, options), formatted); assert.match(formatted, /<\/span>Loading/); }); test("formats inline elements with one attribute per line", () => { const source = `component Button { view { } } `; const expected = `component Button { view { } } `; const options = { insertSpaces: true, tabSize: 2, printWidth: 100, multilineAttributes: true, }; assert.equal(formatWrn(source, options), expected); assert.equal(formatWrn(expected, options), expected); }); test("formats self-closing component props", () => { const source = `component Demo { view { } } `; const formatted = formatWrn(source, { insertSpaces: true, tabSize: 2, printWidth: 100, multilineAttributes: true, }); assert.match(formatted, /$/m); }); test("indents if and each blocks", () => { const source = `page Demo { view { {#if open} {#each items as item} {item.label} {:empty}

Empty

{/each} {:else}

Closed

{/if} } } `; const formatted = formatWrn(source, { insertSpaces: true, tabSize: 2, multilineAttributes: true, }); assert.match(formatted, /^ {6}\{#each items as item\}$/m); assert.match(formatted, /^ {8}/m); assert.equal( formatWrn(formatted, { insertSpaces: true, tabSize: 2, multilineAttributes: true, }), formatted, ); }); test("expands inline if blocks around HTML", () => { const source = `component Button { view { } } `; const expected = `component Button { view { } } `; const options = { insertSpaces: true, tabSize: 2, printWidth: 100, multilineAttributes: true, }; assert.equal(formatWrn(source, options), expected); assert.equal(formatWrn(expected, options), expected); });