-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtemplate_test.go
More file actions
45 lines (43 loc) · 1.43 KB
/
template_test.go
File metadata and controls
45 lines (43 loc) · 1.43 KB
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
package config
import "testing"
func TestTemplate(t *testing.T) {
type args struct {
t Template
str TemplateString
}
for _, tt := range []struct {
name string
args args
want string
}{
{"test#1",
args{
Template{"Damage": 10000, "Name": "Test", "Level": 1},
`<p>Damage: {{ printf "%d" .Damage | color "red" }}, {{ "Name" | italic }}: {{ printf "%q" .Name | bold }}, Level: {{ printf "%d" .Level }}, Reason: {{ default .Reason "unknown" }}</p>`,
},
`<p>Damage: <span style="color: red;">10,000</span>, <i>Name</i>: <b>"Test"</b>, Level: 1, Reason: unknown</p>`},
{"test#2",
args{
Template{"Damage": 10000, "Name": "Test", "Level": 1, "Reason": "test"},
`<p>Damage: {{ printf "%d" .Damage | color "red" }}, {{ "Name" | italic }}: {{ printf "%q" .Name | bold }}, Level: {{ printf "%d" .Level }}, Reason: {{ default .Reason "unknown" }}</p>`,
},
`<p>Damage: <span style="color: red;">10,000</span>, <i>Name</i>: <b>"Test"</b>, Level: 1, Reason: test</p>`},
{"test#3",
args{
Template{"Damage": 100},
`Your damage is
{{ if gt (int .Damage) 1000 -}}
pretty big
{{- else -}}
small
{{- end }}
comparing to the average damage.`,
}, `Your damage is small comparing to the average damage.`},
} {
t.Run(tt.name, func(t *testing.T) {
if got := tt.args.t.execute(tt.args.str.Sanitize()); got != tt.want {
t.Errorf("Template.Execute() = %v, want %v", got, tt.want)
}
})
}
}