-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtag_test.go
68 lines (64 loc) · 1.39 KB
/
tag_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
package xmlutils_test
import (
"testing"
"encoding/xml"
. "github.com/smartystreets/goconvey/convey"
"github.com/mantyr/xmlutils"
)
type table struct {
XMLName xml.Name
XMLNS string `xml:"xmlns:st,attr"`
Item string `xml:"st:item"`
Other string `xml:"header:from>header:data>header:id,omitempty"`
}
func TestTag(t *testing.T) {
data := `<st:table xmlns:st="http://localhost"><st:item>test</st:item><header:from><header:data><header:id>from-data-id</header:id></header:data></header:from></st:table>`
Convey("Проверяем Marshal с prefix:tag", t, func() {
v := &table{
XMLName: xml.Name{
Space: "",
Local: "st:table",
},
XMLNS: "http://localhost",
Item: "test",
Other: "from-data-id",
}
result, err := xmlutils.Marshal(v)
So(err, ShouldBeNil)
So(
string(result),
ShouldEqual,
data,
)
})
Convey("Проверяем Unmarshal с prefix:tag", t, func() {
v := &table{}
err := xmlutils.Unmarshal([]byte(data), v)
So(err, ShouldBeNil)
So(
v,
ShouldResemble,
&table{
XMLName: xml.Name{
Space:"http://localhost",
Local:"table",
},
XMLNS: "http://localhost",
Item: "test",
Other: "from-data-id",
},
)
v.XMLName = xml.Name{
Space: "",
Local: "st:table",
}
v.XMLNS = "http://localhost"
result, err := xmlutils.Marshal(v)
So(err, ShouldBeNil)
So(
string(result),
ShouldEqual,
data,
)
})
}