diff options
| author | Nigel Tao <nigeltao@golang.org> | 2015-02-26 10:40:15 +1100 |
|---|---|---|
| committer | Nigel Tao <nigeltao@golang.org> | 2015-02-25 23:56:21 +0000 |
| commit | b351e1decf4c1cfb3d5a80f467b49846b5d17f4b (patch) | |
| tree | 52c4dce27b35157473a941c4fbd0412b276f26ab /src/encoding | |
| parent | 59e546633d5b41f69971bd9f019f5e54c600fa17 (diff) | |
| download | go-b351e1decf4c1cfb3d5a80f467b49846b5d17f4b.tar.xz | |
encoding/xml: add more marshalTests tests.
There are no behavior changes in this CL, only specifying the status
quo. A follow-up CL, https://go-review.googlesource.com/#/c/5910/, will
change marshaling behavior.
Change-Id: Ib3f4d62e8c4758da2f11a6d26b285c10d3b0d98a
Reviewed-on: https://go-review.googlesource.com/6040
Reviewed-by: Andrew Gerrand <adg@golang.org>
Diffstat (limited to 'src/encoding')
| -rw-r--r-- | src/encoding/xml/marshal_test.go | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/src/encoding/xml/marshal_test.go b/src/encoding/xml/marshal_test.go index cc6994338d..7410a81ec9 100644 --- a/src/encoding/xml/marshal_test.go +++ b/src/encoding/xml/marshal_test.go @@ -617,6 +617,69 @@ var marshalTests = []struct { `</service>`, MarshalOnly: true, }, + { + Value: &struct { + XMLName struct{} `xml:"space top"` + A string `xml:"x>a"` + B string `xml:"x>b"` + C string `xml:"space x>c"` + C1 string `xml:"space1 x>c"` + D1 string `xml:"space1 x>d"` + }{ + A: "a", + B: "b", + C: "c", + C1: "c1", + D1: "d1", + }, + ExpectXML: `<top xmlns="space">` + + `<x xmlns=""><a>a</a><b>b</b><c xmlns="space">c</c>` + + `<c xmlns="space1">c1</c>` + + `<d xmlns="space1">d1</d>` + + `</x>` + + `</top>`, + }, + { + Value: &struct { + XMLName Name + A string `xml:"x>a"` + B string `xml:"x>b"` + C string `xml:"space x>c"` + C1 string `xml:"space1 x>c"` + D1 string `xml:"space1 x>d"` + }{ + XMLName: Name{ + Space: "space0", + Local: "top", + }, + A: "a", + B: "b", + C: "c", + C1: "c1", + D1: "d1", + }, + ExpectXML: `<top xmlns="space0">` + + `<x xmlns=""><a>a</a><b>b</b>` + + `<c xmlns="space">c</c>` + + `<c xmlns="space1">c1</c>` + + `<d xmlns="space1">d1</d>` + + `</x>` + + `</top>`, + }, + { + Value: &struct { + XMLName struct{} `xml:"top"` + B string `xml:"space x>b"` + B1 string `xml:"space1 x>b"` + }{ + B: "b", + B1: "b1", + }, + ExpectXML: `<top>` + + `<x><b xmlns="space">b</b>` + + `<b xmlns="space1">b1</b></x>` + + `</top>`, + }, // Test struct embedding { @@ -933,7 +996,7 @@ func TestMarshal(t *testing.T) { } data, err := Marshal(test.Value) if err != nil { - t.Errorf("#%d: Error: %s", idx, err) + t.Errorf("#%d: marshal(%#v): %s", idx, test.Value, err) continue } if got, want := string(data), test.ExpectXML; got != want { @@ -1037,6 +1100,14 @@ func TestUnmarshal(t *testing.T) { if _, ok := test.Value.(*Plain); ok { continue } + if test.ExpectXML == `<top>`+ + `<x><b xmlns="space">b</b>`+ + `<b xmlns="space1">b1</b></x>`+ + `</top>` { + // TODO(rogpeppe): re-enable this test in + // https://go-review.googlesource.com/#/c/5910/ + continue + } vt := reflect.TypeOf(test.Value) dest := reflect.New(vt.Elem()).Interface() |
