Add some tests and move some docs
This commit is contained in:
parent
ebe84167e7
commit
abfbba3c10
7 changed files with 179 additions and 129 deletions
|
|
@ -68,7 +68,6 @@ my @errors = (
|
|||
do { my $o = {}; bless $o, 'MyToJSONSelf' }, qr/MyToJSONSelf::TO_JSON method returned same object as was passed instead of a new one/,
|
||||
);
|
||||
|
||||
plan tests => @tests*2 + @errors/2 + 10;
|
||||
|
||||
for my($in, $exp) (@tests) {
|
||||
my $out = json_format $in;
|
||||
|
|
@ -120,6 +119,25 @@ eval { json_format 'hello world', max_size => 8 };
|
|||
like $@, qr/maximum string length exceeded/;
|
||||
|
||||
|
||||
# Test large strings to cover some buffer handling special cases.
|
||||
for (2000..2100, 4000..4200, 8100..8200, 12200..12300, 16300..16400) {
|
||||
my $s = 'a'x$_;
|
||||
is json_format($s), "\"$s\"";
|
||||
}
|
||||
|
||||
# 500 depth
|
||||
{
|
||||
my $v = 1;
|
||||
$v = [$v] for (1..500);
|
||||
is json_format($v), '['x500 . 1 . ']'x500;
|
||||
}
|
||||
{
|
||||
my $v = 1;
|
||||
$v = {'',$v} for (1..500);
|
||||
is json_format($v), '{"":'x500 . 1 . '}'x500;
|
||||
}
|
||||
|
||||
|
||||
# http://e-choroba.eu/18-yapc slide 6
|
||||
|
||||
tie my $incs, 'MyIncrementer', 'Xa';
|
||||
|
|
@ -132,6 +150,9 @@ is json_format($incu), 4;
|
|||
is json_format($incu), 5;
|
||||
is json_format($incu), 6;
|
||||
|
||||
|
||||
done_testing;
|
||||
|
||||
package MyIncrementer;
|
||||
use Tie::Scalar;
|
||||
use parent -norequire => 'Tie::StdScalar';
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ is ref $v, 'HASH';
|
|||
is keys %$v, 1;
|
||||
is $v->{a}, 1;
|
||||
|
||||
sub large($s) {
|
||||
sub complete($s) {
|
||||
$v = json_parse $s;
|
||||
is ref $v, 'HASH';
|
||||
is keys %$v, 3;
|
||||
|
|
@ -163,11 +163,32 @@ sub large($s) {
|
|||
is ref $v->{'ë'}, 'ARRAY';
|
||||
is scalar $v->{'ë'}->@*, 0;
|
||||
}
|
||||
large '{"a":[1,0.1,true,null,{}],"":-0,"ë":[]}';
|
||||
large ' {
|
||||
complete '{"a":[1,0.1,true,null,{}],"":-0,"ë":[]}';
|
||||
complete ' {
|
||||
"a" : [ 1 , 0.1 , true , null , { } ] ,
|
||||
"" : -0 ,
|
||||
"ë" : [ ]
|
||||
} ';
|
||||
|
||||
|
||||
# Test large inputs to cover some buffer handling special cases.
|
||||
for (2000..2100, 4000..4200, 8100..8200, 12200..12300, 16300..16400) {
|
||||
my $s = 'a'x$_;
|
||||
is json_parse("\"$s\""), $s
|
||||
}
|
||||
|
||||
# 500 depth
|
||||
{
|
||||
$v = json_parse('['x500 . ']'x500);
|
||||
my $i = 0;
|
||||
while (ref $v) { $v = $v->[0]; $i++ }
|
||||
is $i, 500;
|
||||
}
|
||||
{
|
||||
$v = json_parse('{"":'x500 . 1 . '}'x500);
|
||||
my $i = 0;
|
||||
while (ref $v) { $v = $v->{''}; $i++ }
|
||||
is $i, 500;
|
||||
}
|
||||
|
||||
done_testing;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue