mirror of https://github.com/fluffle/goirc
Make parseLine public by renaming it to ParseLine
This commit is contained in:
parent
7711182a72
commit
8f2ab20f4f
|
@ -282,7 +282,7 @@ func (conn *Conn) recv() {
|
|||
s = strings.Trim(s, "\r\n")
|
||||
logging.Debug("<- %s", s)
|
||||
|
||||
if line := parseLine(s); line != nil {
|
||||
if line := ParseLine(s); line != nil {
|
||||
line.Time = time.Now()
|
||||
conn.in <- line
|
||||
} else {
|
||||
|
|
|
@ -241,7 +241,7 @@ func TestRecv(t *testing.T) {
|
|||
}
|
||||
|
||||
// Test that recv does something useful with a line it can't parse
|
||||
// (not that there are many, parseLine is forgiving).
|
||||
// (not that there are many, ParseLine is forgiving).
|
||||
s.nc.Send(":textwithnospaces")
|
||||
if l := reader(); l != nil {
|
||||
t.Errorf("Bad line still caused receive on input channel.")
|
||||
|
@ -342,7 +342,7 @@ func TestRunLoop(t *testing.T) {
|
|||
h002.call()
|
||||
})
|
||||
|
||||
l1 := parseLine(":irc.server.org 001 test :First test line.")
|
||||
l1 := ParseLine(":irc.server.org 001 test :First test line.")
|
||||
c.in <- l1
|
||||
h001.assertNotCalled("001 handler called before runLoop started.")
|
||||
|
||||
|
@ -357,7 +357,7 @@ func TestRunLoop(t *testing.T) {
|
|||
|
||||
// Send another line, just to be sure :-)
|
||||
h002.assertNotCalled("002 handler called before expected.")
|
||||
l2 := parseLine(":irc.server.org 002 test :Second test line.")
|
||||
l2 := ParseLine(":irc.server.org 002 test :Second test line.")
|
||||
c.in <- l2
|
||||
h002.assertWasCalled("002 handler not called while runLoop started.")
|
||||
|
||||
|
|
|
@ -196,6 +196,6 @@ func TestPanicRecovery(t *testing.T) {
|
|||
c.HandleFunc(PRIVMSG, func(conn *Conn, line *Line) {
|
||||
panic("panic!")
|
||||
})
|
||||
c.in <- parseLine(":nick!user@host.com PRIVMSG #channel :OH NO PIGEONS")
|
||||
c.in <- ParseLine(":nick!user@host.com PRIVMSG #channel :OH NO PIGEONS")
|
||||
recovered.assertWasCalled("Failed to recover panic!")
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ func Test001(t *testing.T) {
|
|||
c, s := setUp(t)
|
||||
defer s.tearDown()
|
||||
|
||||
l := parseLine(":irc.server.org 001 test :Welcome to IRC test!ident@somehost.com")
|
||||
l := ParseLine(":irc.server.org 001 test :Welcome to IRC test!ident@somehost.com")
|
||||
// Set up a handler to detect whether connected handler is called from 001
|
||||
hcon := false
|
||||
c.HandleFunc("connected", func(conn *Conn, line *Line) {
|
||||
|
@ -69,7 +69,7 @@ func Test433(t *testing.T) {
|
|||
defer s.tearDown()
|
||||
|
||||
// Call handler with a 433 line, not triggering c.cfg.Me.Renick()
|
||||
c.h_433(parseLine(":irc.server.org 433 test new :Nickname is already in use."))
|
||||
c.h_433(ParseLine(":irc.server.org 433 test new :Nickname is already in use."))
|
||||
s.nc.Expect("NICK new_")
|
||||
|
||||
// In this case, we're expecting the server to send a NICK line
|
||||
|
@ -82,7 +82,7 @@ func Test433(t *testing.T) {
|
|||
// different one before the connection can proceed. No NICK line will be
|
||||
// sent by the server to confirm nick change in this case.
|
||||
s.st.EXPECT().ReNick("test", "test_")
|
||||
c.h_433(parseLine(":irc.server.org 433 test test :Nickname is already in use."))
|
||||
c.h_433(ParseLine(":irc.server.org 433 test test :Nickname is already in use."))
|
||||
s.nc.Expect("NICK test_")
|
||||
|
||||
// Counter-intuitively, c.cfg.Me.Nick will not change in this case. This
|
||||
|
@ -94,7 +94,7 @@ func Test433(t *testing.T) {
|
|||
|
||||
// Test the code path that *doesn't* involve state tracking.
|
||||
c.st = nil
|
||||
c.h_433(parseLine(":irc.server.org 433 test test :Nickname is already in use."))
|
||||
c.h_433(ParseLine(":irc.server.org 433 test test :Nickname is already in use."))
|
||||
s.nc.Expect("NICK test_")
|
||||
|
||||
if c.cfg.Me.Nick != "test_" {
|
||||
|
@ -112,7 +112,7 @@ func TestNICK(t *testing.T) {
|
|||
c.st = nil
|
||||
|
||||
// Call handler with a NICK line changing "our" nick to test1.
|
||||
c.h_NICK(parseLine(":test!test@somehost.com NICK :test1"))
|
||||
c.h_NICK(ParseLine(":test!test@somehost.com NICK :test1"))
|
||||
|
||||
// Verify that our Nick has changed
|
||||
if c.cfg.Me.Nick != "test1" {
|
||||
|
@ -120,7 +120,7 @@ func TestNICK(t *testing.T) {
|
|||
}
|
||||
|
||||
// Send a NICK line for something that isn't us.
|
||||
c.h_NICK(parseLine(":blah!moo@cows.com NICK :milk"))
|
||||
c.h_NICK(ParseLine(":blah!moo@cows.com NICK :milk"))
|
||||
|
||||
// Verify that our Nick hasn't changed
|
||||
if c.cfg.Me.Nick != "test1" {
|
||||
|
@ -129,7 +129,7 @@ func TestNICK(t *testing.T) {
|
|||
|
||||
// Re-enable state tracking and send a line that *should* change nick.
|
||||
c.st = s.st
|
||||
c.h_NICK(parseLine(":test1!test@somehost.com NICK :test2"))
|
||||
c.h_NICK(ParseLine(":test1!test@somehost.com NICK :test2"))
|
||||
|
||||
// Verify that our Nick hasn't changed (should be handled by h_STNICK).
|
||||
if c.cfg.Me.Nick != "test1" {
|
||||
|
@ -143,19 +143,19 @@ func TestCTCP(t *testing.T) {
|
|||
defer s.tearDown()
|
||||
|
||||
// Call handler with CTCP VERSION
|
||||
c.h_CTCP(parseLine(":blah!moo@cows.com PRIVMSG test :\001VERSION\001"))
|
||||
c.h_CTCP(ParseLine(":blah!moo@cows.com PRIVMSG test :\001VERSION\001"))
|
||||
|
||||
// Expect a version reply
|
||||
s.nc.Expect("NOTICE blah :\001VERSION Powered by GoIRC\001")
|
||||
|
||||
// Call handler with CTCP PING
|
||||
c.h_CTCP(parseLine(":blah!moo@cows.com PRIVMSG test :\001PING 1234567890\001"))
|
||||
c.h_CTCP(ParseLine(":blah!moo@cows.com PRIVMSG test :\001PING 1234567890\001"))
|
||||
|
||||
// Expect a ping reply
|
||||
s.nc.Expect("NOTICE blah :\001PING 1234567890\001")
|
||||
|
||||
// Call handler with CTCP UNKNOWN
|
||||
c.h_CTCP(parseLine(":blah!moo@cows.com PRIVMSG test :\001UNKNOWN ctcp\001"))
|
||||
c.h_CTCP(ParseLine(":blah!moo@cows.com PRIVMSG test :\001UNKNOWN ctcp\001"))
|
||||
}
|
||||
|
||||
// Test the handler for JOIN messages
|
||||
|
@ -175,7 +175,7 @@ func TestJOIN(t *testing.T) {
|
|||
|
||||
// Use #test1 to test expected behaviour
|
||||
// Call handler with JOIN by test to #test1
|
||||
c.h_JOIN(parseLine(":test!test@somehost.com JOIN :#test1"))
|
||||
c.h_JOIN(ParseLine(":test!test@somehost.com JOIN :#test1"))
|
||||
|
||||
// Verify that the MODE and WHO commands are sent correctly
|
||||
s.nc.Expect("MODE #test1")
|
||||
|
@ -192,7 +192,7 @@ func TestJOIN(t *testing.T) {
|
|||
)
|
||||
|
||||
// OK, now #test1 exists, JOIN another user we don't know about
|
||||
c.h_JOIN(parseLine(":user1!ident1@host1.com JOIN :#test1"))
|
||||
c.h_JOIN(ParseLine(":user1!ident1@host1.com JOIN :#test1"))
|
||||
|
||||
// Verify that the WHO command is sent correctly
|
||||
s.nc.Expect("WHO user1")
|
||||
|
@ -204,7 +204,7 @@ func TestJOIN(t *testing.T) {
|
|||
s.st.EXPECT().GetNick("user2").Return(nick2),
|
||||
s.st.EXPECT().Associate(chan1, nick2),
|
||||
)
|
||||
c.h_JOIN(parseLine(":user2!ident2@host2.com JOIN :#test1"))
|
||||
c.h_JOIN(ParseLine(":user2!ident2@host2.com JOIN :#test1"))
|
||||
|
||||
// Test error paths
|
||||
gomock.InOrder(
|
||||
|
@ -215,8 +215,8 @@ func TestJOIN(t *testing.T) {
|
|||
s.st.EXPECT().GetChannel("#test2").Return(nil),
|
||||
s.st.EXPECT().GetNick("user2").Return(nick2),
|
||||
)
|
||||
c.h_JOIN(parseLine(":blah!moo@cows.com JOIN :#test2"))
|
||||
c.h_JOIN(parseLine(":user2!ident2@host2.com JOIN :#test2"))
|
||||
c.h_JOIN(ParseLine(":blah!moo@cows.com JOIN :#test2"))
|
||||
c.h_JOIN(ParseLine(":user2!ident2@host2.com JOIN :#test2"))
|
||||
}
|
||||
|
||||
// Test the handler for PART messages
|
||||
|
@ -234,7 +234,7 @@ func TestPART(t *testing.T) {
|
|||
s.st.EXPECT().GetNick("user1").Return(nick1),
|
||||
s.st.EXPECT().Dissociate(chan1, nick1),
|
||||
)
|
||||
c.h_PART(parseLine(":user1!ident1@host1.com PART #test1 :Bye!"))
|
||||
c.h_PART(ParseLine(":user1!ident1@host1.com PART #test1 :Bye!"))
|
||||
}
|
||||
|
||||
// Test the handler for KICK messages
|
||||
|
@ -253,7 +253,7 @@ func TestKICK(t *testing.T) {
|
|||
s.st.EXPECT().GetNick("user1").Return(nick1),
|
||||
s.st.EXPECT().Dissociate(chan1, nick1),
|
||||
)
|
||||
c.h_KICK(parseLine(":test!test@somehost.com KICK #test1 user1 :Bye!"))
|
||||
c.h_KICK(ParseLine(":test!test@somehost.com KICK #test1 user1 :Bye!"))
|
||||
}
|
||||
|
||||
// Test the handler for QUIT messages
|
||||
|
@ -263,7 +263,7 @@ func TestQUIT(t *testing.T) {
|
|||
|
||||
// Have user1 QUIT. All possible errors handled by state tracker \o/
|
||||
s.st.EXPECT().DelNick("user1")
|
||||
c.h_QUIT(parseLine(":user1!ident1@host1.com QUIT :Bye!"))
|
||||
c.h_QUIT(ParseLine(":user1!ident1@host1.com QUIT :Bye!"))
|
||||
}
|
||||
|
||||
// Test the handler for MODE messages
|
||||
|
@ -279,7 +279,7 @@ func TestMODE(t *testing.T) {
|
|||
// don't want them to be, writing accessors for struct fields sucks).
|
||||
// This makes testing whether ParseModes is called correctly harder.
|
||||
s.st.EXPECT().GetChannel("#test1").Return(chan1)
|
||||
c.h_MODE(parseLine(":user1!ident1@host1.com MODE #test1 +sk somekey"))
|
||||
c.h_MODE(ParseLine(":user1!ident1@host1.com MODE #test1 +sk somekey"))
|
||||
if !chan1.Modes.Secret || chan1.Modes.Key != "somekey" {
|
||||
t.Errorf("Channel.ParseModes() not called correctly.")
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ func TestMODE(t *testing.T) {
|
|||
s.st.EXPECT().GetChannel("test").Return(nil),
|
||||
s.st.EXPECT().GetNick("test").Return(c.cfg.Me),
|
||||
)
|
||||
c.h_MODE(parseLine(":test!test@somehost.com MODE test +i"))
|
||||
c.h_MODE(ParseLine(":test!test@somehost.com MODE test +i"))
|
||||
if !c.cfg.Me.Modes.Invisible {
|
||||
t.Errorf("Nick.ParseModes() not called correctly.")
|
||||
}
|
||||
|
@ -303,8 +303,8 @@ func TestMODE(t *testing.T) {
|
|||
s.st.EXPECT().GetChannel("#test2").Return(nil),
|
||||
s.st.EXPECT().GetNick("#test2").Return(nil),
|
||||
)
|
||||
c.h_MODE(parseLine(":user1!ident1@host1.com MODE user1 +w"))
|
||||
c.h_MODE(parseLine(":user1!ident1@host1.com MODE #test2 +is"))
|
||||
c.h_MODE(ParseLine(":user1!ident1@host1.com MODE user1 +w"))
|
||||
c.h_MODE(ParseLine(":user1!ident1@host1.com MODE #test2 +is"))
|
||||
}
|
||||
|
||||
// Test the handler for TOPIC messages
|
||||
|
@ -321,7 +321,7 @@ func TestTOPIC(t *testing.T) {
|
|||
|
||||
// Send a TOPIC line
|
||||
s.st.EXPECT().GetChannel("#test1").Return(chan1)
|
||||
c.h_TOPIC(parseLine(":user1!ident1@host1.com TOPIC #test1 :something something"))
|
||||
c.h_TOPIC(ParseLine(":user1!ident1@host1.com TOPIC #test1 :something something"))
|
||||
|
||||
// Make sure the channel's topic has been changed
|
||||
if chan1.Topic != "something something" {
|
||||
|
@ -330,7 +330,7 @@ func TestTOPIC(t *testing.T) {
|
|||
|
||||
// Check error paths -- send a topic for an unknown channel
|
||||
s.st.EXPECT().GetChannel("#test2").Return(nil)
|
||||
c.h_TOPIC(parseLine(":user1!ident1@host1.com TOPIC #test2 :dark side"))
|
||||
c.h_TOPIC(ParseLine(":user1!ident1@host1.com TOPIC #test2 :dark side"))
|
||||
}
|
||||
|
||||
// Test the handler for 311 / RPL_WHOISUSER
|
||||
|
@ -343,7 +343,7 @@ func Test311(t *testing.T) {
|
|||
|
||||
// Send a 311 reply
|
||||
s.st.EXPECT().GetNick("user1").Return(nick1)
|
||||
c.h_311(parseLine(":irc.server.org 311 test user1 ident1 host1.com * :name"))
|
||||
c.h_311(ParseLine(":irc.server.org 311 test user1 ident1 host1.com * :name"))
|
||||
|
||||
// Verify we now know more about user1
|
||||
if nick1.Ident != "ident1" ||
|
||||
|
@ -354,7 +354,7 @@ func Test311(t *testing.T) {
|
|||
|
||||
// Check error paths -- send a 311 for an unknown nick
|
||||
s.st.EXPECT().GetNick("user2").Return(nil)
|
||||
c.h_311(parseLine(":irc.server.org 311 test user2 ident2 host2.com * :dongs"))
|
||||
c.h_311(ParseLine(":irc.server.org 311 test user2 ident2 host2.com * :dongs"))
|
||||
}
|
||||
|
||||
// Test the handler for 324 / RPL_CHANNELMODEIS
|
||||
|
@ -367,14 +367,14 @@ func Test324(t *testing.T) {
|
|||
|
||||
// Send a 324 reply
|
||||
s.st.EXPECT().GetChannel("#test1").Return(chan1)
|
||||
c.h_324(parseLine(":irc.server.org 324 test #test1 +sk somekey"))
|
||||
c.h_324(ParseLine(":irc.server.org 324 test #test1 +sk somekey"))
|
||||
if !chan1.Modes.Secret || chan1.Modes.Key != "somekey" {
|
||||
t.Errorf("Channel.ParseModes() not called correctly.")
|
||||
}
|
||||
|
||||
// Check error paths -- send 324 for an unknown channel
|
||||
s.st.EXPECT().GetChannel("#test2").Return(nil)
|
||||
c.h_324(parseLine(":irc.server.org 324 test #test2 +pmt"))
|
||||
c.h_324(ParseLine(":irc.server.org 324 test #test2 +pmt"))
|
||||
}
|
||||
|
||||
// Test the handler for 332 / RPL_TOPIC
|
||||
|
@ -392,7 +392,7 @@ func Test332(t *testing.T) {
|
|||
|
||||
// Send a 332 reply
|
||||
s.st.EXPECT().GetChannel("#test1").Return(chan1)
|
||||
c.h_332(parseLine(":irc.server.org 332 test #test1 :something something"))
|
||||
c.h_332(ParseLine(":irc.server.org 332 test #test1 :something something"))
|
||||
|
||||
// Make sure the channel's topic has been changed
|
||||
if chan1.Topic != "something something" {
|
||||
|
@ -401,7 +401,7 @@ func Test332(t *testing.T) {
|
|||
|
||||
// Check error paths -- send 332 for an unknown channel
|
||||
s.st.EXPECT().GetChannel("#test2").Return(nil)
|
||||
c.h_332(parseLine(":irc.server.org 332 test #test2 :dark side"))
|
||||
c.h_332(ParseLine(":irc.server.org 332 test #test2 :dark side"))
|
||||
}
|
||||
|
||||
// Test the handler for 352 / RPL_WHOREPLY
|
||||
|
@ -414,7 +414,7 @@ func Test352(t *testing.T) {
|
|||
|
||||
// Send a 352 reply
|
||||
s.st.EXPECT().GetNick("user1").Return(nick1)
|
||||
c.h_352(parseLine(":irc.server.org 352 test #test1 ident1 host1.com irc.server.org user1 G :0 name"))
|
||||
c.h_352(ParseLine(":irc.server.org 352 test #test1 ident1 host1.com irc.server.org user1 G :0 name"))
|
||||
|
||||
// Verify we now know more about user1
|
||||
if nick1.Ident != "ident1" ||
|
||||
|
@ -427,7 +427,7 @@ func Test352(t *testing.T) {
|
|||
|
||||
// Check that modes are set correctly from WHOREPLY
|
||||
s.st.EXPECT().GetNick("user1").Return(nick1)
|
||||
c.h_352(parseLine(":irc.server.org 352 test #test1 ident1 host1.com irc.server.org user1 H* :0 name"))
|
||||
c.h_352(ParseLine(":irc.server.org 352 test #test1 ident1 host1.com irc.server.org user1 H* :0 name"))
|
||||
|
||||
if !nick1.Modes.Invisible || !nick1.Modes.Oper {
|
||||
t.Errorf("WHO modes of user1 not set correctly.")
|
||||
|
@ -435,7 +435,7 @@ func Test352(t *testing.T) {
|
|||
|
||||
// Check error paths -- send a 352 for an unknown nick
|
||||
s.st.EXPECT().GetNick("user2").Return(nil)
|
||||
c.h_352(parseLine(":irc.server.org 352 test #test2 ident2 host2.com irc.server.org user2 G :0 fooo"))
|
||||
c.h_352(ParseLine(":irc.server.org 352 test #test2 ident2 host2.com irc.server.org user2 G :0 fooo"))
|
||||
}
|
||||
|
||||
// Test the handler for 353 / RPL_NAMREPLY
|
||||
|
@ -480,8 +480,8 @@ func Test353(t *testing.T) {
|
|||
}
|
||||
|
||||
// Send a couple of names replies (complete with trailing space)
|
||||
c.h_353(parseLine(":irc.server.org 353 test = #test1 :test @user1 user2 +voice "))
|
||||
c.h_353(parseLine(":irc.server.org 353 test = #test1 :%halfop @op &admin ~owner "))
|
||||
c.h_353(ParseLine(":irc.server.org 353 test = #test1 :test @user1 user2 +voice "))
|
||||
c.h_353(ParseLine(":irc.server.org 353 test = #test1 :%halfop @op &admin ~owner "))
|
||||
|
||||
if p := privs["user2"]; p.Voice || p.HalfOp || p.Op || p.Admin || p.Owner {
|
||||
t.Errorf("353 handler incorrectly set modes on nick.")
|
||||
|
@ -494,7 +494,7 @@ func Test353(t *testing.T) {
|
|||
|
||||
// Check error paths -- send 353 for an unknown channel
|
||||
s.st.EXPECT().GetChannel("#test2").Return(nil)
|
||||
c.h_353(parseLine(":irc.server.org 353 test = #test2 :test ~user3"))
|
||||
c.h_353(ParseLine(":irc.server.org 353 test = #test2 :test ~user3"))
|
||||
}
|
||||
|
||||
// Test the handler for 671 (unreal specific)
|
||||
|
@ -510,7 +510,7 @@ func Test671(t *testing.T) {
|
|||
|
||||
// Send a 671 reply
|
||||
s.st.EXPECT().GetNick("user1").Return(nick1)
|
||||
c.h_671(parseLine(":irc.server.org 671 test user1 :some ignored text"))
|
||||
c.h_671(ParseLine(":irc.server.org 671 test user1 :some ignored text"))
|
||||
|
||||
// Ensure user1 is now known to be on an SSL connection
|
||||
if !nick1.Modes.SSL {
|
||||
|
@ -519,5 +519,5 @@ func Test671(t *testing.T) {
|
|||
|
||||
// Check error paths -- send a 671 for an unknown nick
|
||||
s.st.EXPECT().GetNick("user2").Return(nil)
|
||||
c.h_671(parseLine(":irc.server.org 671 test user2 :some ignored text"))
|
||||
c.h_671(ParseLine(":irc.server.org 671 test user2 :some ignored text"))
|
||||
}
|
||||
|
|
|
@ -78,8 +78,8 @@ func (line *Line) Public() bool {
|
|||
}
|
||||
|
||||
|
||||
// parseLine() creates a Line from an incoming message from the IRC server.
|
||||
func parseLine(s string) *Line {
|
||||
// ParseLine() creates a Line from an incoming message from the IRC server.
|
||||
func ParseLine(s string) *Line {
|
||||
line := &Line{Raw: s}
|
||||
if s[0] == ':' {
|
||||
// remove a source and parse it
|
||||
|
|
Loading…
Reference in New Issue