Debian Codegraph @

t/evaluate_json_string.t

raw
1 # vim: set ft=perl ts=8 sts=2 sw=2 tw=100 et :
2 use strictures 2;
3 use 5.020;
4 use stable 0.031 'postderef';
5 use experimental 'signatures';
6 no autovivification warn => qw(fetch store exists delete);
7 use if "$]" >= 5.022, experimental => 're_strict';
8 no if "$]" >= 5.031009, feature => 'indirect';
9 no if "$]" >= 5.033001, feature => 'multidimensional';
10 no if "$]" >= 5.033006, feature => 'bareword_filehandles';
11 no if "$]" >= 5.041009, feature => 'smartmatch';
12 no feature 'switch';
13 use open ':std', ':encoding(UTF-8)'; # force stdin, stdout, stderr into utf8
14
15 use lib 't/lib';
16 use Helper;
17
18 my $js = JSON::Schema::Modern->new;
19
20 like(ref($js->_json_decoder), qr/^(?:Cpanel::JSON::XS|JSON::PP)\z/, 'we have a JSON decoder');
21
22 ok(
23 lives {
24 ok($js->evaluate_json_string('true', {})->valid, 'json data "true" is evaluated successfully');
25 },
26 'no exceptions in evaluate_json_string on good json',
27 );
28
29 ok(
30 lives {
31 cmp_result(
32 $js->evaluate_json_string('blargh', {})->TO_JSON,
33 {
34 valid => false,
35 errors => [
36 {
37 keywordLocation => '',
38 error => re(qr/^malformed JSON string/),
39 },
40 ],
41 },
42 'evaluating bad json data returns false, with error',
43 );
44 },
45 'no exceptions in evaluate_json_string on bad json',
46 );
47
48 done_testing;