-
Notifications
You must be signed in to change notification settings - Fork 89
/
formatter_test.go
96 lines (86 loc) · 1.37 KB
/
formatter_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
84
85
86
87
88
89
90
91
92
93
94
95
96
package ace
import (
"bytes"
"io/ioutil"
"os"
"testing"
)
var innerTemplate string = `
= content inner
section
h1 hello
`
func TestFormatter(t *testing.T) {
inner, _ := ioutil.TempFile("", "inner")
inner.WriteString(innerTemplate)
inner.Close()
os.Rename(inner.Name(), inner.Name()+".ace")
defer os.Remove(inner.Name() + ".ace")
for i, this := range []struct {
template string
expect string
}{
{
template: `
a
span foo
`,
expect: `<a><span>foo</span></a>`,
},
{
template: `
div
span foo
`,
expect: `<div>
<span>foo</span>
</div>`,
},
{
template: `
section
div
{{if true}}
span foo
{{end}}
div text
`,
expect: `<section>
<div>
<span>foo</span>
</div>
<div>
text
</div>
</section>`,
},
{
template: `
body
= yield inner
`,
expect: `<body>
<section>
<h1>
hello
</h1>
</section>
</body>`,
},
} {
base, _ := ioutil.TempFile("", "base")
base.WriteString(this.template)
base.Close()
os.Rename(base.Name(), base.Name()+".ace")
defer os.Remove(base.Name() + ".ace")
tpl, _ := Load(base.Name(), inner.Name(), &Options{
Indent: " ",
})
buf := new(bytes.Buffer)
tpl.Execute(buf, map[string]string{})
compiled := buf.String()
if compiled != this.expect {
t.Errorf("[%d] Compiler didn't return an expected value, got %v but expected %v", i, compiled, this.expect)
}
}
}