xmpp/structs_test.go
changeset 183 b4bd77d58a3e
parent 178 ccfebbd9f49b
--- a/xmpp/structs_test.go	Sun Feb 09 09:50:38 2014 -0700
+++ b/xmpp/structs_test.go	Sun Feb 09 09:52:28 2014 -0700
@@ -23,28 +23,19 @@
 }
 
 func TestJid(t *testing.T) {
-	str := "user@domain/res"
-	jid := &JID{}
-	if err := jid.Set(str); err != nil {
-		t.Errorf("Set(%s) failed: %s", str, err)
-	}
-	assertEquals(t, "user", jid.Node)
-	assertEquals(t, "domain", jid.Domain)
-	assertEquals(t, "res", jid.Resource)
-	assertEquals(t, str, jid.String())
+	jid := JID("user@domain/res")
+	assertEquals(t, "user", jid.Node())
+	assertEquals(t, "domain", jid.Domain())
+	assertEquals(t, "res", jid.Resource())
 
-	str = "domain.tld"
-	if err := jid.Set(str); err != nil {
-		t.Errorf("Set(%s) failed: %s", str, err)
+	jid = "domain.tld"
+	if jid.Node() != "" {
+		t.Errorf("Node: %v\n", jid.Node())
 	}
-	if jid.Node != "" {
-		t.Errorf("Node: %v\n", jid.Node)
+	assertEquals(t, "domain.tld", jid.Domain())
+	if jid.Resource() != "" {
+		t.Errorf("Resource: %v\n", jid.Resource())
 	}
-	assertEquals(t, "domain.tld", jid.Domain)
-	if jid.Resource != "" {
-		t.Errorf("Resource: %v\n", jid.Resource)
-	}
-	assertEquals(t, str, jid.String())
 }
 
 func assertMarshal(t *testing.T, expected string, marshal interface{}) {
@@ -108,8 +99,8 @@
 }
 
 func TestMarshalEscaping(t *testing.T) {
-	msg := &Message{Body: &Generic{XMLName: xml.Name{Local: "body"},
-		Chardata: `&<!-- "`}}
+	msg := &Message{Body: []Text{Text{XMLName: xml.Name{Local: "body"},
+		Chardata: `&<!-- "`}}}
 	exp := `<message xmlns="jabber:client"><body>&amp;&lt;!-- &#34;</body></message>`
 	assertMarshal(t, exp, msg)
 }
@@ -118,12 +109,13 @@
 	str := `<message to="a@b.c"><body>foo!</body></message>`
 	r := strings.NewReader(str)
 	ch := make(chan interface{})
-	go recvXml(r, ch, make(map[xml.Name]reflect.Type))
+	cl := &Client{}
+	go cl.recvXml(r, ch, make(map[xml.Name]reflect.Type))
 	obs := <-ch
 	exp := &Message{XMLName: xml.Name{Local: "message", Space: "jabber:client"},
 		Header: Header{To: "a@b.c", Innerxml: "<body>foo!</body>"},
-		Body: &Generic{XMLName: xml.Name{Local: "body", Space: "jabber:client"},
-			Chardata: "foo!"}}
+		Body: []Text{Text{XMLName: xml.Name{Local: "body", Space: "jabber:client"},
+			Chardata: "foo!"}}}
 	if !reflect.DeepEqual(obs, exp) {
 		t.Errorf("read %s\ngot:  %#v\nwant: %#v\n", str, obs, exp)
 	}