forked from clbanning/mxj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strict_test.go
48 lines (40 loc) · 1.2 KB
/
strict_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
package mxj
import (
"encoding/xml"
"fmt"
"testing"
)
func TestStrictModeXml(t *testing.T) {
fmt.Println("----------------- TestStrictModeXml ...")
data := []byte(`<document> <name>Bill & Hallett</name> <salute>Duc & 123xx</salute> <goes_by/> <lang>E</lang> </document>`)
CustomDecoder = &xml.Decoder{Strict:false}
m, err := NewMapXml(data)
if err != nil {
t.Fatal(err)
}
fmt.Println("m:",m)
}
func TestStrictModeXmlSeq(t *testing.T) {
fmt.Println("----------------- TestStrictModeXmlSeq ...")
data := []byte(`<document> <name>Bill & Hallett</name> <salute>Duc & 123xx</salute> <goes_by/> <lang>E</lang> </document>`)
CustomDecoder = &xml.Decoder{Strict:false}
m, err := NewMapXmlSeq(data)
if err != nil {
t.Fatal(err)
}
fmt.Println("m:",m)
}
func TestStrictModeFail(t *testing.T) {
fmt.Println("----------------- TestStrictFail ...")
data := []byte(`<document> <name>Bill & Hallett</name> <salute>Duc & 123xx</salute> <goes_by/> <lang>E</lang> </document>`)
CustomDecoder = nil
_, err := NewMapXml(data)
if err == nil {
t.Fatal("error not caught: NewMapXml")
}
_, err = NewMapXmlSeq(data)
if err == nil {
t.Fatal("error not caught: NewMapXmlSeq")
}
fmt.Println("OK")
}