diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/TODO.md | 2 | ||||
-rwxr-xr-x | test/test_random.t | 72 |
2 files changed, 73 insertions, 1 deletions
diff --git a/test/TODO.md b/test/TODO.md index b8d66bf..2dc857d 100644 --- a/test/TODO.md +++ b/test/TODO.md @@ -19,7 +19,6 @@ * Men.pm * Natural.pm * Quote_Grab.pm -* Random.pm * Source.pm * Timezone.pm * Titillate.pm @@ -32,5 +31,6 @@ * Autojoin.pm * Echo.pm * Ping.pm +* Random.pm * Thanks.pm * Vote.pm diff --git a/test/test_random.t b/test/test_random.t new file mode 100755 index 0000000..fc30336 --- /dev/null +++ b/test/test_random.t @@ -0,0 +1,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"); +} |