-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathcompile_test.go
83 lines (78 loc) · 2.35 KB
/
compile_test.go
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package ace
import (
"testing"
)
func TestLineCompile(t *testing.T) {
for i, this := range []struct {
template string
expect string
}{
{
template: `a href=./foo foo`,
expect: `<a href="./foo">foo</a>`,
},
{
template: `span.color-red red`,
expect: `<span class="color-red">red</span>`,
},
{
template: `span#ref1 text`,
expect: `<span id="ref1">text</span>`,
},
{
template: `span#ref1.color-red.text-big text`,
expect: `<span id="ref1" class="color-red text-big">text</span>`,
},
{
template: `span.color-red#ref1.text-big text`,
expect: `<span id="ref1" class="color-red text-big">text</span>`,
},
{
template: `#ref1 text`,
expect: `<div id="ref1">text</div>`,
},
{
template: `#ref1.color-red.text-big text`,
expect: `<div id="ref1" class="color-red text-big">text</div>`,
},
{
template: `.color-red#ref1.text-big text`,
expect: `<div id="ref1" class="color-red text-big">text</div>`,
},
{
template: "div class=\"dialog {{ if eq .Attr `important` }}color-red{{end}}\" text",
expect: "<div class=\"dialog {{if eq .Attr `important`}}color-red{{end}}\">text</div>",
},
{
template: "div class=\"dialog {{ if eq .Attr `important` }}color-red text-big{{end}}\" text",
expect: "<div class=\"dialog {{if eq .Attr `important`}}color-red text-big{{end}}\">text</div>",
},
{
template: "div class=\"dialog {{ if eq .Attr \"important\" }}color-red{{end}}\" text",
expect: "<div class=\"dialog {{if eq .Attr \"important\"}}color-red{{end}}\">text</div>",
},
{
template: "div class=\"dialog {{ if eq .Attr \"important\" }}color-red text-big{{end}}\" text",
expect: "<div class=\"dialog {{if eq .Attr \"important\"}}color-red text-big{{end}}\">text</div>",
},
} {
name, filepath := "dummy", "dummy.ace"
base := NewFile(filepath, []byte(this.template))
inner := NewFile("", []byte{})
src := NewSource(base, inner, []*File{})
rslt, err := ParseSource(src, nil)
if err != nil {
t.Errorf("[%d] failed: %s", i, err)
continue
}
tpl, err := CompileResult(name, rslt, nil)
if err != nil {
t.Errorf("[%d] failed: %s", i, err)
continue
}
compiled := tpl.Lookup(name).Tree.Root.String()
if compiled != this.expect {
t.Errorf("[%d] Compiler didn't return an expected value, got %v but expected %v", i, compiled, this.expect)
}
}
}