From 1ccc31c175ab64e1644787a55446d4ab70fe90ab Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Wed, 18 May 2016 20:57:34 +0100 Subject: [PATCH] RC4: Converting to text template --- lib/DDG/Goodie/Rc4.pm | 13 ++++++++----- t/Rc4.t | 27 +++++++++++++++------------ 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/lib/DDG/Goodie/Rc4.pm b/lib/DDG/Goodie/Rc4.pm index c2fc9d3e6..051bb9903 100644 --- a/lib/DDG/Goodie/Rc4.pm +++ b/lib/DDG/Goodie/Rc4.pm @@ -43,11 +43,14 @@ handle remainder => sub { return; } - return "$operation: $plaintext, with key: $key is $result", - structured_answer => { - operation => $operation, - input => [html_enc($plaintext) . ", Key: $key"], - result => $result + return "$operation: $plaintext, with key: $key is $result", structured_answer => { + data => { + title => html_enc($result), + subtitle => "$operation: " . html_enc($plaintext) . ", Key: $key" + }, + templates => { + group => 'text' + } }; }; diff --git a/t/Rc4.t b/t/Rc4.t index f84a141c1..471be4ae1 100644 --- a/t/Rc4.t +++ b/t/Rc4.t @@ -9,22 +9,25 @@ use DDG::Test::Goodie; zci answer_type => "rc4"; zci is_cached => 1; +sub build_test { + my ($text, $title, $subtitle) = @_; + return test_zci($text, structured_answer => { + data => { + title => $title, + subtitle => $subtitle + }, + templates => { + group => 'text' + } + }); +} + ddg_goodie_test( [qw( DDG::Goodie::Rc4 )], - 'rc4 en mysecretkey hello' => test_zci("RC4 Encrypt: hello, with key: mysecretkey is grYU1K8=", - structured_answer => { - input => ['hello, Key: mysecretkey'], - operation => "RC4 Encrypt", - result => "grYU1K8=" - }), - 'rc4 de duck yWrJniG/nNg=' => test_zci("RC4 Decrypt: yWrJniG/nNg=, with key: duck is DdgRocks", - structured_answer => { - input => ['yWrJniG/nNg=, Key: duck'], - operation => "RC4 Decrypt", - result => "DdgRocks" - }), + 'rc4 en mysecretkey hello' => build_test("RC4 Encrypt: hello, with key: mysecretkey is grYU1K8=", "grYU1K8=", "RC4 Encrypt: hello, Key: mysecretkey"), + 'rc4 de duck yWrJniG/nNg=' => build_test("RC4 Decrypt: yWrJniG/nNg=, with key: duck is DdgRocks", "DdgRocks", "RC4 Decrypt: yWrJniG/nNg=, Key: duck"), 'rc4 ' => undef, 'rc4 enc missing' => undef, 'rc4 no operation' => undef