-
Notifications
You must be signed in to change notification settings - Fork 6
/
tag_test.go
69 lines (65 loc) · 1.02 KB
/
tag_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
package htmlgo_test
import (
"context"
"testing"
. "github.com/theplant/htmlgo"
"github.com/theplant/testingutils"
)
var htmltagCases = []struct {
name string
tag *HTMLTagBuilder
expected string
}{
{
name: "case 1",
tag: Div(
Div().Text("Hello"),
),
expected: `
<div>
<div>Hello</div>
</div>
`,
},
{
name: "case 2",
tag: Div(
Div().Text("Hello").
Attr("class", "menu",
"id", "the-menu",
"style").
Attr("id", "menu-id"),
),
expected: `
<div>
<div class='menu' id='menu-id'>Hello</div>
</div>
`,
},
{
name: "escape 1",
tag: Div(
Div().Text("Hello").
Attr("class", "menu",
"id", "the><&\"'-menu",
"style"),
),
expected: `
<div>
<div class='menu' id='the><&"'-menu'>Hello</div>
</div>
`,
},
}
func TestHtmlTag(t *testing.T) {
for _, c := range htmltagCases {
r, err := c.tag.MarshalHTML(context.TODO())
if err != nil {
panic(err)
}
diff := testingutils.PrettyJsonDiff(c.expected, string(r))
if len(diff) > 0 {
t.Error(c.name, diff)
}
}
}