Commit | Line | Data |
---|---|---|
b2f492fe | 1 | #!/usr/bin/perl -w |
29280d6c MG |
2 | use v5.14; |
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | use Test::More tests => 15; | |
7 | use Test::MockObject; | |
8 | ||
9 | BEGIN { use_ok('POE::Component::IRC::Plugin::Hello') }; | |
10 | ||
29280d6c MG |
11 | my $hello_sent; |
12 | ||
13 | my $mockirc = Test::MockObject->new; | |
14 | $mockirc->mock(yield => sub { $hello_sent = 1 })->set_always(nick_name => 'hellobot'); | |
15 | ||
16 | my $self = POE::Component::IRC::Plugin::Hello->new; | |
17 | my $channels = [ '#chan' ]; | |
18 | ||
29280d6c | 19 | sub runtest{ |
9e1acbcb MG |
20 | my ($message, $expect, $comment) = @_; |
21 | $hello_sent=0; | |
22 | $self->S_public($mockirc, \'mgv!marius@ieval.ro', \$channels, \$message); | |
23 | ok($hello_sent == $expect, $comment) | |
29280d6c MG |
24 | } |
25 | ||
29280d6c MG |
26 | runtest 'privet', 1, 'simple privet'; |
27 | runtest 'PrIvEt', 1, 'privet in mixed case'; | |
28 | runtest ' privet ', 1, 'privet with spaces'; | |
29 | runtest 'hellobot: privet', 1, 'addressed privet'; | |
30 | runtest 'hellobot: privet ', 1, 'addressed privet with spaces'; | |
31 | runtest 'ahoy', 1, 'ahoy'; | |
32 | runtest 'namaste', 1, 'namaste'; | |
33 | runtest 'neaţa', 1, 'neaţa (UTF-8 test)'; | |
34 | runtest 'こんにちは', 1, 'こんにちは (another UTF-8 test)'; | |
35 | ||
36 | runtest 'salu', 0, 'salu (misspelling)'; | |
37 | runtest 'hii', 0, 'hii (misspelling)'; | |
38 | runtest 'neaţa mgv', 0, 'neaţa mgv (valid greeting with garbage after it)'; | |
39 | ||
40 | $self = POE::Component::IRC::Plugin::Hello->new(greetings => ['sayonara']); | |
41 | ||
42 | runtest 'privet', 0, 'custom greetings - privet'; | |
43 | runtest ' sayonara ', 1, 'custom greetings - sayonara'; |