forked from clbanning/mxj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmlseq_test.go
80 lines (73 loc) · 2.36 KB
/
xmlseq_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
package mxj
import (
"fmt"
"io"
"testing"
)
func TestXmlSeqHeader(t *testing.T) {
fmt.Println("\n---------------- xmlseq_test.go ...")
}
func TestNewMapXmlSeq(t *testing.T) {
x := []byte(`<doc>
<books>
<book seq="1">
<author>William T. Gaddis</author>
<review>Gaddis is one of the most influential but little know authors in America.</review>
<title>The Recognitions</title>
<!-- here's the rest of the review -->
<review>One of the great seminal American novels of the 20th century.</review>
<review>Without it Thomas Pynchon probably wouldn't have written Gravity's Rainbow.</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>
<author>John Hawkes</author>
<title>The Beetle Leg</title>
<!throw in a directive here>
<review>A lyrical novel about the construction of Ft. Peck Dam in Montana.</review>
</book>
<book>
<author>
<?cat first_name last_name?>
<first_name>T.E.</first_name>
<last_name>Porter</last_name>
</author>
<title>King's Day</title>
<review>A magical novella.</review>
</book>
</books>
</doc>`)
msv, err := NewMapXmlSeq(x)
if err != nil && err != io.EOF {
t.Fatal("err:", err.Error())
}
fmt.Println("NewMapXmlSeq, x:\n", string(x))
fmt.Println("NewMapXmlSeq, s:\n", msv.StringIndent())
b, err := msv.XmlIndent("", " ")
if err != nil {
t.Fatal("err:", err)
}
fmt.Println("NewMapXmlSeq, msv.XmlIndent():\n", string(b))
}
func TestXmlSeqDecodeError(t *testing.T) {
fmt.Println("------------ TestXmlSeqDecodeError ...")
x := []byte(`<doc>
<books>
<book seq="1">
<author>William T. Gaddis</author>
<review>Gaddis is one of the most influential but little know authors in America.</review>
<title>The Recognitions</title>
<!-- here's the rest of the review -->
<review>One of the great seminal American novels of the 20th century.</review>
<review>Without it Thomas Pynchon probably wouldn't have written Gravity's Rainbow.</review>
</books>
</doc>`)
_, err := NewMapXmlSeq(x)
if err == nil {
t.Fatal("didn't catch EndElement error")
}
fmt.Println("err ok:", err)
}