1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
15 XMLName Name
"http://domain a"
28 <?xml version="1.0" encoding="UTF-8"?>
29 <a xmlns="http://domain">
41 // Tests that embedded structs are marshalled.
42 func TestEmbedded1(t
*testing
.T
) {
44 if e
:= Unmarshal(StringReader(_1a
), &a
); e
!= nil {
45 t
.Fatalf("Unmarshal: %s", e
)
47 if a
.FieldA
!= "foo" {
48 t
.Fatalf("Unmarshal: expected 'foo' but found '%s'", a
.FieldA
)
50 if a
.Name
!= "KmlFile" {
51 t
.Fatalf("Unmarshal: expected 'KmlFile' but found '%s'", a
.Name
)
54 t
.Fatal("Unmarshal: expected 'true' but found otherwise")
56 if a
.B
.FieldB
!= "bar" {
57 t
.Fatalf("Unmarshal: expected 'bar' but found '%s'", a
.B
.FieldB
)
59 if a
.B
.Name
!= "Absolute" {
60 t
.Fatalf("Unmarshal: expected 'Absolute' but found '%s'", a
.B
.Name
)
63 t
.Fatal("Unmarshal: expected 'false' but found otherwise")
68 XMLName Name
"http://domain a"
74 <?xml version="1.0" encoding="UTF-8"?>
75 <a xmlns="http://domain">
80 // Tests that conflicting field names get excluded.
81 func TestEmbedded2(t
*testing
.T
) {
83 if e
:= Unmarshal(StringReader(_2a
), &a
); e
!= nil {
84 t
.Fatalf("Unmarshal: %s", e
)
87 t
.Fatalf("Unmarshal: expected empty string but found '%s'", a
.XY
)
90 t
.Fatalf("Unmarshal: expected empty string but found '%s'", a
.Xy
)
95 XMLName Name
"http://domain a"
99 // Tests that private fields are not set.
100 func TestEmbedded3(t
*testing
.T
) {
102 if e
:= Unmarshal(StringReader(_2a
), &a
); e
!= nil {
103 t
.Fatalf("Unmarshal: %s", e
)
106 t
.Fatalf("Unmarshal: expected empty string but found '%s'", a
.xy
)
111 XMLName Name
"http://domain a"
115 // Tests that private fields are not set.
116 func TestEmbedded4(t
*testing
.T
) {
118 if e
:= Unmarshal(StringReader(_2a
), &a
); e
!= nil {
119 t
.Fatalf("Unmarshal: %s", e
)
122 t
.Fatalf("Unmarshal: expected 'foo' but found '%s'", a
.Any
)