Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(413)

Delta Between Two Patch Sets: src/pkg/encoding/xml/namespace_test.go

Issue 6868044: code review 6868044: encoding/xml: namespace handling
Left Patch Set: diff -r d05272f402ec https://code.google.com/p/go Created 11 years, 3 months ago
Right Patch Set: diff -r 8ea98ec93704 https://code.google.com/p/go Created 11 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/encoding/xml/namespace.go ('k') | src/pkg/encoding/xml/read.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2011 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.
4
5 package xml
6
7 // Tests specific to the context object which is included in Encoder
8 // and Decoder.
9
10 import (
11 "bytes"
12 "reflect"
13 "strings"
14 "testing"
15 )
16
17 func TestMarshalSeries(t *testing.T) {
18 obj1 := XmppErr{}
19 obj2 := XmppErr{}
20 var buf bytes.Buffer
21 enc := NewEncoder(&buf)
22 err := enc.Encode(obj1)
23 if err != nil {
24 t.Fatalf("Encode %v: %s", obj1, err)
25 }
26 err = enc.Encode(obj2)
27 if err != nil {
28 t.Fatalf("Encode %v: %s", obj2, err)
29 }
30 want := `<error xmlns="xmpp1"><Text></Text></error>` +
31 `<error xmlns="xmpp1"><Text></Text></error>`
32 got := buf.String()
33 if got != want {
34 t.Errorf("got:\n%s\nwant:\n%s", got, want)
35 }
36 }
37
38 func TestUnmarshalSeries(t *testing.T) {
39 str := `<error xmlns="xmpp1"></error>` +
40 `<error xmlns="xmpp1"></error>`
41 r := strings.NewReader(str)
42 dec := NewDecoder(r)
43 obj1 := &XmppErr{}
44 obj2 := &XmppErr{}
45 err := dec.Decode(obj1)
46 if err != nil {
47 t.Fatalf("Decode %s: %s", str, err)
48 }
49 err = dec.Decode(obj2)
50 if err != nil {
51 t.Fatalf("Decode %s: %s", str, err)
52 }
53 want1 := &XmppErr{XMLName: Name{Space: "xmpp1", Local: "error"}}
54 want2 := &XmppErr{XMLName: Name{Space: "xmpp1", Local: "error"}}
55 if !reflect.DeepEqual(obj1, want1) {
56 t.Errorf("#1 unmarshal(%q):\nhave %#v\nwant %#v", str, obj1,
57 want1)
58 }
59 if !reflect.DeepEqual(obj2, want2) {
60 t.Errorf("#1 unmarshal(%q):\nhave %#v\nwant %#v", str, obj2,
61 want2)
62 }
63 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b