-
Notifications
You must be signed in to change notification settings - Fork 16
/
reader2j_test.go
executable file
·85 lines (73 loc) · 1.8 KB
/
reader2j_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
package x2j
import (
"bytes"
"fmt"
"testing"
)
var doc = `<entry><vars><foo>bar</foo><foo2><hello>world</hello></foo2></vars></entry>`
func TestToTree(t *testing.T) {
fmt.Println("\nToTree - Read doc:",doc)
rdr := bytes.NewBufferString(doc)
n,err := ToTree(rdr)
if err != nil {
fmt.Println("err:",err.Error())
}
fmt.Println(n.WriteTree())
}
func TestToMap(t *testing.T) {
fmt.Println("\nToMap - Read doc:",doc)
rdr := bytes.NewBufferString(doc)
m,err := ToMap(rdr)
if err != nil {
fmt.Println("err:",err.Error())
}
fmt.Println(WriteMap(m))
}
func TestToJson(t *testing.T) {
fmt.Println("\nToJson - Read doc:",doc)
rdr := bytes.NewBufferString(doc)
s,err := ToJson(rdr)
if err != nil {
fmt.Println("err:",err.Error())
}
fmt.Println("json:",s)
}
func TestToJsonIndent(t *testing.T) {
fmt.Println("\nToJsonIndent - Read doc:",doc)
rdr := bytes.NewBufferString(doc)
s,err := ToJsonIndent(rdr)
if err != nil {
fmt.Println("err:",err.Error())
}
fmt.Println("json:",s)
}
func TestBulkParser(t *testing.T) {
s := doc + `<this><is>an</err>`+ doc
fmt.Println("\nBulkParser (with error) - Read doc:",s)
rdr := bytes.NewBufferString(s)
err := XmlMsgsFromReader(rdr,phandler,ehandler)
if err != nil {
fmt.Println("reader terminated:",err.Error())
}
}
func phandler(m map[string]interface{}) bool {
fmt.Println("phandler m:",m)
return true
}
func ehandler(err error) bool {
fmt.Println("ehandler err:",err.Error())
return true
}
func TestBulkParserToJson(t *testing.T) {
s := doc + `<this><is>an</err>`+ doc
fmt.Println("\nBulkParser (with error) - Read doc:",s)
rdr := bytes.NewBufferString(s)
err := XmlMsgsFromReaderAsJson(rdr,phandlerj,ehandler)
if err != nil {
fmt.Println("reader terminated:",err.Error())
}
}
func phandlerj(s string) bool {
fmt.Println("phandlerj s:",s)
return true
}