-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathempty_unmarshaler_test.go
77 lines (70 loc) · 1.51 KB
/
empty_unmarshaler_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
package xmlutils_test
import (
"encoding/xml"
"testing"
"fmt"
. "github.com/smartystreets/goconvey/convey"
"github.com/mantyr/xmlutils"
)
type table2 struct {
XMLName xml.Name
XMLNS string `xml:"xmlns:st,attr"`
FIO fio `xml:"fio"`
}
type fio struct {
value string
}
func (f *fio) UnmarshalXML(d *xmlutils.Decoder, start xml.StartElement) error {
var data string
err := d.DecodeElement(&data, &start)
if err != nil {
return fmt.Errorf("err: %v", err)
}
f.value = data
return nil
}
func TestEmptyUnmarshaler(t *testing.T) {
Convey("Проверяем Unmarshal", t, func() {
Convey("С пустым значением", func() {
data := `<st:table xmlns:st="http://localhost"><header:fio></header:fio></st:table>`
v := &table2{}
v.FIO.value = "test"
err := xmlutils.Unmarshal([]byte(data), v)
So(err, ShouldBeNil)
So(
v,
ShouldResemble,
&table2{
XMLName: xml.Name{
Space: "http://localhost",
Local: "table",
},
XMLNS: "http://localhost",
FIO: fio{
value: "",
},
},
)
})
Convey("Со значением", func() {
data := `<st:table xmlns:st="http://localhost"><header:fio>test</header:fio></st:table>`
v := &table2{}
err := xmlutils.Unmarshal([]byte(data), v)
So(err, ShouldBeNil)
So(
v,
ShouldResemble,
&table2{
XMLName: xml.Name{
Space: "http://localhost",
Local: "table",
},
XMLNS: "http://localhost",
FIO: fio{
value: "test",
},
},
)
})
})
}