zeroclickinfo-goodies/t/Shuffle.t

48 lines
1.0 KiB
Perl
Raw Normal View History

#!/usr/bin/env perl
use strict;
use warnings;
use Test::Deep;
use Test::More;
use DDG::Test::Goodie;
zci answer_type => "shuffle";
zci is_cached => 1;
sub build_structured_answer {
my $items = shift;
my @items = @$items;
my $show = "[@{[join ', ', @items]}]";
return "$show",
structured_answer => {
data => {
title => re(qr/^\[.+?\]$/),
items => bag(@items),
subtitle => "Shuffle: $show",
},
templates => {
group => "text",
}
};
}
sub build_test { test_zci(build_structured_answer(@_)) }
ddg_goodie_test(
[qw( DDG::Goodie::Shuffle )],
# Different types of brackets
'shuffle [1, 2]' => build_test([1, 2]),
'shuffle (1, 2)' => build_test([1, 2]),
'shuffle {1, 2}' => build_test([1, 2]),
2016-05-14 09:17:04 -07:00
# Trailing form
'[1, 2] shuffled' => build_test([1, 2]),
# Nothing to shuffle
'shuffle []' => undef,
'shuffle [1]' => undef,
'shuffle' => undef,
);
done_testing;