Some JID and XML writer tests.

This commit is contained in:
Matt Goodall 2012-07-11 15:57:06 +01:00
parent 9013ad6a6a
commit de92cf1a55
2 changed files with 75 additions and 0 deletions

36
src/xmpp/jid_test.go Normal file
View File

@ -0,0 +1,36 @@
package xmpp
import "testing"
func TestBare(t *testing.T) {
if (JID{"node", "domain", "resource"}).Bare() != "node@domain" {
t.FailNow()
}
}
func TestFull(t *testing.T) {
if (JID{"node", "domain", "resource"}).Full() != "node@domain/resource" {
t.FailNow()
}
if (JID{"node", "domain", ""}).Full() != "node@domain" {
t.FailNow()
}
if (JID{"", "domain", ""}).Full() != "domain" {
t.FailNow()
}
}
func TestParseJID(t *testing.T) {
jid, _ := ParseJID("node@domain/resource")
if jid != (JID{"node", "domain", "resource"}) {
t.FailNow()
}
jid, _ = ParseJID("node@domain")
if jid != (JID{"node", "domain", ""}) {
t.FailNow()
}
jid, _ = ParseJID("domain")
if jid != (JID{"", "domain", ""}) {
t.FailNow()
}
}

39
src/xmpp/xml_test.go Normal file
View File

@ -0,0 +1,39 @@
package xmpp
import (
"bytes"
"encoding/xml"
"testing"
)
func TestWriteNameLocal(t *testing.T) {
buf := new(bytes.Buffer)
writeXMLName(buf, xml.Name{"", "foo"})
if buf.String() != "foo" {
t.Fail()
}
}
func TestWriteName(t *testing.T) {
buf := new(bytes.Buffer)
writeXMLName(buf, xml.Name{"space", "foo"})
if buf.String() != "space:foo" {
t.Fail()
}
}
func TestWriteAttrLocal(t *testing.T) {
buf := new(bytes.Buffer)
writeXMLAttr(buf, xml.Attr{xml.Name{"", "foo"}, "bar"})
if buf.String() != "foo='bar'" {
t.Fail()
}
}
func TestWriteAttr(t *testing.T) {
buf := new(bytes.Buffer)
writeXMLAttr(buf, xml.Attr{xml.Name{"space", "foo"}, "bar"})
if buf.String() != "space:foo='bar'" {
t.Fail()
}
}