-
Notifications
You must be signed in to change notification settings - Fork 0
/
namednodemap_test.go
70 lines (58 loc) · 1.48 KB
/
namednodemap_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
package dom
import "testing"
func TestNamedNodeMap(t *testing.T) {
doc := NewDocument()
nnm := newNamedNodeMap()
if nnm.Length() != 0 {
t.Error("expected length of 0")
}
comment, _ := doc.CreateComment("meh")
err := nnm.SetNamedItem(comment)
if err == nil {
t.Error("expected error at this point, but got none")
}
attr, _ := doc.CreateAttribute("name")
attr.SetValue("value")
nnm.SetNamedItem(attr)
if nnm.Length() != 1 {
t.Errorf("expected length of 1, got %d", nnm.Length())
t.FailNow()
}
ret := nnm.GetNamedItem("name")
if v, ok := ret.(Attr); ok {
if v.GetNodeValue() != "value" {
t.Errorf("expected 'value', got '%v'", v.GetNodeValue())
}
} else {
t.Error("type assertion for Attr failed")
t.FailNow()
}
attrDuplicate, _ := doc.CreateAttribute("name")
attrDuplicate.SetValue("dupe!")
nnm.SetNamedItem(attrDuplicate)
if nnm.Length() != 1 {
t.Errorf("expected length of 1, got %d", nnm.Length())
t.FailNow()
}
ret = nnm.GetNamedItem("name")
if v, ok := ret.(Attr); ok {
if v.GetNodeValue() != "dupe!" {
t.Errorf("expected 'dupe!', got '%v'", v.GetNodeValue())
}
} else {
t.Error("type assertion for Attr failed")
t.FailNow()
}
m := nnm.GetItems()
if len(m) != 1 {
t.Errorf("expected length of 1, got %d", len(m))
t.FailNow()
}
if v, found := m["name"]; found {
if v.GetNodeValue() != "dupe!" {
t.Errorf("expected 'dupe!' got '%v'", v.GetNodeValue())
}
} else {
t.Error("expected to find key 'name', but got nothing")
}
}