more verbose errors in IsValid plugins

master
Alessandro Ghedini 2012-08-03 19:26:06 +02:00
parent cc598fe550
commit ee60cd0175
3 changed files with 17 additions and 5 deletions

View File

@ -19,10 +19,16 @@ handle remainder => sub {
from_json($_);
return 'valid';
} catch {
return 'invalid';
$_ =~ /^(.* at character offset \d+ .*) at/;
if ($1) {
return "invalid: $1"
} else {
return "invalid"
}
};
return "Your JSON is $result!";
return "Your JSON is $result!"
};
1;

View File

@ -19,7 +19,13 @@ handle remainder => sub {
XMLin($_);
return 'valid';
} catch {
return 'invalid';
$_ =~ /^\n(.* at line \d+, column \d+, byte \d+) at/;
if ($1) {
return "invalid: $1"
} else {
return "invalid"
}
};
return "Your XML is $result!";

View File

@ -16,7 +16,7 @@ ddg_goodie_test(
ddg_goodie_test(
[qw(DDG::Goodie::IsValid::JSON)],
'is valid json {"test" "lol"}' => test_zci('Your JSON is invalid!'),
'is valid json {"test" "lol"}' => test_zci('Your JSON is invalid: \':\' expected, at character offset 8 (before ""lol"}")!'),
);
ddg_goodie_test(
@ -26,7 +26,7 @@ ddg_goodie_test(
ddg_goodie_test(
[qw(DDG::Goodie::IsValid::XML)],
'is valid xml <test>lol' => test_zci('Your XML is invalid!'),
'is valid xml <test>lol' => test_zci('Your XML is invalid: no element found at line 1, column 9, byte 9!'),
);
done_testing;