...
1
2
3 package mxj
4
5 import (
6 "bytes"
7 "fmt"
8 "testing"
9 )
10
11 var baddata = []byte(`
12 something strange
13 <Allitems>
14 <Item>
15 </Item>
16 <Item>
17 <link>http://www.something.com</link>
18 <description>Some description goes here.</description>
19 </Item>
20 </Allitems>
21 `)
22
23 func TestBadXml(t *testing.T) {
24 fmt.Println("\n---------------- badxml_test.go")
25 fmt.Println("TestBadXml ...")
26 m, err := NewMapXml(baddata)
27 if err != nil {
28 t.Fatalf("err: didn't find xml.StartElement")
29 }
30 fmt.Printf("m: %v\n", m)
31 j, _ := m.Xml()
32 fmt.Println("m:", string(j))
33 }
34
35 func TestBadXmlSeq(t *testing.T) {
36 fmt.Println("TestBadXmlSeq ...")
37 m, err := NewMapXmlSeq(baddata)
38 if err != nil {
39 t.Fatalf("err: didn't find xmlStartElement")
40 }
41 fmt.Printf("m: %v\n", m)
42 j, _ := m.Xml()
43 fmt.Println("m:", string(j))
44 }
45
46 func TestBadXmlReader(t *testing.T) {
47 fmt.Println("TestBadXmlReader ...")
48 r := bytes.NewReader(baddata)
49 m, err := NewMapXmlReader(r)
50 if err != nil {
51 t.Fatalf("err: didn't find xml.StartElement")
52 }
53 fmt.Printf("m: %v\n", m)
54 j, _ := m.Xml()
55 fmt.Println("m:", string(j))
56 }
57
58 func TestBadXmlSeqReader(t *testing.T) {
59 fmt.Println("TestBadXmlSeqReader ...")
60 r := bytes.NewReader(baddata)
61 m, err := NewMapXmlSeqReader(r)
62 if err != nil {
63 t.Fatalf("err: didn't find xmlStartElement")
64 }
65 fmt.Printf("m: %v\n", m)
66 j, _ := m.Xml()
67 fmt.Println("m:", string(j))
68 }
69
View as plain text