1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 10;
use Mock::CommandRegistry;
use Plugin::Random;
my $cr = new Mock::CommandRegistry;
my $register = sub { $cr->register(@_); };
Plugin::Random->configure($register, undef, undef, undef);
my %ctx = (
irc => undef,
logger => undef,
who => undef,
where => undef,
ided => undef,
rest => undef,
no_reenter => undef,
args => undef
);
# Test that all expected commands were registered
{
for my $cmd (qw/shuffle choose/) {
my $is_registered = $cr->is_registered_to_owner("Plugin::Random", $cmd);
ok($is_registered, "registered command $cmd");
}
}
# Test that `choose` works on a singleton input
{
my %ctx_m = %ctx;
$ctx_m{rest} = "singleton";
my $result = $cr->run_owned("Plugin::Random", "choose", %ctx_m);
is($result, "singleton", "choose on singleton is the singleton");
}
# Test that `choose` chooses returns something from the input
{
my %ctx_m = %ctx;
$ctx_m{rest} = "foo bar baz qux";
my @items = split / /, $ctx_m{rest};
my $result = $cr->run_owned("Plugin::Random", "choose", %ctx_m);
my $in_input = grep {$_ eq $result} @items;
ok($in_input, "chosen value was given as an option");
}
# Test that `shuffle` on singleton is that same singleton
{
my %ctx_m = %ctx;
$ctx_m{rest} = "singleton";
my $result = $cr->run_owned("Plugin::Random", "shuffle", %ctx_m);
is($result, "singleton", "shuffled singleton is the same");
}
# Test that `shuffle` on list has all the same elements. No more or less
{
my %ctx_m = %ctx;
$ctx_m{rest} = "foo bar baz qux";
my @expected_items = split / /, $ctx_m{rest};
my $result = $cr->run_owned("Plugin::Random", "shuffle", %ctx_m);
my @results = split / /, $result;
for my $item (@expected_items) {
ok((grep {$_ eq $item} @results), "$item carried over");
}
is(@results, @expected_items, "shuffled list same length as expected");
}
|