-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhtml5_test.go
101 lines (90 loc) · 2.12 KB
/
html5_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
97
98
99
100
101
package htmx_test
import (
"bytes"
"io"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
htmx "github.com/zeiss/fiber-htmx"
)
func Benchmark_HTML5_Render(b *testing.B) {
nodes := []htmx.Node{}
for i := 0; i < 10000; i++ {
nodes = append(nodes, htmx.Element("div"))
}
for i := 0; i < b.N; i++ {
err := htmx.HTML5(
htmx.HTML5Props{
Title: "Hello, World!",
Description: "An example of an HTML5 document.",
Language: "en",
Head: []htmx.Node{
htmx.Meta(htmx.Charset("utf-8")),
htmx.Meta(htmx.Name("viewport"), htmx.Content("width=device-width, initial-scale=1")),
htmx.TitleElement(htmx.Text("Hello, World!")),
},
}, nodes...).Render(io.Discard)
assert.NoError(b, err)
}
}
func Benchmark_ClassNames_Render(b *testing.B) {
c := htmx.ClassNames{"foo": true, "bar": true, "baz": true, "qux": true, "quux": true, "corge": true, "grault": true, "garply": true, "waldo": true, "fred": true, "plugh": true, "xyzzy": true, "thud": true}
for i := 0; i < b.N; i++ {
var buf bytes.Buffer
buf.Reset()
err := c.Render(&buf)
require.NoError(b, err)
}
}
func Test_ClassNames_Render(t *testing.T) {
t.Parallel()
tests := []struct {
name string
c htmx.ClassNames
want string
}{
{
name: "empty",
c: htmx.ClassNames{},
want: " class=\"\"",
},
{
name: "single",
c: htmx.ClassNames{"foo": true},
want: " class=\"foo\"",
},
{
name: "multiple",
c: htmx.ClassNames{"foo": true, "bar": true},
want: " class=\"bar foo\"",
},
{
name: "overwrite",
c: htmx.ClassNames{"foo": false},
want: " class=\"\"",
},
{
name: "merge",
c: htmx.ClassNames{"foo": true},
want: " class=\"foo\"",
},
{
name: "merge overwrite",
c: htmx.ClassNames{"foo": true},
want: " class=\"foo\"",
},
{
name: "trim space",
c: htmx.ClassNames{" foo ": true},
want: " class=\"foo\"",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
var b bytes.Buffer
err := test.c.Render(&b)
require.NoError(t, err)
assert.Equal(t, test.want, b.String())
})
}
}