From cbb6491d76c7aa81cdf5d3b3a81386129c5e2fce Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 2 Mar 2012 16:38:43 +0000 Subject: libgo: Update to weekly.2012-02-14 release. From-SVN: r184798 --- libgo/go/encoding/xml/marshal_test.go | 93 ++++++++++++++++++++++++++++++++--- 1 file changed, 87 insertions(+), 6 deletions(-) (limited to 'libgo/go/encoding/xml/marshal_test.go') diff --git a/libgo/go/encoding/xml/marshal_test.go b/libgo/go/encoding/xml/marshal_test.go index 0f6c0f0795d..9170fccd243 100644 --- a/libgo/go/encoding/xml/marshal_test.go +++ b/libgo/go/encoding/xml/marshal_test.go @@ -9,6 +9,7 @@ import ( "strconv" "strings" "testing" + "time" ) type DriveType int @@ -38,14 +39,14 @@ type NamedType string type Port struct { XMLName struct{} `xml:"port"` - Type string `xml:"type,attr"` + Type string `xml:"type,attr,omitempty"` Comment string `xml:",comment"` Number string `xml:",chardata"` } type Domain struct { XMLName struct{} `xml:"domain"` - Country string `xml:",attr"` + Country string `xml:",attr,omitempty"` Name []byte `xml:",chardata"` Comment []byte `xml:",comment"` } @@ -149,11 +150,33 @@ type NameInField struct { type AttrTest struct { Int int `xml:",attr"` - Lower int `xml:"int,attr"` + Named int `xml:"int,attr"` Float float64 `xml:",attr"` Uint8 uint8 `xml:",attr"` Bool bool `xml:",attr"` Str string `xml:",attr"` + Bytes []byte `xml:",attr"` +} + +type OmitAttrTest struct { + Int int `xml:",attr,omitempty"` + Named int `xml:"int,attr,omitempty"` + Float float64 `xml:",attr,omitempty"` + Uint8 uint8 `xml:",attr,omitempty"` + Bool bool `xml:",attr,omitempty"` + Str string `xml:",attr,omitempty"` + Bytes []byte `xml:",attr,omitempty"` +} + +type OmitFieldTest struct { + Int int `xml:",omitempty"` + Named int `xml:"int,omitempty"` + Float float64 `xml:",omitempty"` + Uint8 uint8 `xml:",omitempty"` + Bool bool `xml:",omitempty"` + Str string `xml:",omitempty"` + Bytes []byte `xml:",omitempty"` + Ptr *PresenceTest `xml:",omitempty"` } type AnyTest struct { @@ -234,6 +257,12 @@ var marshalTests = []struct { {Value: &Plain{[]int{1, 2, 3}}, ExpectXML: `123`}, {Value: &Plain{[3]int{1, 2, 3}}, ExpectXML: `123`}, + // Test time. + { + Value: &Plain{time.Unix(1e9, 123456789).UTC()}, + ExpectXML: `2001-09-09T01:46:40.123456789Z`, + }, + // A pointer to struct{} may be used to test for an element's presence. { Value: &PresenceTest{new(struct{})}, @@ -549,13 +578,65 @@ var marshalTests = []struct { { Value: &AttrTest{ Int: 8, - Lower: 9, + Named: 9, + Float: 23.5, + Uint8: 255, + Bool: true, + Str: "str", + Bytes: []byte("byt"), + }, + ExpectXML: ``, + }, + { + Value: &AttrTest{Bytes: []byte{}}, + ExpectXML: ``, + }, + { + Value: &OmitAttrTest{ + Int: 8, + Named: 9, + Float: 23.5, + Uint8: 255, + Bool: true, + Str: "str", + Bytes: []byte("byt"), + }, + ExpectXML: ``, + }, + { + Value: &OmitAttrTest{}, + ExpectXML: ``, + }, + + // omitempty on fields + { + Value: &OmitFieldTest{ + Int: 8, + Named: 9, Float: 23.5, Uint8: 255, Bool: true, - Str: "s", + Str: "str", + Bytes: []byte("byt"), + Ptr: &PresenceTest{}, }, - ExpectXML: ``, + ExpectXML: `` + + `8` + + `9` + + `23.5` + + `255` + + `true` + + `str` + + `byt` + + `` + + ``, + }, + { + Value: &OmitFieldTest{}, + ExpectXML: ``, }, // Test ",any" -- cgit v1.2.1