Merge pull request #3064 from duckduckgo/mintsoft/GenerateMAC-template

GenerateMAC: Switching to text template
master
Ben Moon 2016-05-15 20:05:22 +01:00
commit 8eeddb5c19
2 changed files with 26 additions and 17 deletions

15
lib/DDG/Goodie/GenerateMAC.pm Normal file → Executable file
View File

@ -20,12 +20,15 @@ handle remainder => sub {
my $address = join(':', map { sprintf '%0.2X', rand(255) } (1 .. 6));
return "Here's a random MAC address: $address",
structured_answer => {
input => [],
operation => 'Random MAC address',
result => $address
};
return "Here's a random MAC address: $address", structured_answer => {
data => {
title => $address,
subtitle => 'Random MAC Address'
},
templates => {
group => 'text'
}
};
};
1;

28
t/GenerateMAC.t Normal file → Executable file
View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => "MAC Address";
@ -11,22 +12,27 @@ zci is_cached => 0;
my $mac_regxp = "([0-9A-F]{2}[:-]){5}([0-9A-F]{2})";
my $text_start = "Here's a random MAC address: ";
my @answer = (
qr/^$text_start$mac_regxp$/,
structured_answer => {
input => [],
operation => 'Random MAC address',
result => qr/$mac_regxp/
sub build_test
{
return test_zci(re(qr/^$text_start$mac_regxp$/), structured_answer => {
data => {
title => re($mac_regxp),
subtitle => "Random MAC Address"
},
templates => {
group => 'text'
}
});
}
#regexp from http://stackoverflow.com/questions/4260467/what-is-a-regular-expression-for-a-mac-address
ddg_goodie_test(
['DDG::Goodie::GenerateMAC'],
'generate mac address' => test_zci(@answer),
'generate mac addr' => test_zci(@answer),
'random mac address' => test_zci(@answer),
'random mac addr' => test_zci(@answer),
'please generate mac address' => test_zci(@answer),
'generate mac address' => build_test(),
'generate mac addr' => build_test(),
'random mac address' => build_test(),
'random mac addr' => build_test(),
'please generate mac address' => build_test(),
);
done_testing;