"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 large typed JSON prop defaults with the bundled formatter", () => { const source = `component Catalog { props { categories: unknown[] = [{"label":"Platform & Core","apps":[{"label":"Home","href":"/home"},{"label":"SSO","href":"/sso"}]},{"label":"Sales","apps":[{"label":"CRM","href":"/crm"}]}] } view {
} }`; const formatted = formatWrn(source, { insertSpaces: true, tabSize: 2, printWidth: 70 }); assert.match(formatted, /categories: unknown\[\] = \[\n \{/); assert.match(formatted, /"apps": \[\n \{/); assert.equal(formatWrn(formatted, { insertSpaces: true, tabSize: 2, printWidth: 70 }), formatted); }); test("formats native JSON state values with readable indentation", () => { const source = `component Footer { state footerItems = [{"label":"Accessibility","href":"/accessibility","value":"accessibility"},{"label":"Privacy","href":"/privacy","value":"privacy"}] view { } } `; const expected = `component Footer { state footerItems = [ { "label": "Accessibility", "href": "/accessibility", "value": "accessibility" }, { "label": "Privacy", "href": "/privacy", "value": "privacy" } ] view { } } `; const options = { insertSpaces: true, tabSize: 2 }; assert.equal(formatWrn(source, options), expected); assert.equal(formatWrn(expected, options), expected); }); test("formats direct structured component props and preserves expression props", () => { const source = `component Demo { view {