JSON5
view release on metacpan or search on metacpan
t/parser/05_public.t view on Meta::CPAN
use strict;
use warnings;
use utf8;
use Test::More 0.98;
use Test::Base::Less;
use JSON::PP;
use JSON5;
use JSON5::Parser;
my $json = JSON::PP->new->allow_nonref->utf8;
Test::Base::Less::register_filter(json => sub { $json->decode($_[0]) });
filters {
expected => [qw/json/],
};
my $parser = JSON5::Parser->new
->inflate_nan(sub { "<<<SPECIAL VALUE:NaN>>>" })
->inflate_infinity(sub { "<<<SPECIAL VALUE:$_[0]Infinity>>>" })
->allow_nonref
->utf8;
for my $block (blocks) {
my $parsed = eval { $parser->parse($block->input) };
is_deeply $parsed, $block->expected, $block->get_section('name')
or diag $block->input;
diag $@ if $@;
}
done_testing;
__DATA__
===
--- name: arrays - trailing-comma-array
--- input
[
null,
]
--- expected
[null]
===
--- name: comments - block-comment-following-top-level-value
--- input
null
/*
Some non-comment top-level value is needed;
we use null above.
*/
--- expected
null
===
--- name: comments - block-comment-preceding-top-level-value
--- input
/*
Some non-comment top-level value is needed;
we use null below.
*/
null
--- expected
null
===
--- name: comments - inline-comment-preceding-top-level-value
--- input
// Some non-comment top-level value is needed; we use null below.
null
--- expected
null
===
--- name: comments - block-comment-following-array-element
--- input
[
false
/*
true
*/
]
--- expected
[false]
===
t/parser/05_public.t view on Meta::CPAN
51428
===
--- name: numbers - negative-hexadecimal
--- input
-0xC8
--- expected
-200
===
--- name: numbers - positive-float-leading-decimal-point
--- input
+.5
--- expected
0.5
===
--- name: numbers - zero-hexadecimal
--- input
0x0
--- expected
0
===
--- name: numbers - infinity
--- input
Infinity
--- expected
"<<<SPECIAL VALUE:+Infinity>>>"
===
--- name: numbers - hexadecimal-uppercase-x
--- input
0XC8
--- expected
200
===
--- name: numbers - float-trailing-decimal-point
--- input
5.
--- expected
5
===
--- name: numbers - positive-zero-integer
--- input
+0
--- expected
0
===
--- name: numbers - float-trailing-decimal-point-with-integer-exponent
--- input
5.e4
--- expected
50000
===
--- name: numbers - nan
--- input
NaN
--- expected
"<<<SPECIAL VALUE:NaN>>>"
===
--- name: numbers - negative-float-trailing-decimal-point
--- input
-5.
--- expected
-5
===
--- name: numbers - hexadecimal
--- input
0xC8
--- expected
200
===
--- name: numbers - positive-zero-hexadecimal
--- input
+0x0
--- expected
0
===
--- name: numbers - positive-zero-float
--- input
+0.0
--- expected
0
===
--- name: numbers - negative-zero-float-trailing-decimal-point
--- input
-0.
--- expected
0
===
--- name: numbers - negative-infinity
--- input
-Infinity
--- expected
"<<<SPECIAL VALUE:-Infinity>>>"
===
--- name: numbers - positive-hexadecimal
--- input
+0xC8
--- expected
200
===
--- name: numbers - float-leading-decimal-point
--- input
.5
--- expected
0.5
===
--- name: numbers - positive-zero-float-trailing-decimal-point
--- input
+0.
( run in 0.496 second using v1.01-cache-2.11-cpan-39bf76dae61 )