2025-07-07 20:58:02 -07:00
|
|
|
import { test } from "node:test";
|
2025-08-02 19:22:07 -07:00
|
|
|
import * as render from "./render.ts";
|
2025-07-07 20:58:02 -07:00
|
|
|
|
2025-08-02 19:22:07 -07:00
|
|
|
test("sanity", (t) => t.assert.equal(render.sync("gm <3").text, "gm <3"));
|
2025-07-07 20:58:02 -07:00
|
|
|
test("simple tree", (t) =>
|
|
|
|
t.assert.equal(
|
2025-08-02 19:22:07 -07:00
|
|
|
render.sync(
|
2025-07-07 20:58:02 -07:00
|
|
|
<main class={["a", "b"]}>
|
|
|
|
<h1 style="background-color:red">hello world</h1>
|
|
|
|
<p>haha</p>
|
2025-08-02 19:22:07 -07:00
|
|
|
{1}|{0}|{true}|{false}|{null}|{undefined}|
|
2025-07-07 20:58:02 -07:00
|
|
|
</main>,
|
|
|
|
).text,
|
|
|
|
'<main class="a b"><h1 style=background-color:red>hello world</h1><p>haha</p>1|0|||||</main>',
|
|
|
|
));
|
|
|
|
test("unescaped/escaped html", (t) =>
|
|
|
|
t.assert.equal(
|
2025-08-02 19:22:07 -07:00
|
|
|
render.sync(
|
|
|
|
<div>
|
|
|
|
{render.raw("<fuck>")}
|
|
|
|
{"\"&'`<>"}
|
|
|
|
</div>,
|
|
|
|
).text,
|
2025-07-07 20:58:02 -07:00
|
|
|
"<div><fuck>"&'`<></div>",
|
|
|
|
));
|
|
|
|
test("clsx built-in", (t) =>
|
|
|
|
t.assert.equal(
|
2025-08-02 19:22:07 -07:00
|
|
|
render.sync(
|
2025-07-07 20:58:02 -07:00
|
|
|
<>
|
|
|
|
<a class="a" />
|
|
|
|
<b class={null} />
|
|
|
|
<c class={undefined} />
|
|
|
|
<d class={["a", "b", null]} />
|
|
|
|
<e class={{ a: true, b: false }} />
|
|
|
|
<e
|
|
|
|
class={[null, "x", { z: true }, [{ m: true }, null, { v: false }]]}
|
|
|
|
/>
|
|
|
|
</>,
|
|
|
|
).text,
|
|
|
|
'<a class=a></a><b></b><c></c><d class="a b"></d><e class=a></e><e class="x z m"></e>',
|
|
|
|
));
|