2011-10-22 22:58:06 +00:00
|
|
|
package state
|
|
|
|
|
2014-12-31 13:17:28 +00:00
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func compareNick(t *testing.T, nk *nick) {
|
|
|
|
n := nk.Nick()
|
|
|
|
if n.Nick != nk.nick || n.Ident != nk.ident || n.Host != nk.host || n.Name != nk.name ||
|
|
|
|
!n.Modes.Equals(nk.modes) || len(n.Channels) != len(nk.chans) {
|
|
|
|
t.Errorf("Nick not duped correctly from internal state.")
|
|
|
|
}
|
|
|
|
for ch, cp := range nk.chans {
|
|
|
|
if other, ok := n.Channels[ch.name]; !ok || !cp.Equals(other) {
|
|
|
|
t.Errorf("Channel not duped correctly from internal state.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-22 22:58:06 +00:00
|
|
|
|
|
|
|
func TestNewNick(t *testing.T) {
|
2014-12-31 13:17:28 +00:00
|
|
|
nk := newNick("test1")
|
2011-10-22 22:58:06 +00:00
|
|
|
|
2014-12-31 13:17:28 +00:00
|
|
|
if nk.nick != "test1" {
|
2011-10-22 22:58:06 +00:00
|
|
|
t.Errorf("Nick not created correctly by NewNick()")
|
|
|
|
}
|
|
|
|
if len(nk.chans) != 0 || len(nk.lookup) != 0 {
|
|
|
|
t.Errorf("Nick maps contain data after NewNick()")
|
|
|
|
}
|
2014-12-31 13:17:28 +00:00
|
|
|
compareNick(t, nk)
|
2011-10-22 22:58:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddChannel(t *testing.T) {
|
2014-12-31 13:17:28 +00:00
|
|
|
nk := newNick("test1")
|
|
|
|
ch := newChannel("#test1")
|
2011-10-22 22:58:06 +00:00
|
|
|
cp := new(ChanPrivs)
|
|
|
|
|
|
|
|
nk.addChannel(ch, cp)
|
|
|
|
|
|
|
|
if len(nk.chans) != 1 || len(nk.lookup) != 1 {
|
2011-10-27 17:43:34 +00:00
|
|
|
t.Errorf("Channel lists not updated correctly for add.")
|
2011-10-22 22:58:06 +00:00
|
|
|
}
|
|
|
|
if c, ok := nk.chans[ch]; !ok || c != cp {
|
|
|
|
t.Errorf("Channel #test1 not properly stored in chans map.")
|
|
|
|
}
|
|
|
|
if c, ok := nk.lookup["#test1"]; !ok || c != ch {
|
|
|
|
t.Errorf("Channel #test1 not properly stored in lookup map.")
|
|
|
|
}
|
2014-12-31 13:17:28 +00:00
|
|
|
compareNick(t, nk)
|
2011-10-27 17:43:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDelChannel(t *testing.T) {
|
2014-12-31 13:17:28 +00:00
|
|
|
nk := newNick("test1")
|
|
|
|
ch := newChannel("#test1")
|
2011-10-27 17:43:34 +00:00
|
|
|
cp := new(ChanPrivs)
|
|
|
|
|
|
|
|
nk.addChannel(ch, cp)
|
|
|
|
nk.delChannel(ch)
|
|
|
|
if len(nk.chans) != 0 || len(nk.lookup) != 0 {
|
|
|
|
t.Errorf("Channel lists not updated correctly for del.")
|
|
|
|
}
|
|
|
|
if c, ok := nk.chans[ch]; ok || c != nil {
|
|
|
|
t.Errorf("Channel #test1 not properly removed from chans map.")
|
|
|
|
}
|
|
|
|
if c, ok := nk.lookup["#test1"]; ok || c != nil {
|
|
|
|
t.Errorf("Channel #test1 not properly removed from lookup map.")
|
|
|
|
}
|
2014-12-31 13:17:28 +00:00
|
|
|
compareNick(t, nk)
|
2011-10-22 22:58:06 +00:00
|
|
|
}
|
2011-11-03 03:01:50 +00:00
|
|
|
|
2011-11-03 04:15:12 +00:00
|
|
|
func TestNickParseModes(t *testing.T) {
|
2014-12-31 13:17:28 +00:00
|
|
|
nk := newNick("test1")
|
|
|
|
md := nk.modes
|
2011-11-03 03:01:50 +00:00
|
|
|
|
|
|
|
// Modes should all be false for a new nick
|
|
|
|
if md.Invisible || md.Oper || md.WallOps || md.HiddenHost || md.SSL {
|
|
|
|
t.Errorf("Modes for new nick set to true.")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set a couple of modes, for testing.
|
|
|
|
md.Invisible = true
|
|
|
|
md.HiddenHost = true
|
|
|
|
|
|
|
|
// Parse a mode line that flips one true to false and two false to true
|
2014-12-31 13:17:28 +00:00
|
|
|
nk.parseModes("+z-x+w")
|
2011-11-03 03:01:50 +00:00
|
|
|
|
2014-12-31 13:17:28 +00:00
|
|
|
compareNick(t, nk)
|
2011-11-03 03:01:50 +00:00
|
|
|
if !md.Invisible || md.Oper || !md.WallOps || md.HiddenHost || !md.SSL {
|
|
|
|
t.Errorf("Modes not flipped correctly by ParseModes.")
|
|
|
|
}
|
|
|
|
}
|