2024-07-30 23:24:17 +08:00
|
|
|
import { assertEquals } from "@std/assert";
|
2024-02-03 02:19:07 +08:00
|
|
|
import { parseTemplate } from "./template_parser.ts";
|
|
|
|
|
|
|
|
Deno.test("Test template", () => {
|
|
|
|
assertEquals(parseTemplate(`{{.}}`), ["Template", ["TemplateElement", [
|
|
|
|
"ExpressionDirective",
|
|
|
|
[
|
|
|
|
"Expression",
|
|
|
|
["TopLevelVal", "."],
|
|
|
|
],
|
|
|
|
]]]);
|
|
|
|
|
|
|
|
assertEquals(parseTemplate(`{{{page}}}`), ["Template", ["TemplateElement", [
|
|
|
|
"ExpressionDirective",
|
|
|
|
["Expression", ["QueryExpression", "{", ["Query", [
|
|
|
|
"TagIdentifier",
|
|
|
|
"page",
|
|
|
|
]], "}"]],
|
|
|
|
]]]);
|
|
|
|
|
2024-07-03 01:12:40 +08:00
|
|
|
assertEquals(parseTemplate(`{{escapeRegexp(@page.name)}}`), ["Template", [
|
2024-02-03 02:19:07 +08:00
|
|
|
"TemplateElement",
|
|
|
|
["ExpressionDirective", ["Expression", [
|
|
|
|
"Call",
|
|
|
|
["Identifier", "escapeRegexp"],
|
|
|
|
"(",
|
|
|
|
["Expression", [
|
|
|
|
"Attribute",
|
|
|
|
[
|
|
|
|
"Expression",
|
|
|
|
["GlobalIdentifier", "@page"],
|
|
|
|
],
|
|
|
|
".",
|
|
|
|
[
|
|
|
|
"Identifier",
|
|
|
|
"name",
|
|
|
|
],
|
|
|
|
]],
|
|
|
|
")",
|
|
|
|
]]],
|
|
|
|
]]);
|
|
|
|
|
|
|
|
const tree = parseTemplate(`
|
|
|
|
# My template
|
|
|
|
{{#each .}}
|
|
|
|
* Page: {{name}}
|
|
|
|
{{#if somethingComplicated(something)}}
|
|
|
|
Sup
|
|
|
|
{{else}}
|
|
|
|
Not sup
|
|
|
|
{{/if}}
|
|
|
|
{{/each}}
|
|
|
|
`);
|
|
|
|
|
|
|
|
console.log(JSON.stringify(tree, null, 2));
|
|
|
|
});
|