forked from clbanning/mxj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
escapechars_test.go
113 lines (89 loc) · 2.14 KB
/
escapechars_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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package mxj
import (
"fmt"
"testing"
)
var s = `"'<>&`
func TestEscapeChars(t *testing.T) {
fmt.Println("\n================== TestEscapeChars")
ss := escapeChars(s)
if ss != `"'<>&` {
t.Fatal(s, ":", ss)
}
fmt.Println(" s:", s)
fmt.Println("ss:", ss)
}
func TestXMLEscapeChars(t *testing.T) {
fmt.Println("================== TestXMLEscapeChars")
XMLEscapeChars(true)
defer XMLEscapeChars(false)
m := map[string]interface{}{"mychars":s}
x, err := AnyXmlIndent(s, "", " ")
if err != nil {
t.Fatal(err)
}
fmt.Println("s:", string(x))
x, err = AnyXmlIndent(m, "", " ")
if err != nil {
t.Fatal(err)
}
fmt.Println("m:", string(x))
}
func TestXMLEscapeChars2(t *testing.T) {
fmt.Println("================== TestXMLEscapeChars2")
XMLEscapeChars(true)
defer XMLEscapeChars(false)
ss := []byte(`<doc><simple attr1="an attribute">"'<>&</simple></doc>`)
fmt.Println(string(ss))
mv, err := NewMapXml(ss)
if err != nil {
t.Fatal(err)
}
fmt.Printf("%v\n", mv)
x, err := mv.XmlIndent("", " ")
if err != nil {
t.Fatal(err)
}
fmt.Println("mv:", string(x))
}
func TestXMLSeqEscapeChars(t *testing.T) {
fmt.Println("================== TestXMLSeqEscapeChars")
data := []byte(`
<doc>
<shortDescription>>0-2y</shortDescription>
</doc>`)
fmt.Println("data:", string(data))
m, err := NewMapXmlSeq(data)
if err != nil {
t.Fatal(err)
}
fmt.Printf("m: %v\n", m)
XMLEscapeChars(true)
defer XMLEscapeChars(false)
x, err := m.XmlIndent("", " ")
if err != nil {
t.Fatal(err)
}
fmt.Println("m:", string(x))
}
func TestXMLSeqEscapeChars2(t *testing.T) {
fmt.Println("================== TestXMLSeqEscapeChars2")
data := []byte(`
<doc>
<shortDescription test="&something here">>0-2y</shortDescription>
<shortDescription test="something there" quote="""><10-15</shortDescription>
</doc>`)
fmt.Println("data:", string(data))
m, err := NewMapXmlSeq(data)
if err != nil {
t.Fatal(err)
}
fmt.Printf("m: %v\n", m)
XMLEscapeChars(true)
defer XMLEscapeChars(false)
x, err := m.XmlIndent("", " ")
if err != nil {
t.Fatal(err)
}
fmt.Println("m:", string(x))
}