From 1b89249a78f44aaa3f02e40488a7a05cb3a9ebca Mon Sep 17 00:00:00 2001 From: Rob Date: Mon, 30 May 2016 19:13:01 +0100 Subject: [PATCH] EmailValidator: Switching to text template --- lib/DDG/Goodie/EmailValidator.pm | 13 ++++-- t/EmailValidator.t | 78 +++++++++----------------------- 2 files changed, 30 insertions(+), 61 deletions(-) mode change 100644 => 100755 lib/DDG/Goodie/EmailValidator.pm mode change 100644 => 100755 t/EmailValidator.t diff --git a/lib/DDG/Goodie/EmailValidator.pm b/lib/DDG/Goodie/EmailValidator.pm old mode 100644 new mode 100755 index fdc479f17fb..8ebb489cd2d --- a/lib/DDG/Goodie/EmailValidator.pm +++ b/lib/DDG/Goodie/EmailValidator.pm @@ -43,11 +43,14 @@ handle remainder => sub { $message = "$address appears to be valid."; } - return $message, - structured_answer => { - input => [html_enc($address)], - operation => 'Email address validation', - result => html_enc($message), + return $message, structured_answer => { + data => { + title => html_enc($message), + subtitle => 'Email address validation: '.html_enc($address) + }, + templates => { + group => 'text' + } }; }; diff --git a/t/EmailValidator.t b/t/EmailValidator.t old mode 100644 new mode 100755 index c491fda5cec..8b6964f0a87 --- a/t/EmailValidator.t +++ b/t/EmailValidator.t @@ -9,65 +9,31 @@ use DDG::Test::Goodie; zci answer_type => 'email_validation'; zci is_cached => 1; +sub build_test { + my ($answer, $input) = @_; + return test_zci($answer, structured_answer => { + data => { + title => re($answer), + subtitle => $input + }, + templates => { + group => 'text' + } + }); +} + +my $valid_re = qr/appears to be valid/; + ddg_goodie_test( ['DDG::Goodie::EmailValidator'], - 'validate my email foo@example.com' => test_zci( - re(qr/appears to be valid/), - structured_answer => { - input => ['foo@example.com'], - operation => 'Email address validation', - result => re(qr/appears to be valid/) - } - ), - 'validate my email foo+abc@example.com' => test_zci( - re(qr/appears to be valid/), - structured_answer => { - input => ['foo+abc@example.com'], - operation => 'Email address validation', - result => re(qr/appears to be valid/) - } - ), - 'validate my email foo.bar@example.com' => test_zci( - re(qr/appears to be valid/), - structured_answer => { - input => ['foo.bar@example.com'], - operation => 'Email address validation', - result => re(qr/appears to be valid/) - } - ), + 'validate my email foo@example.com' => build_test($valid_re, 'Email address validation: foo@example.com'), + 'validate my email foo+abc@example.com' => build_test($valid_re, 'Email address validation: foo+abc@example.com'), + 'validate my email foo.bar@example.com' => build_test($valid_re, 'Email address validation: foo.bar@example.com'), 'validate user@exampleaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com' - => test_zci( - re(qr/Please check the address/), - structured_answer => { - input => ignore(), - operation => 'Email address validation', - result => re(qr/Please check the address/), - } - ), - 'validate foo@example.com' => test_zci( - re(qr/appears to be valid/), - structured_answer => { - input => ['foo@example.com'], - operation => 'Email address validation', - result => re(qr/appears to be valid/) - } - ), - 'validate foo@!!!.com' => test_zci( - re(qr/Please check the fully qualified domain name/), - structured_answer => { - input => ['foo@!!!.com'], - operation => 'Email address validation', - result => re(qr/Please check the fully qualified domain name/), - } - ), - 'validate foo@example.lmnop' => test_zci( - re(qr/Please check the top-level domain/), - structured_answer => { - input => ['foo@example.lmnop'], - operation => 'Email address validation', - result => re(qr/Please check the top-level domain/), - } - ), + => build_test(qr/Please check the address/, ignore()), + 'validate foo@example.com' => build_test($valid_re, 'Email address validation: foo@example.com'), + 'validate foo@!!!.com' => build_test(qr/Please check the fully qualified domain name/, 'Email address validation: foo@!!!.com'), + 'validate foo@example.lmnop' => build_test(qr/Please check the top-level domain/, 'Email address validation: foo@example.lmnop'), 'validate foo' => undef, );