diff -r a01e06faf0db -r 4dabfef08c8c structs_test.go --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/structs_test.go Sat Dec 24 09:55:26 2011 -0700 @@ -0,0 +1,50 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package xmpp + +import ( + "bytes" + "testing" + "xml" +) + +func TestStreamMarshal(t *testing.T) { + s := &Stream{to: "bob"} + exp := `` + assertMarshal(t, exp, s) + + s = &Stream{to: "bob", from: "alice", id: "#3", version: "5.3"} + exp = `` + assertMarshal(t, exp, s) + + s = &Stream{lang: "en_US"} + exp = `` + assertMarshal(t, exp, s) +} + +func TestStreamErrorMarshal(t *testing.T) { + name := xml.Name{Space: nsStreams, Local: "ack"} + e := &StreamError{cond: definedCondition{name}} + exp := ``; + assertMarshal(t, exp, e) + + txt := errText{Lang: "pt", text: "things happen"} + e = &StreamError{cond: definedCondition{name}, text: &txt} + exp = `things happen` + assertMarshal(t, exp, e) +} + +func assertMarshal(t *testing.T, expected string, marshal interface{}) { + buf := bytes.NewBuffer(nil) + xml.Marshal(buf, marshal) + observed := string(buf.Bytes()) + if expected != observed { + t.Errorf("Expected:\n%s\nObserved:\n%s\n", expected, + observed) + } +}