]>
Commit | Line | Data |
---|---|---|
30023d12 MG |
1 | #!/usr/bin/perl -wT |
2 | use strict; | |
3 | use warnings; | |
4 | ||
30023d12 | 5 | use Test::MockObject; |
6849c080 | 6 | use Test::More tests => 17; |
30023d12 MG |
7 | |
8 | BEGIN { use_ok('POE::Component::IRC::Plugin::Infobot') }; | |
9 | ||
10 | no warnings 'redefine'; | |
11 | sub POE::Component::IRC::Plugin::Infobot::getstr { | |
ac607520 MG |
12 | my $rstrings = shift; |
13 | sprintf @{$rstrings}[0], @_ | |
30023d12 MG |
14 | } |
15 | use warnings 'redefine'; | |
16 | ||
17 | my $last_msg; | |
18 | my $last_ctcp; | |
19 | ||
20 | sub yield { | |
ac607520 MG |
21 | $last_msg = $_[3] if $_[1] eq 'privmsg'; |
22 | $last_ctcp = $_[3] if $_[1] eq 'ctcp'; | |
30023d12 MG |
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{ | |
ac607520 MG |
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) | |
30023d12 MG |
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'; | |
6849c080 | 45 | runtest '!forget a', 'I didn\'t have anything matching a, mgv', '!forget'; |
30023d12 MG |
46 | runtest 'a?', undef, 'query for inexistent factoid'; |
47 | runtest 'bot: a?', 'I don\'t know, mgv', 'addressed query for inexistent factoid'; | |
48 | ||
49 | runtest 'bot: b is <reply> c', 'sure, mgv', 'add with reply'; | |
50 | runtest 'b?', 'c', 'check reply'; | |
51 | runtest 'bot: c is <action> d', 'sure, mgv', 'add with action'; | |
52 | runtest 'c?', 'ACTION d', 'check action'; | |
53 | ||
54 | runtest 'x is y', 'sure, mgv', 'private add', 1; | |
55 | runtest 'x?', 'x is y', 'private query', 1; | |
56 | runtest 'forget x', 'mgv: I forgot x', 'private forget', 1; |