6 use Test
::More tests
=> 16;
8 BEGIN { use_ok
('POE::Component::IRC::Plugin::Infobot') };
10 no warnings
'redefine';
11 sub POE
::Component
::IRC
::Plugin
::Infobot
::getstr
{
13 sprintf @
{$rstrings}[0], @_
15 use warnings
'redefine';
21 $last_msg = $_[3] if $_[1] eq 'privmsg';
22 $last_ctcp = $_[3] if $_[1] eq 'ctcp';
25 my $mockirc = Test
::MockObject
->new;
26 $mockirc->mock(yield
=> \
&yield
)->set_always(nick_name
=> 'bot');
28 my $self = POE
::Component
::IRC
::Plugin
::Infobot
->new(filename
=> undef);
31 my ($message, $expect, $comment, $private) = @_;
34 $self->S_public($mockirc, \'mgv
!marius
@ieval.ro
', \([ '#chan' ]), \$message) unless $private;
35 $self->S_msg($mockirc, \'mgv
!marius
@ieval.ro
', undef, \$message) if $private;
36 is($last_msg // $last_ctcp, $expect, $comment)
39 runtest 'bot
: a is b
', 'sure
, mgv
', 'add
';
40 runtest 'bot
: a is b
', 'I already had it that way
, mgv
', 'add same factoid twice
';
41 runtest 'bot
: a is c
', '... but a is b
!', 'redefine factoid
';
42 runtest 'a?
', 'a is b
', 'query
';
43 runtest 'bot
: forget a
', 'mgv
: I forgot a
', 'forget
';
44 runtest 'bot
: forget a
', 'I didn
\'t have anything matching a
, mgv
', 'forget inexistent factoid
';
45 runtest 'a?
', undef, 'query
for inexistent factoid
';
46 runtest 'bot
: a?
', 'I don
\'t know
, mgv
', 'addressed query
for inexistent factoid
';
48 runtest 'bot
: b is
<reply
> c
', 'sure
, mgv
', 'add with reply
';
49 runtest 'b?
', 'c
', 'check reply
';
50 runtest 'bot
: c is
<action
> d
', 'sure
, mgv
', 'add with action
';
51 runtest 'c?
', 'ACTION d
', 'check action
';
53 runtest 'x is y
', 'sure
, mgv
', 'private add
', 1;
54 runtest 'x?
', 'x is y
', 'private query
', 1;
55 runtest 'forget x
', 'mgv
: I forgot x
', 'private forget
', 1;