factor/extra/irc/client/client-tests.factor

86 lines
3.7 KiB
Factor
Raw Normal View History

USING: kernel tools.test accessors arrays sequences qualified
2008-06-03 18:53:27 -04:00
io.streams.string io.streams.duplex namespaces threads
2008-07-10 19:11:08 -04:00
calendar irc.client.private irc.client irc.messages.private
concurrency.mailboxes classes assocs ;
2008-07-10 19:11:08 -04:00
EXCLUDE: irc.messages => join ;
RENAME: join irc.messages => join_
IN: irc.client.tests
! Utilities
: <test-stream> ( lines -- stream )
"\n" join <string-reader> <string-writer> <duplex-stream> ;
: make-client ( lines -- irc-client )
"someserver" irc-port "factorbot" f <irc-profile> <irc-client>
swap [ 2nip <test-stream> f ] curry >>connect ;
2008-06-03 18:53:27 -04:00
: set-nick ( irc-client nickname -- )
2008-06-30 11:31:21 -04:00
swap profile>> (>>nickname) ;
2008-06-03 18:53:27 -04:00
: with-dummy-client ( quot -- )
rot with-variable ; inline
2008-06-03 18:53:27 -04:00
{ "" } make-client dup "factorbot" set-nick current-irc-client [
2008-06-30 11:31:21 -04:00
{ t } [ irc> profile>> nickname>> me? ] unit-test
2008-06-30 11:31:21 -04:00
{ "factorbot" } [ irc> profile>> nickname>> ] unit-test
{ "someuser" } [ "someuser!n=user@some.where" parse-name ] unit-test
{ "#factortest" } [ ":someuser!n=user@some.where PRIVMSG #factortest :hi"
parse-irc-line irc-message-origin ] unit-test
{ "someuser" } [ ":someuser!n=user@some.where PRIVMSG factorbot :hi"
parse-irc-line irc-message-origin ] unit-test
] with-variable
2008-06-03 18:53:27 -04:00
! Test login and nickname set
{ "factorbot" } [ { "NOTICE AUTH :*** Looking up your hostname..."
"NOTICE AUTH :*** Checking ident"
"NOTICE AUTH :*** Found your hostname"
"NOTICE AUTH :*** No identd (auth) response"
":some.where 001 factorbot :Welcome factorbot"
} make-client
[ connect-irc ] keep 1 seconds sleep
profile>> nickname>> ] unit-test
2008-06-03 18:53:27 -04:00
{ join_ "#factortest" } [
{ ":factorbot!n=factorbo@some.where JOIN :#factortest"
":ircserver.net MODE #factortest +ns"
":ircserver.net 353 factorbot @ #factortest :@factorbot "
":ircserver.net 366 factorbot #factortest :End of /NAMES list."
":ircserver.net 477 factorbot #factortest :[ircserver-info] blah blah"
} make-client dup "factorbot" set-nick
[ connect-irc ] keep 1 seconds sleep
join-messages>> 1 seconds mailbox-get-timeout
[ class ] [ trailing>> ] bi ] unit-test
{ +join+ "somebody" } [
{ ":somebody!n=somebody@some.where JOIN :#factortest"
} make-client dup "factorbot" set-nick
[ listeners>> [ "#factortest" [ <irc-channel-listener> ] keep ] dip set-at ]
[ connect-irc ]
[ listeners>> [ "#factortest" ] dip at
[ read-message drop ] [ read-message drop ] [ read-message ] tri ] tri
[ action>> ] [ nick>> ] bi
] unit-test
2008-07-18 15:36:40 -04:00
{ privmsg "#factortest" "hello" } [
{ ":somebody!n=somebody@some.where PRIVMSG #factortest :hello"
} make-client dup "factorbot" set-nick
[ listeners>> [ "#factortest" [ <irc-channel-listener> ] keep ] dip set-at ]
[ connect-irc ]
[ listeners>> [ "#factortest" ] dip at
[ read-message drop ] [ read-message ] bi ] tri
[ class ] [ name>> ] [ trailing>> ] tri
] unit-test
{ privmsg "factorbot" "hello" } [
{ ":somedude!n=user@isp.net PRIVMSG factorbot :hello"
} make-client dup "factorbot" set-nick
[ listeners>> [ "somedude" [ <irc-nick-listener> ] keep ] dip set-at ]
[ connect-irc ]
[ listeners>> [ "somedude" ] dip at
[ read-message drop ] [ read-message ] bi ] tri
[ class ] [ name>> ] [ trailing>> ] tri
] unit-test