-
Notifications
You must be signed in to change notification settings - Fork 112
/
global_map_prefix_test.go
115 lines (95 loc) · 2.52 KB
/
global_map_prefix_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
114
115
package mxj
import (
"testing"
"github.com/google/go-cmp/cmp"
)
var whiteSpaceDataSeqTest2 = []byte(`<books>
<book seq="1" ser="5">
<author>William T. Gaddis </author>
<title> The Recognitions </title>
<review> One of the great seminal American novels of the 20th century.</review>
</book>
<book seq="2">
<author>Austin Tappan Wright</author>
<title>Islandia</title>
<review>An example of earlier 20th century American utopian fiction.</review>
</book>
<book seq="3" ser="6">
<author> John Hawkes </author>
<title> The Beetle Leg </title>
<review> A lyrical novel about the construction of Ft. Peck Dam in Montana. </review>
</book>
</books>`)
func TestSetGlobalKeyMapPrefix(t *testing.T) {
prefixList := []struct {
name string
value string
}{
{
name: "Testing with % as Map Key Prefix",
value: "%",
},
{
name: "Testing with _ as Map Key Prefix",
value: "_",
},
{
name: "Testing with - as Map Key Prefix",
value: "-",
},
{
name: "Testing with & as Map Key Prefix",
value: "&",
},
}
for _, prefix := range prefixList {
t.Run(prefix.name, func(t *testing.T) {
// Testing MapSeq(Ordering) with whitespace and byte equivalence
DisableTrimWhiteSpace(true)
SetGlobalKeyMapPrefix(prefix.value)
m, err := NewMapFormattedXmlSeq(whiteSpaceDataSeqTest2)
if err != nil {
t.Fatal(err)
}
m1 := MapSeq(m)
x, err := m1.XmlIndent("", " ")
if err != nil {
t.Fatal(err)
}
if string(x) != string(whiteSpaceDataSeqTest2) {
t.Fatalf("expected\n'%s' \ngot \n'%s'", whiteSpaceDataSeqTest2, x)
}
DisableTrimWhiteSpace(false)
// Testing Map with whitespace and deep equivalence
DisableTrimWhiteSpace(true)
m3, err := NewMapXml(whiteSpaceDataSeqTest2)
if err != nil {
t.Fatal(err)
}
m4 := Map(m3)
if !cmp.Equal(m3, m4) {
t.Errorf("Maps unmatched using %s", prefix.value)
}
DisableTrimWhiteSpace(false)
// Testing MapSeq(Ordering) without whitespace and byte equivalence
m5, err := NewMapFormattedXmlSeq(whiteSpaceDataSeqTest2)
if err != nil {
t.Fatal(err)
}
m6 := MapSeq(m5)
if !cmp.Equal(m5, m6) {
t.Errorf("Maps unmatched using %s", prefix.value)
}
// Testing Map without whitespace and deep equivalence
m7, err := NewMapXml(whiteSpaceDataSeqTest2)
if err != nil {
t.Fatal(err)
}
m8 := Map(m7)
if !cmp.Equal(m7, m8) {
t.Errorf("Maps unmatched using %s", prefix.value)
}
})
}
SetGlobalKeyMapPrefix("#")
}