aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@yeah.nah.nz>2020-04-04 20:37:11 +1300
committerDavid Phillips <david@yeah.nah.nz>2020-04-04 20:37:23 +1300
commitbb50b299de382395bd2ff7099ae1f32db3fd7a7a (patch)
treeb2eeffa616d650642c1faa378f253ccf8b37174b
parentcba83d93d8b47cc044e8d093049d23aba5d8b6ed (diff)
downloadidalius-bb50b299de382395bd2ff7099ae1f32db3fd7a7a.tar.xz
Add test plan for Random
-rw-r--r--Mock/CommandRegistry.pm2
-rwxr-xr-xtest.pl2
-rw-r--r--test/TODO.md2
-rwxr-xr-xtest/test_random.t72
4 files changed, 75 insertions, 3 deletions
diff --git a/Mock/CommandRegistry.pm b/Mock/CommandRegistry.pm
index 6531fd7..cf1d573 100644
--- a/Mock/CommandRegistry.pm
+++ b/Mock/CommandRegistry.pm
@@ -22,7 +22,7 @@ sub run {
sub run_owned {
my ($self, $owner, $command, %ctx) = @_;
- die "$owner::$command not registered\n"
+ die "$owner\:\:$command not registered\n"
unless $self->is_registered_to_owner($owner, $command);
# XXX plugins need to eventually use the ctx hash directly. Much more
diff --git a/test.pl b/test.pl
index fbce463..b819e0e 100755
--- a/test.pl
+++ b/test.pl
@@ -3,7 +3,7 @@
use Test::Harness;
my @tests = map {"test/test_$_.t"} qw/
- autojoin echo ping thanks vote
+ autojoin echo ping random thanks vote
/;
runtests(@tests);
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");
+}