-
Notifications
You must be signed in to change notification settings - Fork 0
/
procinst_test.go
71 lines (67 loc) · 2.09 KB
/
procinst_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
package dom
import (
"testing"
)
func TestProcessingInstructionGetters(t *testing.T) {
doc := NewDocument()
pi, _ := doc.CreateProcessingInstruction("procinsttarget", "procinstdata")
pi.setParentNode(doc)
bogusElement, _ := doc.CreateElement("anything")
if err := pi.AppendChild(bogusElement); err == nil {
t.Error("expected error at this point")
}
if pi.GetOwnerDocument() != doc {
t.Error("owner document invalid")
}
if pi.GetParentNode() != doc {
t.Error("invalid parent node (should be document)")
}
if pi.GetFirstChild() != nil {
t.Error("processing instructions should not have children")
}
if pi.GetLastChild() != nil {
t.Error("processing instructions should not have children")
}
if len(pi.GetChildNodes()) != 0 {
t.Error("child nodes length should be 0")
}
if pi.HasChildNodes() {
t.Error("HasChildNodes returns true, should be false")
}
if pi.GetAttributes() != nil {
t.Error("attributes should be nil")
}
if pi.GetTarget() != "procinsttarget" {
t.Errorf("target should be 'procinsttarget', but was '%v'", pi.GetTarget())
}
if pi.GetNodeName() != "procinsttarget" {
t.Errorf("nodename should be 'procinsttarget', but was '%v'", pi.GetNodeName())
}
if pi.GetData() != "procinstdata" {
t.Errorf("data should be 'procinstdata', but was '%v'", pi.GetData())
}
if pi.GetNodeValue() != "procinstdata" {
t.Errorf("node value should be 'procinstdata', but was '%v'", pi.GetNodeValue())
}
if pi.GetNamespaceURI() != "" {
t.Error("namespace uri should be an empty string at all times")
}
if pi.GetNodeType() != ProcessingInstructionNode {
t.Errorf("node type should be '%v'", pi.GetNodeType())
}
if pi.GetNamespacePrefix() != "" {
t.Error("namespace prefix should be an empty string")
}
if _, err := pi.RemoveChild(nil); err == nil {
t.Error("expected error, but got none")
}
if _, err := pi.InsertBefore(nil, nil); err == nil {
t.Error("expected error, but got none")
}
if _, err := pi.ReplaceChild(nil, nil); err == nil {
t.Error("expected error, but got none")
}
if pi.HasAttributes() {
t.Error("processing instructions cannot have children")
}
}