release: WRNexusJS 0.8.0
This commit is contained in:
1 parent
87507edf59
commit
586a6db8ff
625 files changed
+243608
-11210
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { formatWrn, parse } from "../src/index.ts";
|
||||
|
||||
const options = {
|
||||
insertSpaces: true,
|
||||
tabSize: 2,
|
||||
printWidth: 70,
|
||||
multilineAttributes: true,
|
||||
} as const;
|
||||
|
||||
describe("canonical WRN formatter", () => {
|
||||
test("formats declarations, structured values, markup, and imports idempotently", () => {
|
||||
const source = `import Card from "@/components/Card.wrn"
|
||||
component Demo {
|
||||
props { title: string = "Hello" items = [{ id: 1, label: "One" }] }
|
||||
view {
|
||||
<Card title='{title}' items='{items}' class="very-long-utility-name another-long-utility-name"><strong>{title}</strong></Card>
|
||||
}
|
||||
}`;
|
||||
const formatted = formatWrn(source, options);
|
||||
|
||||
expect(formatted).toContain('import Card from "@/components/Card.wrn"');
|
||||
expect(formatted).toContain('props {\n title: string = "Hello"');
|
||||
expect(formatted).toContain('items = [{ id: 1, label: "One" }]');
|
||||
expect(formatted).toContain("<Card\n");
|
||||
expect(formatWrn(formatted, options)).toBe(formatted);
|
||||
expect(() => parse(formatted)).not.toThrow();
|
||||
});
|
||||
|
||||
test("preserves comments and normalizes the final newline", () => {
|
||||
const source = `// leading comment\r\npage Home {\r\nview { <!-- keep --> <p>Home</p> }\r\n}`;
|
||||
const formatted = formatWrn(source, options);
|
||||
|
||||
expect(formatted.startsWith("// leading comment\n")).toBe(true);
|
||||
expect(formatted).toContain("<!-- keep -->");
|
||||
expect(formatted.endsWith("\n")).toBe(true);
|
||||
expect(formatted).not.toContain("\r");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user