fix for merge conflict
[official-gcc.git] / libgo / go / xml / embed_test.go
blobabfe781acdf18a8a453e39bded11128bda843d35
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.
5 package xml
7 import "testing"
9 type C struct {
10 Name string
11 Open bool
14 type A struct {
15 XMLName Name "http://domain a"
17 B B
18 FieldA string
21 type B struct {
22 XMLName Name "b"
24 FieldB string
27 const _1a = `
28 <?xml version="1.0" encoding="UTF-8"?>
29 <a xmlns="http://domain">
30 <name>KmlFile</name>
31 <open>1</open>
32 <b>
33 <name>Absolute</name>
34 <open>0</open>
35 <fieldb>bar</fieldb>
36 </b>
37 <fielda>foo</fielda>
38 </a>
41 // Tests that embedded structs are marshalled.
42 func TestEmbedded1(t *testing.T) {
43 var a A
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)
53 if !a.Open {
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)
62 if a.B.Open {
63 t.Fatal("Unmarshal: expected 'false' but found otherwise")
67 type A2 struct {
68 XMLName Name "http://domain a"
69 XY string
70 Xy string
73 const _2a = `
74 <?xml version="1.0" encoding="UTF-8"?>
75 <a xmlns="http://domain">
76 <xy>foo</xy>
77 </a>
80 // Tests that conflicting field names get excluded.
81 func TestEmbedded2(t *testing.T) {
82 var a A2
83 if e := Unmarshal(StringReader(_2a), &a); e != nil {
84 t.Fatalf("Unmarshal: %s", e)
86 if a.XY != "" {
87 t.Fatalf("Unmarshal: expected empty string but found '%s'", a.XY)
89 if a.Xy != "" {
90 t.Fatalf("Unmarshal: expected empty string but found '%s'", a.Xy)
94 type A3 struct {
95 XMLName Name "http://domain a"
96 xy string
99 // Tests that private fields are not set.
100 func TestEmbedded3(t *testing.T) {
101 var a A3
102 if e := Unmarshal(StringReader(_2a), &a); e != nil {
103 t.Fatalf("Unmarshal: %s", e)
105 if a.xy != "" {
106 t.Fatalf("Unmarshal: expected empty string but found '%s'", a.xy)
110 type A4 struct {
111 XMLName Name "http://domain a"
112 Any string
115 // Tests that private fields are not set.
116 func TestEmbedded4(t *testing.T) {
117 var a A4
118 if e := Unmarshal(StringReader(_2a), &a); e != nil {
119 t.Fatalf("Unmarshal: %s", e)
121 if a.Any != "foo" {
122 t.Fatalf("Unmarshal: expected 'foo' but found '%s'", a.Any)