-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgostache_test.go
executable file
·51 lines (41 loc) · 1009 Bytes
/
gostache_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
package gostache
import (
"strings"
"testing"
)
type Person struct {
Name string
Age int
}
func TestRenderString(t *testing.T) {
p := Person{"Triny", 7}
result := RenderString("Name: {{Name}}\nAge: {{Age}}", p)
expected := "Name: Triny\nAge: 7"
if result != expected {
t.Error("RenderString did not pass.")
}
}
func TestRenderFile(t *testing.T) {
p := Person{"Triny", 7}
result := RenderFile("a", p)
expected := "Name: Triny\nAge: 7"
if !strings.Contains(result, expected) {
t.Error("RenderFile did not pass.")
}
}
func TestRenderFileWithPartial(t *testing.T) {
p := Person{"Triny", 7}
result := RenderFile("b", p)
expected := "Partial 7\n\nName: Triny\nAge: 7"
if !strings.Contains(result, expected) {
t.Error("RenderFile with a partial template did not pass.")
}
}
func TestHTMLEscape(t *testing.T) {
str := "\"'&<>"
result := HTMLEscape(str)
expected := ""'&<>"
if !strings.Contains(result, expected) {
t.Error("HTMLEscape did not pass.")
}
}