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];
return "ROT13: $out",
structured_answer => {
input => [html_enc($in)],
operation => 'ROT13',
result => html_enc($out),
};
return "ROT13: $out", structured_answer => {
data => {
title => html_enc($out),
subtitle => "ROT13: ".html_enc($in)
},
templates => {
group => 'text'
}
};
};
1;

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

@ -9,32 +9,24 @@ use DDG::Test::Goodie;
zci answer_type => 'rot13';
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(
[qw( DDG::Goodie::Rot13 )],
'rot13 This is a test' => test_zci(
'ROT13: Guvf vf n grfg',
structured_answer => {
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'
}
),
'rot13 This is a test' => build_answer('ROT13: Guvf vf n grfg', 'This is a test', 'Guvf vf n grfg'),
'rot13 thirteen' => build_answer('ROT13: guvegrra', 'thirteen', 'guvegrra'),
'rot13 guvegrra' => build_answer('ROT13: thirteen', 'guvegrra', 'thirteen'),
);
done_testing;