Rot13: Converting to text template

master
Rob Emery 2016-05-18 23:23:28 +01:00
parent e71eb3c5d4
commit 8a1b15f858
2 changed files with 25 additions and 30 deletions

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

@ -17,12 +17,15 @@ handle remainder => sub {
$out =~ tr[a-zA-Z][n-za-mN-ZA-M]; $out =~ tr[a-zA-Z][n-za-mN-ZA-M];
return "ROT13: $out", return "ROT13: $out", structured_answer => {
structured_answer => { data => {
input => [html_enc($in)], title => html_enc($out),
operation => 'ROT13', subtitle => "ROT13: ".html_enc($in)
result => html_enc($out), },
}; templates => {
group => 'text'
}
};
}; };
1; 1;

40
t/Rot13.t Normal file → Executable file
View File

@ -9,32 +9,24 @@ use DDG::Test::Goodie;
zci answer_type => 'rot13'; zci answer_type => 'rot13';
zci is_cached => 1; zci is_cached => 1;
sub build_answer {
my ($text, $input, $answer) = @_;
return test_zci($text, structured_answer => {
data => {
title => $answer,
subtitle => "ROT13: $input"
},
templates => {
group => 'text'
}
});
}
ddg_goodie_test( ddg_goodie_test(
[qw( DDG::Goodie::Rot13 )], [qw( DDG::Goodie::Rot13 )],
'rot13 This is a test' => test_zci( 'rot13 This is a test' => build_answer('ROT13: Guvf vf n grfg', 'This is a test', 'Guvf vf n grfg'),
'ROT13: Guvf vf n grfg', 'rot13 thirteen' => build_answer('ROT13: guvegrra', 'thirteen', 'guvegrra'),
structured_answer => { 'rot13 guvegrra' => build_answer('ROT13: thirteen', 'guvegrra', 'thirteen'),
input => ['This is a test'],
operation => 'ROT13',
result => 'Guvf vf n grfg'
}
),
'rot13 thirteen' => test_zci(
'ROT13: guvegrra',
structured_answer => {
input => ['thirteen'],
operation => 'ROT13',
result => 'guvegrra'
}
),
'rot13 guvegrra' => test_zci(
'ROT13: thirteen',
structured_answer => {
input => ['guvegrra'],
operation => 'ROT13',
result => 'thirteen'
}
),
); );
done_testing; done_testing;