-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelements_test.go
More file actions
92 lines (63 loc) · 1.45 KB
/
elements_test.go
File metadata and controls
92 lines (63 loc) · 1.45 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
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
/* Copyright 2019 Kilobit Labs Inc. */
// Tests for the elements unit.
//
package elements
import "testing"
func TestElementsTest(t *testing.T) {
Expect(t, true, true)
}
func TestElement(t *testing.T) {
el := NewElement("tag").
AddAttr("tagged").
SetAttr("foo", "bar")
t.Log(el)
Expect(t, "tag", el.Tag())
attr := el.Attr("tagged")
Expect(t, "", attr)
attr = el.Attr("foo")
Expect(t, "bar", attr)
}
func TestElementCopy(t *testing.T) {
el := NewElement("tag").
AddAttr("tagged").
SetAttr("foo", "bar").
AddChild(NewElement("nav")).
AddChild(NewElement("main")).
AddChild(Content("Hello World!"))
cel := el.Copy()
t.Logf("%#v", cel)
t.Log(cel)
attr := cel.Attr("tagged")
Expect(t, "", attr)
attr = cel.Attr("foo")
Expect(t, "bar", attr)
Expect(t, 3, len(el.Children()))
}
func TestElementNested(t *testing.T) {
el := NewElement("section").
AddChild(NewElement("nav")).
AddChild(NewElement("main"))
t.Log(el)
Expect(t, 2, len(el.Children()))
}
func TestElementContent(t *testing.T) {
c := Content("Hello > World!")
el := NewElement("p").
AddChild(c)
t.Log(el)
Expect(t, c, el.ChildN(0))
Expect(t, 1, len(el.Children()))
}
func TestElementAttrs(t *testing.T) {
el := NewElement("TAG").
SetAttrs(
map[string]string{
"foo": "bar",
"bing": "bang!",
"cheery": "oh",
})
t.Log(el)
Expect(t, "bar", el.Attr("foo"))
Expect(t, "bang!", el.Attr("bing"))
Expect(t, "oh", el.Attr("cheery"))
}