File: max-depth.t

package info (click to toggle)
libjson-parse-perl 0.62-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 572 kB
  • sloc: ansic: 3,614; perl: 475; makefile: 12
file content (27 lines) | stat: -rw-r--r-- 711 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# This tests the "max depth" feature added so that the JSON Test Suite
# silly test with 100,000 open { and [ doesn't cause an error.

use FindBin '$Bin';
use lib "$Bin";
use JPT;

my $jp = JSON::Parse->new ();

# Test setting to "one" so that two [[ will cause an error.

$jp->set_max_depth (1);
my $ok = eval {
    $jp->run ('[[[["should fail due to depth"]]]]');
    1;
};
ok (! $ok, "fails to parse array when max depth is set to 1");
my $md = $jp->get_max_depth ();
cmp_ok ($md, '==', 1, "got back the max depth");

# Test setting back to default using zero argument.

$jp->set_max_depth (0);
my $mdd = $jp->get_max_depth ();
cmp_ok ($mdd, '==', 10000, "got back the default max depth");

done_testing ();