| 1 |
|
| 2 |
use Test::More; |
| 3 |
use strict; |
| 4 |
|
| 5 |
BEGIN { $ENV{PERL_JSON_BACKEND} ||= "JSON::backportPP"; } |
| 6 |
|
| 7 |
use JSON; |
| 8 |
|
| 9 |
my @simples = |
| 10 |
qw/ascii latin1 utf8 indent canonical space_before space_after allow_nonref shrink allow_blessed |
| 11 |
convert_blessed relaxed |
| 12 |
/; |
| 13 |
|
| 14 |
my $json = new JSON; |
| 15 |
|
| 16 |
# JSON::XS/JSON::PP 4.0 allow nonref by default |
| 17 |
my $allow_nonref_by_default = $json->allow_nonref; |
| 18 |
|
| 19 |
my $has_allow_tags = 0; |
| 20 |
if ($json->can('allow_tags') and !ref $json->allow_tags) { |
| 21 |
push @simples, 'allow_tags'; |
| 22 |
$has_allow_tags = 1; |
| 23 |
} |
| 24 |
|
| 25 |
plan tests => 90 + $has_allow_tags * 7; |
| 26 |
|
| 27 |
for my $name (@simples) { |
| 28 |
my $method = 'get_' . $name; |
| 29 |
if ($name eq 'allow_nonref' and $allow_nonref_by_default) { |
| 30 |
ok( $json->$method(), $method . ' default'); |
| 31 |
} else { |
| 32 |
ok(! $json->$method(), $method . ' default'); |
| 33 |
} |
| 34 |
$json->$name(); |
| 35 |
ok($json->$method(), $method . ' set true'); |
| 36 |
$json->$name(0); |
| 37 |
ok(! $json->$method(), $method . ' set false'); |
| 38 |
$json->$name(); |
| 39 |
ok($json->$method(), $method . ' set true again'); |
| 40 |
} |
| 41 |
|
| 42 |
ok($json->get_max_depth == 512, 'get_max_depth default'); |
| 43 |
$json->max_depth(7); |
| 44 |
ok($json->get_max_depth == 7, 'get_max_depth set 7 => 7'); |
| 45 |
$json->max_depth(); |
| 46 |
ok($json->get_max_depth != 0, 'get_max_depth no arg'); |
| 47 |
|
| 48 |
|
| 49 |
ok($json->get_max_size == 0, 'get_max_size default'); |
| 50 |
$json->max_size(7); |
| 51 |
ok($json->get_max_size == 7, 'get_max_size set 7 => 7'); |
| 52 |
$json->max_size(); |
| 53 |
ok($json->get_max_size == 0, 'get_max_size no arg'); |
| 54 |
|
| 55 |
|
| 56 |
for my $name (@simples) { |
| 57 |
$json->$name(); |
| 58 |
ok($json->property($name), $name); |
| 59 |
$json->$name(0); |
| 60 |
ok(! $json->property($name), $name); |
| 61 |
$json->$name(); |
| 62 |
ok($json->property($name), $name); |
| 63 |
} |
| 64 |
|
| 65 |
|