-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelement_test.go
96 lines (84 loc) · 1.86 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
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
package kiteroot
import (
"reflect"
"testing"
)
func TestMakeAttrs(t *testing.T) {
testcase := [][]string{
[]string{"key", "value", "id", "post"},
[]string{"src", "somewhere"},
[]string{"href", "#", "type", "text/css", "rel", "stylesheet", "dropped"},
[]string{"hash", "1234", "class", "secret"},
}
attrs := []Attributes{
Attributes{
"key": "value",
"id": "post",
},
Attributes{
"src": "somewhere",
},
Attributes{
"href": "#",
"rel": "stylesheet",
"type": "text/css",
},
Attributes{
"hash": "1234",
"class": "secret",
},
}
for i, tc := range testcase {
if !reflect.DeepEqual(MakeAttrs(tc...), attrs[i]) {
t.Fail()
}
}
}
func TestAttribute(t *testing.T) {
baseAttrs := Attributes{
"id": "site-head",
"class": "header",
"title": "attribute",
"condition": "yes",
}
if !containsAttrs(baseAttrs, nil) {
t.Errorf("Contains nil Attributes should be true")
}
testcase := [][]string{
[]string{"id", "site-head"},
[]string{"class", "content"},
[]string{"title", "attribute", "condition", "yes"},
[]string{"id", "site-head", "class", "header", "title", "attribute"},
}
results := []bool{true, false, true, true}
for i, tc := range testcase {
attrs := MakeAttrs(tc...)
if containsAttrs(baseAttrs, attrs) != results[i] {
t.Fail()
}
}
}
func TestTagString(t *testing.T) {
var text Element
text.Type = TextType
text.Content = "text"
var tag Element
tag.Type = TagType
tag.Content = "name"
tag.Attrs = MakeAttrs("class", "attribute", "attr", "yes")
tag.Append(&text)
var br Element
br.Type = TagType
br.Content = "br"
br.Attrs = MakeAttrs("class", "correct")
br.selfClosing = true
tag.Append(&br)
found := tag.FindAll("br", "class", "correct")
if len(found) != 1 {
t.Fail()
}
elem := tag.FindWithAttrs("br", MakeAttrs("class", "wrong"))
if elem != nil {
t.Fail()
}
}