grim/gobnc

Update for the new hosting path
draft default tip
2020-04-27, Gary Kramlich
7cd26371cd9c
Update for the new hosting path
package irc
import (
"testing"
. "github.com/onsi/gomega"
)
func TestMessageMarshal(t *testing.T) {
g := NewGomegaWithT(t)
var m Message = "foo"
d, e := m.MarshalIRC()
g.Expect(e).To(BeNil())
g.Expect(d).To(Equal([]byte(":foo")))
}
func TestMessageUnmarshal(t *testing.T) {
g := NewGomegaWithT(t)
var m Message
var e error
e = m.UnmarshalIRC([]byte(":foo"))
g.Expect(e).To(BeNil())
g.Expect(m).To(Equal(Message("foo")))
e = m.UnmarshalIRC([]byte("foo"))
g.Expect(e).To(MatchError(ErrMalformedMessage))
}
// Nick tests
var (
nickTests = map[string]bool{
"": false,
"a": true,
"A": true,
"*": false,
"aa": true,
"Aa": true,
"aA": true,
"1a": false,
"1A": false,
"a1": true,
"A1": true,
"A^": true,
}
)
func TestNickMarshal(t *testing.T) {
g := NewGomegaWithT(t)
for nick, exp := range nickTests {
var n Nick = Nick(nick)
mn, e := n.MarshalNick()
if exp {
g.Expect(e).To(BeNil())
g.Expect(mn).To(Equal([]byte(nick)))
} else {
g.Expect(e).To(MatchError(ErrInvalidNick))
}
}
}
func TestNickUnmarshal(t *testing.T) {
g := NewGomegaWithT(t)
var n Nick
for nick, exp := range nickTests {
err := n.UnmarshalIRC([]byte(nick))
if exp {
g.Expect(err).To(BeNil())
} else {
g.Expect(err).To(Not(BeNil()))
}
}
}