From db059282165343a99609ff2f655ec6c1daeb4998 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Tue, 2 Feb 2010 11:53:10 +1100 Subject: allow any scalar type in xml.Unmarshal. Fixes issue 574. R=rsc CC=golang-dev http://codereview.appspot.com/196056 --- src/pkg/xml/xml_test.go | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'src/pkg/xml/xml_test.go') diff --git a/src/pkg/xml/xml_test.go b/src/pkg/xml/xml_test.go index f228dfba3..fa1949500 100644 --- a/src/pkg/xml/xml_test.go +++ b/src/pkg/xml/xml_test.go @@ -214,6 +214,76 @@ func TestSyntax(t *testing.T) { } } +type allScalars struct { + Bool bool + Int int + Int8 int8 + Int16 int16 + Int32 int32 + Int64 int64 + Uint int + Uint8 uint8 + Uint16 uint16 + Uint32 uint32 + Uint64 uint64 + Uintptr uintptr + Float float + Float32 float32 + Float64 float64 + String string +} + +var all = allScalars{ + Bool: true, + Int: 1, + Int8: -2, + Int16: 3, + Int32: -4, + Int64: 5, + Uint: 6, + Uint8: 7, + Uint16: 8, + Uint32: 9, + Uint64: 10, + Uintptr: 11, + Float: 12.0, + Float32: 13.0, + Float64: 14.0, + String: "15", +} + +const testScalarsInput = ` + + 1 + -2 + 3 + -4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12.0 + 13.0 + 14.0 + 15 +` + +func TestAllScalars(t *testing.T) { + var a allScalars + buf := bytes.NewBufferString(testScalarsInput) + err := Unmarshal(buf, &a) + + if err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(a, all) { + t.Errorf("expected %+v got %+v", a, all) + } +} + type item struct { Field_a string } -- cgit v1.2.3