From 4dcf7d03c591fda57b24606280ce742f13c166a9 Mon Sep 17 00:00:00 2001 From: tpltnt Date: Sun, 16 Feb 2014 01:10:08 +0100 Subject: [PATCH] hasValidValues() -> has ConnectionValues() --- irc.go | 10 +++++++--- irc_test.go | 38 +++++++++++++++++++++++++++----------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/irc.go b/irc.go index 7fb086c..5948ee8 100644 --- a/irc.go +++ b/irc.go @@ -389,9 +389,9 @@ func IRC(nick, user string) *Connection { return irc } -// Returns true if all values in struct make -// somewhat sense. -func (irc *Connection) hasValidValues() bool { +// Returns true if all values in struct allow for +// establishing a connection. +func (irc *Connection) hasConnectionValues() bool { if 0 == len(irc.nick) { return false } @@ -404,6 +404,10 @@ func (irc *Connection) hasValidValues() bool { return false } + if 0 == len(irc.server) { + return false + } + if nil == irc.Log { return false } diff --git a/irc_test.go b/irc_test.go index 8a71e2b..a829c3c 100644 --- a/irc_test.go +++ b/irc_test.go @@ -163,25 +163,27 @@ func TestIRCemptyUser(t *testing.T) { } -func TestHasValidValues0(t *testing.T) { +func TestHasConnectionValues0(t *testing.T) { irccon := IRC("go-eventirc", "go-eventirc") if nil == irccon { t.Error("creating IRC struct failed") } - if false == irccon.hasValidValues() { + irccon.server = "foo" + if false == irccon.hasConnectionValues() { t.Error("valid struct not detected as such") } } -func TestHasValidValues1(t *testing.T) { +func TestHasConnectionValues1(t *testing.T) { irccon := IRC("go-eventirc", "go-eventirc") if nil == irccon { t.Error("creating IRC struct failed") } + irccon.server = "foo" irccon.Version = "" - if irccon.hasValidValues() { + if irccon.hasConnectionValues() { t.Error("empty 'Version' not detected") } } @@ -191,33 +193,47 @@ func TestHasValidValues2(t *testing.T) { if nil == irccon { t.Error("creating IRC struct failed") } + irccon.server = "foo" irccon.nick = "" - if irccon.hasValidValues() { + if irccon.hasConnectionValues() { t.Error("empty 'nick' not detected") } } -func TestHasValidValues3(t *testing.T) { +func TestHasConnectionValues3(t *testing.T) { irccon := IRC("go-eventirc", "go-eventirc") if nil == irccon { t.Error("creating IRC struct failed") } + irccon.server = "foo" irccon.user = "" - if irccon.hasValidValues() { + if irccon.hasConnectionValues() { t.Error("empty 'user' not detected") } } -func TestHasValidValues4(t *testing.T) { +func TestHasConnectionValues4(t *testing.T) { + irccon := IRC("go-eventirc", "go-eventirc") + if nil == irccon { + t.Error("creating IRC struct failed") + } + irccon.server = "foo" + + irccon.Log = nil + if irccon.hasConnectionValues() { + t.Error("nil pointer 'Log' not detected") + } +} + +func TestHasConnectionValues5(t *testing.T) { irccon := IRC("go-eventirc", "go-eventirc") if nil == irccon { t.Error("creating IRC struct failed") } - irccon.Log = nil - if irccon.hasValidValues() { - t.Error("nil pointer 'Log' not detected") + if irccon.hasConnectionValues() { + t.Error("empty 'server' not detected") } }