-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender_person_test.go
45 lines (36 loc) · 949 Bytes
/
render_person_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
package veun_test
import (
"context"
"html/template"
"testing"
"github.com/alecthomas/assert/v2"
. "github.com/stanistan/veun"
t "github.com/stanistan/veun/template"
)
type Person struct {
Name string
}
type personView struct {
Person Person
}
func PersonView(person Person) *personView {
return &personView{Person: person}
}
var personViewTpl = template.Must(
template.New("PersonView").Parse(`<div>Hi, {{ .Name }}.</div>`),
)
func (v *personView) View(_ context.Context) (*View, error) {
return V(t.Template{Tpl: personViewTpl, Data: v.Person}), nil
}
func TestRenderPerson(t *testing.T) {
html, err := Render(context.Background(), PersonView(Person{Name: "Stan"}))
assert.NoError(t, err)
assert.Equal(t, html, template.HTML(`<div>Hi, Stan.</div>`))
}
func BenchmarkRender(b *testing.B) {
ctx := context.Background()
person := PersonView(Person{Name: "Stan"})
for i := 0; i < b.N; i++ {
_, _ = Render(ctx, person)
}
}