2016-05-14 09:10:31 -07:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use Test::Deep;
|
|
|
|
use Test::More;
|
|
|
|
use DDG::Test::Goodie;
|
|
|
|
|
|
|
|
zci answer_type => "shuffle";
|
2016-05-20 03:35:04 -07:00
|
|
|
zci is_cached => 0;
|
2016-05-14 09:10:31 -07:00
|
|
|
|
|
|
|
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-20 04:04:06 -07:00
|
|
|
# In words
|
|
|
|
'shuffle 1 and 2 and 3' => build_test([1, 2, 3]),
|
|
|
|
'shuffle 1, 2, and 3' => build_test([1, 2, 3]),
|
|
|
|
'shuffle 1 and 2, and 3' => build_test([1, 2, 3]),
|
2016-05-14 09:17:04 -07:00
|
|
|
# Trailing form
|
|
|
|
'[1, 2] shuffled' => build_test([1, 2]),
|
2016-05-14 09:11:50 -07:00
|
|
|
# Nothing to shuffle
|
|
|
|
'shuffle []' => undef,
|
|
|
|
'shuffle [1]' => undef,
|
2016-05-14 09:15:45 -07:00
|
|
|
'shuffle' => undef,
|
2016-05-14 09:10:31 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
done_testing;
|