Reindent code, tests, Makefile.PL
[poe-component-irc-plugin-infobot.git] / t / POE-Component-IRC-Plugin-Infobot.t
CommitLineData
30023d12
MG
1#!/usr/bin/perl -wT
2use strict;
3use warnings;
4
30023d12
MG
5use Test::MockObject;
6use Test::More tests => 16;
7
8BEGIN { use_ok('POE::Component::IRC::Plugin::Infobot') };
9
10no warnings 'redefine';
11sub POE::Component::IRC::Plugin::Infobot::getstr {
ac607520
MG
12 my $rstrings = shift;
13 sprintf @{$rstrings}[0], @_
30023d12
MG
14}
15use warnings 'redefine';
16
17my $last_msg;
18my $last_ctcp;
19
20sub yield {
ac607520
MG
21 $last_msg = $_[3] if $_[1] eq 'privmsg';
22 $last_ctcp = $_[3] if $_[1] eq 'ctcp';
30023d12
MG
23}
24
25my $mockirc = Test::MockObject->new;
26$mockirc->mock(yield => \&yield)->set_always(nick_name => 'bot');
27
28my $self = POE::Component::IRC::Plugin::Infobot->new(filename => undef);
29
30sub 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
39runtest 'bot: a is b', 'sure, mgv', 'add';
40runtest 'bot: a is b', 'I already had it that way, mgv', 'add same factoid twice';
41runtest 'bot: a is c', '... but a is b!', 'redefine factoid';
42runtest 'a?', 'a is b', 'query';
43runtest 'bot: forget a', 'mgv: I forgot a', 'forget';
44runtest 'bot: forget a', 'I didn\'t have anything matching a, mgv', 'forget inexistent factoid';
45runtest 'a?', undef, 'query for inexistent factoid';
46runtest 'bot: a?', 'I don\'t know, mgv', 'addressed query for inexistent factoid';
47
48runtest 'bot: b is <reply> c', 'sure, mgv', 'add with reply';
49runtest 'b?', 'c', 'check reply';
50runtest 'bot: c is <action> d', 'sure, mgv', 'add with action';
51runtest 'c?', 'ACTION d', 'check action';
52
53runtest 'x is y', 'sure, mgv', 'private add', 1;
54runtest 'x?', 'x is y', 'private query', 1;
55runtest 'forget x', 'mgv: I forgot x', 'private forget', 1;
This page took 0.012025 seconds and 4 git commands to generate.