Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Commit

Permalink
EmailValidator: Switching to text template
Browse files Browse the repository at this point in the history
  • Loading branch information
mintsoft committed May 30, 2016
1 parent bd08813 commit 1b89249
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 61 deletions.
13 changes: 8 additions & 5 deletions lib/DDG/Goodie/EmailValidator.pm 100644 → 100755
Expand Up @@ -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'
}
};
};

Expand Down
78 changes: 22 additions & 56 deletions t/EmailValidator.t 100644 → 100755
Expand Up @@ -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,
);

Expand Down

0 comments on commit 1b89249

Please sign in to comment.