Rot13: use structured answer
parent
5555ef2da9
commit
51639f4d2f
|
@ -15,14 +15,23 @@ attribution github => ['https://github.com/unlisted', 'unlisted'];
|
|||
|
||||
triggers start => 'rot13';
|
||||
|
||||
zci is_cached => 1;
|
||||
zci answer_type => 'rot13';
|
||||
zci is_cached => 1;
|
||||
|
||||
handle remainder => sub {
|
||||
if ($_) {
|
||||
$_ =~ tr[a-zA-Z][n-za-mN-ZA-M];
|
||||
return "ROT13: $_";
|
||||
};
|
||||
return;
|
||||
my $in = shift;
|
||||
|
||||
return unless $in;
|
||||
my $out = $in;
|
||||
|
||||
$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),
|
||||
};
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
33
t/Rot13.t
33
t/Rot13.t
|
@ -6,15 +6,34 @@ use Test::More;
|
|||
use DDG::Test::Goodie;
|
||||
|
||||
zci answer_type => 'rot13';
|
||||
zci is_cached => 1;
|
||||
zci is_cached => 1;
|
||||
|
||||
ddg_goodie_test(
|
||||
[qw(
|
||||
DDG::Goodie::Rot13
|
||||
)],
|
||||
'rot13 This is a test' => test_zci('ROT13: Guvf vf n grfg'),
|
||||
'rot13 thirteen' => test_zci('ROT13: guvegrra'),
|
||||
'rot13 guvegrra' => test_zci('ROT13: thirteen'),
|
||||
[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'
|
||||
}
|
||||
),
|
||||
);
|
||||
|
||||
done_testing;
|
||||
|
|
Loading…
Reference in New Issue