xref: /openbsd-src/gnu/usr.bin/perl/cpan/JSON-PP/t/gh_28_json_test_suite.t (revision f2a19305cfc49ea4d1a5feb55cd6c283c6f1e031)
1# the following test cases are taken from JSONTestSuite
2# by Nicolas Seriot (https://github.com/nst/JSONTestSuite)
3
4use strict;
5use warnings;
6use Test::More;
7
8BEGIN { plan tests => 20 };
9
10BEGIN { $ENV{PERL_JSON_BACKEND} = 0; }
11
12use JSON::PP;
13
14my $DECODER = JSON::PP->new->utf8->allow_nonref;
15
16# n_multidigit_number_then_00
17decode_should_fail(qq!123\x00!);
18
19# number_-01
20decode_should_fail(qq![-01]!);
21
22# number_neg_int_starting_with_zero
23decode_should_fail(qq![-012]!);
24
25# n_object_trailing_comment
26decode_should_fail(qq!{"a":"b"}/**/!);
27
28# n_object_trailing_comment_slash_open
29decode_should_fail(qq!{"a":"b"}//!);
30
31# n_structure_null-byte-outside-sting
32decode_should_fail(qq![\x00]!);
33
34# n_structure_object_with_comment
35decode_should_fail(qq!{"a":/*comment*/"b"}!);
36
37# n_structure_whitespace_formfeed
38decode_should_fail(qq![\0x0c]!);
39
40# y_string_utf16BE_no_BOM
41decode_should_pass(qq!\x00[\x00"\x00\xE9\x00"\x00]!);
42
43# y_string_utf16LE_no_BOM
44decode_should_pass(qq![\x00"\x00\xE9\x00"\x00]\x00!);
45
46sub decode_should_pass {
47    my $json = shift;
48    my $result = eval { $DECODER->decode($json); };
49    ok !$@, $@ || '';
50    ok defined $result;
51}
52
53sub decode_should_fail {
54    my $json = shift;
55    my $result = eval { $DECODER->decode($json); };
56    ok $@, $@ || '';
57    ok !defined $result;
58}
59