# HG changeset patch # User Chris Jones # Date 1356739640 25200 # Node ID a058e33c16668203f3964282c90f0b2f00900889 # Parent bee6cc13179864b8de757f38a29f9ffd3c7bac2a Updated for the latest revision of the encoding/xml fixes: The context object owned by Encoder and Decoder isn't directly accessible. Also improved the output from the two assert functions to show the info of the caller rather than the assert function itself. diff -r bee6cc131798 -r a058e33c1666 stream.go --- a/stream.go Sun Dec 16 23:06:54 2012 -0700 +++ b/stream.go Fri Dec 28 17:07:20 2012 -0700 @@ -87,9 +87,13 @@ } defer close(ch) - p := xml.NewDecoder(r) - p.Context.Map[""] = NsClient - p.Context.Map["stream"] = NsStream + // This trick loads our namespaces into the parser. + nsstr := fmt.Sprintf(``, + NsClient, NsStream) + nsrdr := strings.NewReader(nsstr) + p := xml.NewDecoder(io.MultiReader(nsrdr, r)) + p.Token() + Loop: for { // Sniff the next token on the stream. @@ -206,8 +210,6 @@ }(w) enc := xml.NewEncoder(w) - enc.Context.Map[NsClient] = "" - enc.Context.Map[NsStream] = "stream" for obj := range ch { if st, ok := obj.(*stream); ok { diff -r bee6cc131798 -r a058e33c1666 structs_test.go --- a/structs_test.go Sun Dec 16 23:06:54 2012 -0700 +++ b/structs_test.go Fri Dec 28 17:07:20 2012 -0700 @@ -7,13 +7,20 @@ import ( "bytes" "encoding/xml" + "fmt" + "os" + "runtime" "testing" ) func assertEquals(t *testing.T, expected, observed string) { if expected != observed { - t.Errorf("Expected:\n%s\nObserved:\n%s\n", expected, - observed) + file := "unknown" + line := 0 + _, file, line, _ = runtime.Caller(1) + fmt.Fprintf(os.Stderr, "%s:%d: Expected:\n%s\nObserved:\n%s\n", + file, line, expected, observed) + t.Fail() } } @@ -45,14 +52,19 @@ func assertMarshal(t *testing.T, expected string, marshal interface{}) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) - enc.Context.Map[NsClient] = "" - enc.Context.Map[NsStream] = "stream" err := enc.Encode(marshal) if err != nil { t.Errorf("Marshal error for %s: %s", marshal, err) } observed := buf.String() - assertEquals(t, expected, observed) + if expected != observed { + file := "unknown" + line := 0 + _, file, line, _ = runtime.Caller(1) + fmt.Fprintf(os.Stderr, "%s:%d: Expected:\n%s\nObserved:\n%s\n", + file, line, expected, observed) + t.Fail() + } } func TestStreamMarshal(t *testing.T) { @@ -76,15 +88,15 @@ func TestStreamErrorMarshal(t *testing.T) { name := xml.Name{Space: NsStreams, Local: "ack"} e := &streamError{Any: Generic{XMLName: name}} - exp := `` + exp := `` assertMarshal(t, exp, e) txt := errText{Lang: "pt", Text: "things happen"} e = &streamError{Any: Generic{XMLName: name}, Text: &txt} - exp = `things happen` + `" xml:lang="pt">things happen` assertMarshal(t, exp, e) } diff -r bee6cc131798 -r a058e33c1666 xmpp_test.go --- a/xmpp_test.go Sun Dec 16 23:06:54 2012 -0700 +++ b/xmpp_test.go Fri Dec 28 17:07:20 2012 -0700 @@ -81,14 +81,14 @@ func TestWriteError(t *testing.T) { se := &streamError{Any: Generic{XMLName: xml.Name{Local: "blah"}}} str := testWrite(se) - exp := `` + exp := `` assertEquals(t, exp, str) se = &streamError{Any: Generic{XMLName: xml.Name{Space: NsStreams, Local: "foo"}}, Text: &errText{Lang: "ru", Text: "Пошёл ты"}} str = testWrite(se) - exp = `Пошёл ты` + `" xml:lang="ru">Пошёл ты` assertEquals(t, exp, str) }