--- a/structs_test.go Sat Dec 24 09:55:26 2011 -0700
+++ b/structs_test.go Sat Dec 24 11:05:54 2011 -0700
@@ -10,6 +10,45 @@
"xml"
)
+func assertEquals(t *testing.T, expected, observed string) {
+ if expected != observed {
+ t.Errorf("Expected:\n%s\nObserved:\n%s\n", expected,
+ observed)
+ }
+}
+
+func TestJid(t *testing.T) {
+ str := "user@domain/res"
+ jid := &JID{}
+ if !jid.Set(str) {
+ t.Errorf("Set(%s) failed\n", str)
+ }
+ assertEquals(t, "user", *jid.Node)
+ assertEquals(t, "domain", jid.Domain)
+ assertEquals(t, "res", *jid.Resource)
+ assertEquals(t, str, jid.String())
+
+ str = "domain.tld"
+ if !jid.Set(str) {
+ t.Errorf("Set(%s) failed\n", str)
+ }
+ if jid.Node != nil {
+ t.Errorf("Node: %v\n", *jid.Node)
+ }
+ assertEquals(t, "domain.tld", jid.Domain)
+ if jid.Resource != nil {
+ t.Errorf("Resource: %v\n", *jid.Resource)
+ }
+ assertEquals(t, str, jid.String())
+}
+
+func assertMarshal(t *testing.T, expected string, marshal interface{}) {
+ buf := bytes.NewBuffer(nil)
+ xml.Marshal(buf, marshal)
+ observed := string(buf.Bytes())
+ assertEquals(t, expected, observed)
+}
+
func TestStreamMarshal(t *testing.T) {
s := &Stream{to: "bob"}
exp := `<stream:stream to="bob">`
@@ -38,13 +77,3 @@
`" xml:lang="pt">things happen</text></stream:error>`
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)
- }
-}