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