...
1 package mxj
2
3 import (
4 "fmt"
5 "io"
6 "testing"
7 )
8
9 func TestXmlSeqHeader(t *testing.T) {
10 fmt.Println("\n---------------- xmlseq_test.go ...")
11 }
12
13 func TestNewMapXmlSeq(t *testing.T) {
14 x := []byte(`<doc>
15 <books>
16 <book seq="1">
17 <author>William T. Gaddis</author>
18 <review>Gaddis is one of the most influential but little know authors in America.</review>
19 <title>The Recognitions</title>
20 <!-- here's the rest of the review -->
21 <review>One of the great seminal American novels of the 20th century.</review>
22 <review>Without it Thomas Pynchon probably wouldn't have written Gravity's Rainbow.</review>
23 </book>
24 <book seq="2">
25 <author>Austin Tappan Wright</author>
26 <title>Islandia</title>
27 <review>An example of earlier 20th century American utopian fiction.</review>
28 </book>
29 <book>
30 <author>John Hawkes</author>
31 <title>The Beetle Leg</title>
32 <!throw in a directive here>
33 <review>A lyrical novel about the construction of Ft. Peck Dam in Montana.</review>
34 </book>
35 <book>
36 <author>
37 <?cat first_name last_name?>
38 <first_name>T.E.</first_name>
39 <last_name>Porter</last_name>
40 </author>
41 <title>King's Day</title>
42 <review>A magical novella.</review>
43 </book>
44 </books>
45 </doc>`)
46
47 msv, err := NewMapXmlSeq(x)
48 if err != nil && err != io.EOF {
49 t.Fatal("err:", err.Error())
50 }
51 fmt.Println("NewMapXmlSeq, x:\n", string(x))
52 fmt.Println("NewMapXmlSeq, s:\n", msv.StringIndent())
53
54 b, err := msv.XmlIndent("", " ")
55 if err != nil {
56 t.Fatal("err:", err)
57 }
58 fmt.Println("NewMapXmlSeq, msv.XmlIndent():\n", string(b))
59 }
60
61 func TestXmlSeqDecodeError(t *testing.T) {
62 fmt.Println("------------ TestXmlSeqDecodeError ...")
63 x := []byte(`<doc>
64 <books>
65 <book seq="1">
66 <author>William T. Gaddis</author>
67 <review>Gaddis is one of the most influential but little know authors in America.</review>
68 <title>The Recognitions</title>
69 <!-- here's the rest of the review -->
70 <review>One of the great seminal American novels of the 20th century.</review>
71 <review>Without it Thomas Pynchon probably wouldn't have written Gravity's Rainbow.</review>
72 </books>
73 </doc>`)
74
75 _, err := NewMapXmlSeq(x)
76 if err == nil {
77 t.Fatal("didn't catch EndElement error")
78 }
79 fmt.Println("err ok:", err)
80 }
81
View as plain text