From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- libgo/go/xml/embed_test.go | 124 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 libgo/go/xml/embed_test.go (limited to 'libgo/go/xml/embed_test.go') diff --git a/libgo/go/xml/embed_test.go b/libgo/go/xml/embed_test.go new file mode 100644 index 000000000..abfe781ac --- /dev/null +++ b/libgo/go/xml/embed_test.go @@ -0,0 +1,124 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package xml + +import "testing" + +type C struct { + Name string + Open bool +} + +type A struct { + XMLName Name "http://domain a" + C + B B + FieldA string +} + +type B struct { + XMLName Name "b" + C + FieldB string +} + +const _1a = ` + + + KmlFile + 1 + + Absolute + 0 + bar + + foo + +` + +// Tests that embedded structs are marshalled. +func TestEmbedded1(t *testing.T) { + var a A + if e := Unmarshal(StringReader(_1a), &a); e != nil { + t.Fatalf("Unmarshal: %s", e) + } + if a.FieldA != "foo" { + t.Fatalf("Unmarshal: expected 'foo' but found '%s'", a.FieldA) + } + if a.Name != "KmlFile" { + t.Fatalf("Unmarshal: expected 'KmlFile' but found '%s'", a.Name) + } + if !a.Open { + t.Fatal("Unmarshal: expected 'true' but found otherwise") + } + if a.B.FieldB != "bar" { + t.Fatalf("Unmarshal: expected 'bar' but found '%s'", a.B.FieldB) + } + if a.B.Name != "Absolute" { + t.Fatalf("Unmarshal: expected 'Absolute' but found '%s'", a.B.Name) + } + if a.B.Open { + t.Fatal("Unmarshal: expected 'false' but found otherwise") + } +} + +type A2 struct { + XMLName Name "http://domain a" + XY string + Xy string +} + +const _2a = ` + + + foo + +` + +// Tests that conflicting field names get excluded. +func TestEmbedded2(t *testing.T) { + var a A2 + if e := Unmarshal(StringReader(_2a), &a); e != nil { + t.Fatalf("Unmarshal: %s", e) + } + if a.XY != "" { + t.Fatalf("Unmarshal: expected empty string but found '%s'", a.XY) + } + if a.Xy != "" { + t.Fatalf("Unmarshal: expected empty string but found '%s'", a.Xy) + } +} + +type A3 struct { + XMLName Name "http://domain a" + xy string +} + +// Tests that private fields are not set. +func TestEmbedded3(t *testing.T) { + var a A3 + if e := Unmarshal(StringReader(_2a), &a); e != nil { + t.Fatalf("Unmarshal: %s", e) + } + if a.xy != "" { + t.Fatalf("Unmarshal: expected empty string but found '%s'", a.xy) + } +} + +type A4 struct { + XMLName Name "http://domain a" + Any string +} + +// Tests that private fields are not set. +func TestEmbedded4(t *testing.T) { + var a A4 + if e := Unmarshal(StringReader(_2a), &a); e != nil { + t.Fatalf("Unmarshal: %s", e) + } + if a.Any != "foo" { + t.Fatalf("Unmarshal: expected 'foo' but found '%s'", a.Any) + } +} -- cgit v1.2.3