6 BEGIN { plan tests
=> 10 };
7 BEGIN { $ENV{PERL_JSON_BACKEND
} = "JSON::backportPP"; }
15 eval q
| $json->encode( [ sub {} ] ) |;
16 ok
( $@
=~ /encountered CODE/, $@
);
18 eval q
| $json->encode( [ \
-1 ] ) |;
19 ok
( $@
=~ /cannot encode reference to scalar/, $@
);
21 eval q
| $json->encode( [ \
undef ] ) |;
22 ok
( $@
=~ /cannot encode reference to scalar/, $@
);
24 eval q
| $json->encode( [ \
{} ] ) |;
25 ok
( $@
=~ /cannot encode reference to scalar/, $@
);
29 is
( $json->encode( [ sub {} ] ), '[null]' );
30 is
( $json->encode( [ \
-1 ] ), '[null]' );
31 is
( $json->encode( [ \
undef ] ), '[null]' );
32 is
( $json->encode( [ \
{} ] ), '[null]' );
37 skip
"this test is for Perl 5.8 or later", 2 if( $] < 5.008 );
39 $json->allow_unknown(0);
42 open( $fh, '>hoge.txt' ) or die $!;
44 eval q
| $json->encode( [ $fh ] ) |;
45 ok
( $@
=~ /encountered GLOB/, $@
);
47 $json->allow_unknown(1);
49 is
( $json->encode( [ $fh ] ), '[null]' );