-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_test.cj
68 lines (64 loc) · 1.89 KB
/
parse_test.cj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package mustache
import std.unittest.*
import std.unittest.testmacro.*
import std.collection.ArrayList
class ParserTestItem {
ParserTestItem(let template: String, let expected: Array<Node>) {}
}
var parserTests = ArrayList<ParserTestItem>(
ParserTestItem(
"{{#foo}}\n\t{{#foo}}hello nested{{/foo}}{{/foo}}",
SectionNode(
"foo",
false,
ArrayList<Node>(
TextNode("\n\t"),
SectionNode("foo", false, ArrayList<Node>(TextNode("hello nested")))
)
),
),
ParserTestItem(
"\nfoo {{bar}} {{#alex}}\r\n\tbaz\n{{/alex}} {{!foo}}",
TextNode("\nfoo "),
VarNode("bar", true),
TextNode(" "),
SectionNode("alex", false, ArrayList<Node>(TextNode("\r\n\tbaz\n"),)),
TextNode(" "),
CommentNode("foo")
),
ParserTestItem(
"this will{{^foo}}not{{/foo}} be rendered",
TextNode("this will"),
SectionNode("foo", true, ArrayList<Node>(TextNode("not"))),
TextNode(" be rendered"),
),
ParserTestItem(
"{{#list}}({{.}}){{/list}}",
SectionNode("list", false, ArrayList<Node>(
TextNode("("),
VarNode(".", true),
TextNode(")"),
)),
)
)
@Test
class ParserTest {
@TestCase
func test() {
for (test in parserTests) {
println("Template: ${test.template}")
let parser = Parser(Lexer(test.template, "{{", "}}"))
let elems = parser.parse()
var i = 0
for (elem in elems) {
let pelem = test.expected[i]
println("expected: ${elem}")
println("got: ${pelem}")
if (elem.toString() != pelem.toString()) {
@Fail("elements are not equal ${elem} != ${pelem}")
}
i++
}
}
}
}