~samwhited/xmpp

ee35379eefc058c4117833cc148fc49f83f86a90 — Sam Whited 5 years ago c6eea89
jid: Fix tests
3 files changed, 8 insertions(+), 11 deletions(-)

M jid/benchmark_test.go
M jid/jid.go
M jid/jid_test.go
M jid/benchmark_test.go => jid/benchmark_test.go +3 -3
@@ 16,19 16,19 @@ func BenchmarkSplit(b *testing.B) {

func BenchmarkParseString(b *testing.B) {
	for i := 0; i < b.N; i++ {
		ParseString("user@example.com/resource")
		Parse("user@example.com/resource")
	}
}

func BenchmarkParseStringIPv4(b *testing.B) {
	for i := 0; i < b.N; i++ {
		ParseString("user@127.0.0.1/resource")
		Parse("user@127.0.0.1/resource")
	}
}

func BenchmarkParseStringIPv6(b *testing.B) {
	for i := 0; i < b.N; i++ {
		ParseString("user@[::1]/resource")
		Parse("user@[::1]/resource")
	}
}


M jid/jid.go => jid/jid.go +3 -3
@@ 159,12 159,12 @@ func (j *JID) Copy() *JID {

// Satisfies the net.Addr interface by returning the name of the network
// ("xmpp").
func (j JID) Network() string {
func (j *JID) Network() string {
	return "xmpp"
}

// String converts an JID to its string representation.
func (j JID) String() string {
func (j *JID) String() string {
	s := j.domainpart
	if j.localpart != "" {
		s = j.localpart + "@" + s


@@ 183,7 183,7 @@ func (j *JID) Equal(j2 JID) bool {

// MarshalXMLAttr satisfies the MarshalerAttr interface and marshals the JID as
// an XML attribute.
func (j JID) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
func (j *JID) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
	return xml.Attr{Name: name, Value: j.String()}, nil
}


M jid/jid_test.go => jid/jid_test.go +2 -5
@@ 13,12 13,9 @@ import (

// Compile time check ot make sure that JID and *JID match several interfaces.
var _ fmt.Stringer = (*JID)(nil)
var _ fmt.Stringer = JID{}
var _ xml.MarshalerAttr = (*JID)(nil)
var _ xml.MarshalerAttr = JID{}
var _ xml.UnmarshalerAttr = (*JID)(nil)
var _ net.Addr = (*JID)(nil)
var _ net.Addr = JID{}

func TestValidJIDs(t *testing.T) {
	for _, jid := range []struct {


@@ 34,7 31,7 @@ func TestValidJIDs(t *testing.T) {
		{"mercutio@example.net//@", "mercutio", "example.net", "/@"},
		{"mercutio@example.net//@//", "mercutio", "example.net", "/@//"},
	} {
		j, err := ParseString(jid.jid)
		j, err := Parse(jid.jid)
		switch {
		case err != nil:
			t.Log(err)


@@ 63,7 60,7 @@ func TestInvalidJIDs(t *testing.T) {
		"example.com/" + invalidutf8,
		"lp@/rp",
	} {
		_, err := ParseString(jid)
		_, err := Parse(jid)
		if err == nil {
			t.Logf("Expected JID %s to fail", jid)
			t.Fail()