diff --git a/test/Features.js b/test/Features.js
index 6a37e49..bd811af 100644
--- a/test/Features.js
+++ b/test/Features.js
@@ -1,31 +1,43 @@
import { Renderer } from "../index.js"
import should from "should"
-const keikan = new Renderer();
+const keikan = new Renderer({ debug: true });
describe("Features", () => {
it("<% include %> can be used to load another view", async () => {
const view = await keikan.compilePath(import.meta.dirname + "/views/has-include");
- view({ name: "world" }).should.equal("
Hello world\n
");
+ view({ name: "world" }).should.equal("\n\tHello world\n
");
+ });
+
+ it("<% include %> will return an if not found", async () => {
+ const view = await keikan.compilePath(import.meta.dirname + "/views/has-bad-include");
+
+ view().should.equal("\n\tInclude not found: notfound\n
");
});
it("<%= %>, <%- %> and <%# %>", async () => {
const view = await keikan.compilePath(import.meta.dirname + "/views/escaping");
- view().should.equal("- This is a "quoted" string
- This is not a \"quoted\" string
");
+ view().should.equal("\n\t- This is a "quoted" string
\n\t- This is not a \"quoted\" string
\n\t\n
");
});
it("supports code like conditions, loops, ..", async () => {
const view = await keikan.compilePath(import.meta.dirname + "/views/condition");
- view({ condition: true }).should.equal("Hello\n
");
- view({ condition: false }).should.equal("");
+ view({ condition: true }).should.equal("\n\tHello\n
");
+ view({ condition: false }).should.equal("\n
");
});
it("removes unnecessary whitespace", async () => {
const view = await keikan.compilePath(import.meta.dirname + "/views/long");
- view().should.equal("Hello\n
");
+ view().should.equal("\n\t\n\t\tHello\n\t\n
");
+ });
+
+ it("handles more complex views", async () => {
+ const view = await keikan.compilePath(import.meta.dirname + "/views/complex");
+
+ view().should.equal("\n\t- (odd) 1. 1
\n\t- (even) 2. 2
\n\t- (odd) 3. 3
\n
");
});
});
diff --git a/test/views/complex.html b/test/views/complex.html
new file mode 100644
index 0000000..9853ed4
--- /dev/null
+++ b/test/views/complex.html
@@ -0,0 +1,9 @@
+
+<% [ 1, 2, 3 ].map(i => { %>
+ <% if (i % 2 == 0) { %>
+ - (even) <%= i %>. <%- i %>
+ <% } else { %>
+ - (odd) <%= i %>. <%- i %>
+ <% } %>
+<% }) %>
+
diff --git a/test/views/has-bad-include.html b/test/views/has-bad-include.html
new file mode 100644
index 0000000..801589c
--- /dev/null
+++ b/test/views/has-bad-include.html
@@ -0,0 +1,3 @@
+
+ <% include notfound({ name }) %>
+