OLD | NEW |
(Empty) | |
| 1 |
| 2 use strict; |
| 3 |
| 4 use Test::More; |
| 5 BEGIN { plan tests => 10 }; |
| 6 BEGIN { $ENV{PERL_JSON_BACKEND} = "JSON::backportPP"; } |
| 7 |
| 8 |
| 9 use strict; |
| 10 use JSON; |
| 11 |
| 12 my $json = JSON->new; |
| 13 |
| 14 eval q| $json->encode( [ sub {} ] ) |; |
| 15 ok( $@ =~ /encountered CODE/, $@ ); |
| 16 |
| 17 eval q| $json->encode( [ \-1 ] ) |; |
| 18 ok( $@ =~ /cannot encode reference to scalar/, $@ ); |
| 19 |
| 20 eval q| $json->encode( [ \undef ] ) |; |
| 21 ok( $@ =~ /cannot encode reference to scalar/, $@ ); |
| 22 |
| 23 eval q| $json->encode( [ \{} ] ) |; |
| 24 ok( $@ =~ /cannot encode reference to scalar/, $@ ); |
| 25 |
| 26 $json->allow_unknown; |
| 27 |
| 28 is( $json->encode( [ sub {} ] ), '[null]' ); |
| 29 is( $json->encode( [ \-1 ] ), '[null]' ); |
| 30 is( $json->encode( [ \undef ] ), '[null]' ); |
| 31 is( $json->encode( [ \{} ] ), '[null]' ); |
| 32 |
| 33 |
| 34 SKIP: { |
| 35 |
| 36 skip "this test is for Perl 5.8 or later", 2 if( $] < 5.008 ); |
| 37 |
| 38 $json->allow_unknown(0); |
| 39 |
| 40 my $fh; |
| 41 open( $fh, '>hoge.txt' ) or die $!; |
| 42 |
| 43 eval q| $json->encode( [ $fh ] ) |; |
| 44 ok( $@ =~ /encountered GLOB/, $@ ); |
| 45 |
| 46 $json->allow_unknown(1); |
| 47 |
| 48 is( $json->encode( [ $fh ] ), '[null]' ); |
| 49 |
| 50 close $fh; |
| 51 |
| 52 unlink('hoge.txt'); |
| 53 |
| 54 } |
OLD | NEW |