]>
Commit | Line | Data |
---|---|---|
30023d12 MG |
1 | #!/usr/bin/perl -wT |
2 | use strict; | |
3 | use warnings; | |
4 | ||
30023d12 MG |
5 | use Test::MockObject; |
6 | use Test::More tests => 16; | |
7 | ||
8 | BEGIN { use_ok('POE::Component::IRC::Plugin::Infobot') }; | |
9 | ||
10 | no warnings 'redefine'; | |
11 | sub POE::Component::IRC::Plugin::Infobot::getstr { | |
12 | my $rstrings = shift; | |
13 | sprintf @{$rstrings}[0], @_ | |
14 | } | |
15 | use warnings 'redefine'; | |
16 | ||
17 | my $last_msg; | |
18 | my $last_ctcp; | |
19 | ||
20 | sub yield { | |
21 | $last_msg = $_[3] if $_[1] eq 'privmsg'; | |
22 | $last_ctcp = $_[3] if $_[1] eq 'ctcp'; | |
23 | } | |
24 | ||
25 | my $mockirc = Test::MockObject->new; | |
26 | $mockirc->mock(yield => \&yield)->set_always(nick_name => 'bot'); | |
27 | ||
28 | my $self = POE::Component::IRC::Plugin::Infobot->new(filename => undef); | |
29 | ||
30 | sub runtest{ | |
31 | my ($message, $expect, $comment, $private) = @_; | |
32 | undef $last_msg; | |
33 | undef $last_ctcp; | |
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) | |
37 | } | |
38 | ||
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'; | |
47 | ||
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'; | |
52 | ||
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; |