forked from clbanning/mxj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bom_test.go
88 lines (77 loc) · 1.89 KB
/
bom_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
// bomxml.go - test handling Byte-Order-Mark headers
package mxj
import (
"bytes"
"fmt"
"io"
"testing"
)
// Check for Byte-Order-Mark header.
var boms = [][]byte{
{'\xef', '\xbb', '\xbf'},
{'\xfe', '\xff'},
{'\xff', '\xfe'},
{'\x00', '\x00', '\xfe', '\xff'},
{'\xff', '\xfe', '\x00', '\x00'},
}
func TestBom(t *testing.T) {
fmt.Println("\n--------------- bom_test.go")
fmt.Println("TestBom ...")
// use just UTF-8 BOM ... no alternative CharSetReader
if _, err := NewMapXml(boms[0]); err != io.EOF {
t.Fatalf("NewMapXml err; %v\n", err)
}
if _, err := NewMapXmlSeq(boms[0]); err != io.EOF {
t.Fatalf("NewMapXmlSeq err: %v\n", err)
}
}
var bomdata = append(boms[0], []byte(`<Allitems>
<Item>
</Item>
<Item>
<link>http://www.something.com</link>
<description>Some description goes here.</description>
</Item>
</Allitems>`)...)
func TestBomData(t *testing.T) {
fmt.Println("TestBomData ...")
m, err := NewMapXml(bomdata)
if err != nil {
t.Fatalf("err: didn't find xml.StartElement")
}
fmt.Printf("m: %v\n", m)
j, _ := m.Xml()
fmt.Println("m:", string(j))
}
func TestBomDataSeq(t *testing.T) {
fmt.Println("TestBomDataSeq ...")
m, err := NewMapXmlSeq(bomdata)
if err != nil {
t.Fatalf("err: didn't find xml.StartElement")
}
fmt.Printf("m: %v\n", m)
j, _ := m.Xml()
fmt.Println("m:", string(j))
}
func TestBomDataReader(t *testing.T) {
fmt.Println("TestBomDataReader ...")
r := bytes.NewReader(bomdata)
m, err := NewMapXmlReader(r)
if err != nil {
t.Fatalf("err: didn't find xml.StartElement")
}
fmt.Printf("m: %v\n", m)
j, _ := m.Xml()
fmt.Println("m:", string(j))
}
func TestBomDataSeqReader(t *testing.T) {
fmt.Println("TestBomDataSeqReader ...")
r := bytes.NewReader(bomdata)
m, err := NewMapXmlSeqReader(r)
if err != nil {
t.Fatalf("err: didn't find xml.StartElement")
}
fmt.Printf("m: %v\n", m)
j, _ := m.Xml()
fmt.Println("m:", string(j))
}