diff --git a/src/xmpp/jid_test.go b/src/xmpp/jid_test.go new file mode 100644 index 0000000..c4a012a --- /dev/null +++ b/src/xmpp/jid_test.go @@ -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() + } +} diff --git a/src/xmpp/xml_test.go b/src/xmpp/xml_test.go new file mode 100644 index 0000000..7b74ad4 --- /dev/null +++ b/src/xmpp/xml_test.go @@ -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() + } +}