~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/xml/read_test.go

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-08-03 17:04:59 UTC
  • mfrom: (14.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110803170459-wzd99m3567y80ila
Tags: 1:59-1
* Imported Upstream version 59
* Refresh patches to a new release
* Fix FTBFS on ARM (Closes: #634270)
* Update version.bash to work with Debian packaging and not hg
  repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
</summary></entry></feed>          `
79
79
 
80
80
type Feed struct {
81
 
        XMLName Name "http://www.w3.org/2005/Atom feed"
 
81
        XMLName Name `xml:"http://www.w3.org/2005/Atom feed"`
82
82
        Title   string
83
83
        Id      string
84
84
        Link    []Link
97
97
}
98
98
 
99
99
type Link struct {
100
 
        Rel  string "attr"
101
 
        Href string "attr"
 
100
        Rel  string `xml:"attr"`
 
101
        Href string `xml:"attr"`
102
102
}
103
103
 
104
104
type Person struct {
105
105
        Name     string
106
106
        URI      string
107
107
        Email    string
108
 
        InnerXML string "innerxml"
 
108
        InnerXML string `xml:"innerxml"`
109
109
}
110
110
 
111
111
type Text struct {
112
 
        Type string "attr"
113
 
        Body string "chardata"
 
112
        Type string `xml:"attr"`
 
113
        Body string `xml:"chardata"`
114
114
}
115
115
 
116
116
type Time string
255
255
}
256
256
 
257
257
type PathTestA struct {
258
 
        Items         []PathTestItem ">item1"
 
258
        Items         []PathTestItem `xml:">item1"`
259
259
        Before, After string
260
260
}
261
261
 
262
262
type PathTestB struct {
263
 
        Other         []PathTestItem "items>Item1"
 
263
        Other         []PathTestItem `xml:"items>Item1"`
264
264
        Before, After string
265
265
}
266
266
 
267
267
type PathTestC struct {
268
 
        Values1       []string "items>item1>value"
269
 
        Values2       []string "items>item2>value"
 
268
        Values1       []string `xml:"items>item1>value"`
 
269
        Values2       []string `xml:"items>item2>value"`
270
270
        Before, After string
271
271
}
272
272
 
275
275
}
276
276
 
277
277
type PathTestD struct {
278
 
        Other         PathTestSet "items>"
 
278
        Other         PathTestSet `xml:"items>"`
279
279
        Before, After string
280
280
}
281
281
 
299
299
}
300
300
 
301
301
type BadPathTestA struct {
302
 
        First  string "items>item1"
303
 
        Other  string "items>item2"
304
 
        Second string "items>"
 
302
        First  string `xml:"items>item1"`
 
303
        Other  string `xml:"items>item2"`
 
304
        Second string `xml:"items>"`
305
305
}
306
306
 
307
307
type BadPathTestB struct {
308
 
        Other  string "items>item2>value"
309
 
        First  string "items>item1"
310
 
        Second string "items>item1>value"
 
308
        Other  string `xml:"items>item2>value"`
 
309
        First  string `xml:"items>item1"`
 
310
        Second string `xml:"items>item1>value"`
311
311
}
312
312
 
313
313
var badPathTests = []struct {
325
325
                }
326
326
        }
327
327
}
 
328
 
 
329
func TestUnmarshalAttrs(t *testing.T) {
 
330
        var f AttrTest
 
331
        if err := Unmarshal(StringReader(attrString), &f); err != nil {
 
332
                t.Fatalf("Unmarshal: %s", err)
 
333
        }
 
334
        if !reflect.DeepEqual(f, attrStruct) {
 
335
                t.Fatalf("have %#v\nwant %#v", f, attrStruct)
 
336
        }
 
337
}
 
338
 
 
339
type AttrTest struct {
 
340
        Test1 Test1
 
341
        Test2 Test2
 
342
}
 
343
 
 
344
type Test1 struct {
 
345
        Int   int     `xml:"attr"`
 
346
        Float float64 `xml:"attr"`
 
347
        Uint8 uint8   `xml:"attr"`
 
348
}
 
349
 
 
350
type Test2 struct {
 
351
        Bool bool `xml:"attr"`
 
352
}
 
353
 
 
354
const attrString = `
 
355
<?xml version="1.0" charset="utf-8"?>
 
356
<attrtest>
 
357
  <test1 int="8" float="23.5" uint8="255"/>
 
358
  <test2 bool="true"/>
 
359
</attrtest>
 
360
`
 
361
 
 
362
var attrStruct = AttrTest{
 
363
        Test1: Test1{
 
364
                Int:   8,
 
365
                Float: 23.5,
 
366
                Uint8: 255,
 
367
        },
 
368
        Test2: Test2{
 
369
                Bool: true,
 
370
        },
 
371
}