File: reader2j_test.go

package info (click to toggle)
golang-github-clbanning-mxj 2.5.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,852 kB
  • sloc: xml: 176; makefile: 4
file content (76 lines) | stat: -rw-r--r-- 1,633 bytes parent folder | download | duplicates (2)
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
package x2j

import (
	"bytes"
	"fmt"
	"testing"
)

var doc = `<entry><vars><foo>bar</foo><foo2><hello>world</hello></foo2></vars></entry>`


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
}