-
Notifications
You must be signed in to change notification settings - Fork 17
/
bool_test.go
46 lines (40 loc) · 1.08 KB
/
bool_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
package epp
import (
"encoding/xml"
"testing"
"github.com/nbio/st"
)
func TestBool(t *testing.T) {
x := []byte(`<example><fred/><susan/></example>`)
var y struct {
XMLName struct{} `xml:"example"`
Fred Bool `xml:"fred"`
Jane Bool `xml:"jane"`
Susan Bool `xml:"susan"`
}
err := xml.Unmarshal(x, &y)
st.Expect(t, err, nil)
st.Expect(t, y.Fred, True)
st.Expect(t, y.Jane, False)
st.Expect(t, y.Susan, True)
z, err := xml.Marshal(&y)
st.Expect(t, err, nil)
st.Expect(t, string(z), `<example><fred></fred><susan></susan></example>`)
}
func TestBoolAttr(t *testing.T) {
x := []byte(`<example fred="1" jane="FALSE"></example>`)
var y struct {
XMLName struct{} `xml:"example"`
Fred Bool `xml:"fred,attr"`
Jane Bool `xml:"jane,attr"`
Susan Bool `xml:"susan,attr"`
}
err := xml.Unmarshal(x, &y)
st.Expect(t, err, nil)
st.Expect(t, y.Fred, True)
st.Expect(t, y.Jane, False)
st.Expect(t, y.Susan, False)
z, err := xml.Marshal(&y)
st.Expect(t, err, nil)
st.Expect(t, string(z), `<example fred="1" jane="0" susan="0"></example>`)
}