-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelement_test.go
64 lines (58 loc) · 1.75 KB
/
element_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
package htmlbuilder
import "testing"
func TestElementRender(t *testing.T) {
type test struct {
name string
input *Element
expected string
}
tests := []test{
{
name: "Empty element",
input: NewElement("div"),
expected: "<div></div>",
},
{
name: "Element with inner text",
input: NewElement("div", Text("Hello")),
expected: "<div>Hello</div>",
},
{
name: "Element with inner text and children",
input: NewElement("div", Text("Hello"), NewElement("span")),
expected: "<div>Hello<span></span></div>",
},
{
name: "Element with inner text and children",
input: NewElement("div", NewElement("span", Text("Hello"))),
expected: "<div><span>Hello</span></div>",
},
{
name: "Element with inner text and children",
input: NewElement("div", Text("Hello"), NewElement("span", NewElement("b", Text("Hello")))),
expected: "<div>Hello<span><b>Hello</b></span></div>",
},
{
name: "Element with attributes",
input: NewElement("div", Attr("id", "test"), Attr("class", "test")),
expected: "<div id=\"test\" class=\"test\"></div>",
},
{
name: "Element with attributes and inner text",
input: NewElement("div", Attr("id", "test"), Attr("class", "test"), Text("Hello")),
expected: "<div id=\"test\" class=\"test\">Hello</div>",
},
{
name: "Element with attributes and children",
input: NewElement("div", Attr("id", "test"), Attr("class", "test"), Span(Text("test"))),
expected: "<div id=\"test\" class=\"test\"><span>test</span></div>",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if test.input.Render() != test.expected {
t.Error("Rendered element is not correct", test.input.Render())
}
})
}
}