jsonfmt: Add error reporting
This commit is contained in:
parent
3ae9347ad2
commit
e0161cd22c
2 changed files with 18 additions and 6 deletions
|
|
@ -50,7 +50,15 @@ my @tests = (
|
|||
1844674407370955161 / 10, '1.84467440737096e+17',
|
||||
);
|
||||
|
||||
plan tests => @tests + 6;
|
||||
my @errors = (
|
||||
\1, qr/unable to format reference/,
|
||||
*STDOUT, qr/unable to format unknown value/,
|
||||
'NaN'+0, qr/unable to format floating point NaN or Inf as JSON/,
|
||||
'Inf'+0, qr/unable to format floating point NaN or Inf as JSON/,
|
||||
do { no warnings 'portable'; "\x{ffffffff}" }, qr/invalid codepoint encountered in string/,
|
||||
);
|
||||
|
||||
plan tests => @tests + @errors/2 + 6;
|
||||
|
||||
for my($in, $exp) (@tests) {
|
||||
my $out = json_format $in;
|
||||
|
|
@ -58,6 +66,11 @@ for my($in, $exp) (@tests) {
|
|||
ok utf8::is_utf8($out);
|
||||
}
|
||||
|
||||
for my ($in, $exp) (@errors) {
|
||||
eval { json_format $in };
|
||||
like $@, $exp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
# http://e-choroba.eu/18-yapc slide 6
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue