-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_test.go
86 lines (69 loc) · 2.59 KB
/
util_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
package dom
import (
"testing"
)
// TestUtilEscape tests the convenience method to escape XML character data.
func TestUtilEscape(t *testing.T) {
data := "<>&&"
str := escape(data)
expected := "<>&&amp;"
if str != expected {
t.Logf("expected: %v", expected)
t.Logf("acuta: %v", str)
t.Errorf("escaped sequence does not match")
}
}
// TODO fix this implementatin, plus test!
// func TestUtilMoveNamespacesToRoot(t *testing.T) {
// doc := NewDocument()
// root, _ := doc.CreateElement("employees")
// root.SetAttribute("hasNamespace", "nope")
// employee1, _ := doc.CreateElementNS("urn:employee", "employee")
// person1, _ := doc.CreateElementNS("urn:person", "p1:person")
// person1.SetAttribute("name", "Mimi")
// person2, _ := doc.CreateElementNS("urn:person", "p2:person")
// person3, _ := doc.CreateElementNS("urn:person", "person")
// employee2, _ := doc.CreateElementNS("urn:employee", "employee")
// employee2.SetAttribute("nonamespace", "valuevalue")
// employee2ExtraInfo, _ := doc.CreateAttributeNS("urn:extraInfo", "pfx1:extraInfo")
// employee2ExtraInfo.SetValue("deb")
// employee2Bleh, _ := doc.CreateAttributeNS("urn:attr_no_pfx", "attributeNoPrefix")
// employee2Bleh.SetValue("HI THAR")
// elemExtraInfo, _ := doc.CreateElementNS("urn:extraInfo", "extraInfo")
// doc.AppendChild(root)
// root.AppendChild(employee1)
// root.AppendChild(employee2)
// root.AppendChild(elemExtraInfo)
// employee1.AppendChild(person1)
// employee1.AppendChild(person2)
// employee1.AppendChild(person3)
// employee2.SetAttributeNode(employee2ExtraInfo)
// employee2.SetAttributeNode(employee2Bleh)
// var b bytes.Buffer
// PrintTree(doc, &b)
// t.Logf("\nBefore moving namespaces to root:\n\n%s", b.String())
// // Move namespaces to the document element.
// MoveNamespacesToRoot(doc)
// b.Reset()
// PrintTree(doc, &b)
// t.Logf("\nAfter moving namespaces to root:\n\n%s", b.String())
// // Assert things.
// tests := []struct {
// expected interface{}
// actual interface{}
// }{
// {"employees", root.GetTagName()},
// {6, root.GetAttributes().Length()},
// {"urn:employee", root.GetAttribute("xmlns:ns0")},
// {"urn:person", root.GetAttribute("xmlns:p1")},
// {"urn:person", root.GetAttribute("xmlns:p2")},
// {"urn:extraInfo", root.GetAttribute("xmlns:pfx1")},
// {"Mimi", person1.GetAttribute("name")},
// {"pfx1:extraInfo", root.GetChildNodes()[2].GetNodeName()},
// }
// for i, bla := range tests {
// if bla.expected != bla.actual {
// t.Errorf("test index %d: expected '%v', got '%v'", i, bla.expected, bla.actual)
// }
// }
// }