Home
}\r\n}`; const formatted = formatWrn(source, options); expect(formatted.startsWith("// leading comment\n")).toBe(true); expect(formatted).toContain(""); expect(formatted.endsWith("\n")).toBe(true); expect(formatted).not.toContain("\r"); }); }); test("preserves preformatted code examples while formatting surrounding markup", () => { const source = `page Docs { view {// One project, one language
page ProductDashboard {
state count: number = 0
<button @click='count++'>Ship {count}</button>
}
// One project, one language
page ProductDashboard {
state count: number = 0`);
expect(formatWrn(formatted, options)).toBe(formatted);
expect(() => parse(formatted)).not.toThrow();
});
test("does not split an attribute-free opening tag delimiter", () => {
const source = `page Docs {
view {
This is intentionally long documentation copy that should wrap as content without formatting the opening p tag as separate less-than and greater-than lines.
}
}
`;
const formatted = formatWrn(source, options);
expect(formatted).toContain(" \n");
expect(formatted).not.toContain("
");
expect(formatWrn(formatted, options)).toBe(formatted);
});
test("preserves balanced compact sibling markup without indentation drift", () => {
const source = `page Compact {
view {
Page→API
}
}\n`;
const formatted = formatWrn(source, { tabSize: 2, printWidth: 80 });
expect(formatted).toContain('Page→API');
expect(formatWrn(formatted, { tabSize: 2, printWidth: 80 })).toBe(formatted);
});
test("formats large typed JSON prop defaults and remains idempotent", () => {
const source = `component Catalog {
props {
categories: unknown[] = [{"label":"Platform & Core","value":"platform","apps":[{"label":"WRNexus Home / Business Command Center","href":"/products/home","number":"01"},{"label":"SSO & Account","href":"/products/sso","number":"02"}]},{"label":"Sales & Customer","value":"sales","apps":[{"label":"CRM","href":"/products/crm","number":"11"}]}]
}
view { }
}`;
const formatted = formatWrn(source, options);
expect(formatted).toContain(`categories: unknown[] = [\n {\n "label": "Platform & Core"`);
expect(formatted).toContain(`"apps": [\n {`);
expect(formatWrn(formatted, options)).toBe(formatted);
expect(() => parse(formatted)).not.toThrow();
});