forked from chteufleur/go-xmpp
Some JID and XML writer tests.
This commit is contained in:
parent
9013ad6a6a
commit
de92cf1a55
|
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue