-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
30 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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("<h3>Hello world\n</h3>"); | ||
view({ name: "world" }).should.equal("<h3>\n\tHello world\n</h3>"); | ||
}); | ||
|
||
it("<% include %> will return an <error/> if not found", async () => { | ||
const view = await keikan.compilePath(import.meta.dirname + "/views/has-bad-include"); | ||
|
||
view().should.equal("<h3>\n\t<error>Include not found: notfound</error>\n</h3>"); | ||
}); | ||
|
||
it("<%= %>, <%- %> and <%# %>", async () => { | ||
const view = await keikan.compilePath(import.meta.dirname + "/views/escaping"); | ||
|
||
view().should.equal("<ul><li>This is a "quoted" string</li><li>This is not a \"quoted\" string</li><li></li></ul>"); | ||
view().should.equal("<ul>\n\t<li>This is a "quoted" string</li>\n\t<li>This is not a \"quoted\" string</li>\n\t<li></li>\n</ul>"); | ||
}); | ||
|
||
it("supports code like conditions, loops, ..", async () => { | ||
const view = await keikan.compilePath(import.meta.dirname + "/views/condition"); | ||
|
||
view({ condition: true }).should.equal("<h3>Hello\n</h3>"); | ||
view({ condition: false }).should.equal("<h3></h3>"); | ||
view({ condition: true }).should.equal("<h3>\n\tHello\n</h3>"); | ||
view({ condition: false }).should.equal("<h3>\n</h3>"); | ||
}); | ||
|
||
it("removes unnecessary whitespace", async () => { | ||
const view = await keikan.compilePath(import.meta.dirname + "/views/long"); | ||
|
||
view().should.equal("<h3><strong>Hello\n</strong></h3>"); | ||
view().should.equal("<h3>\n\t<strong>\n\t\tHello\n\t</strong>\n</h3>"); | ||
}); | ||
|
||
it("handles more complex views", async () => { | ||
const view = await keikan.compilePath(import.meta.dirname + "/views/complex"); | ||
|
||
view().should.equal("<ul>\n\t<li>(odd) 1. 1</li>\n\t<li>(even) 2. 2</li>\n\t<li>(odd) 3. 3</li>\n</ul>"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<ul> | ||
<% [ 1, 2, 3 ].map(i => { %> | ||
<% if (i % 2 == 0) { %> | ||
<li>(even) <%= i %>. <%- i %></li> | ||
<% } else { %> | ||
<li>(odd) <%= i %>. <%- i %></li> | ||
<% } %> | ||
<% }) %> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h3> | ||
<% include notfound({ name }) %> | ||
</h3> |