summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/perl/cpan/JSON-PP/t/020_unknown.t
diff options
context:
space:
mode:
authorsthen <sthen@openbsd.org>2013-03-25 20:06:16 +0000
committersthen <sthen@openbsd.org>2013-03-25 20:06:16 +0000
commit898184e3e61f9129feb5978fad5a8c6865f00b92 (patch)
tree56f32aefc1eed60b534611007c7856f82697a205 /gnu/usr.bin/perl/cpan/JSON-PP/t/020_unknown.t
parentPGSHIFT -> PAGE_SHIFT (diff)
downloadwireguard-openbsd-898184e3e61f9129feb5978fad5a8c6865f00b92.tar.xz
wireguard-openbsd-898184e3e61f9129feb5978fad5a8c6865f00b92.zip
import perl 5.16.3 from CPAN - worked on by Andrew Fresh and myself
Diffstat (limited to 'gnu/usr.bin/perl/cpan/JSON-PP/t/020_unknown.t')
-rw-r--r--gnu/usr.bin/perl/cpan/JSON-PP/t/020_unknown.t55
1 files changed, 55 insertions, 0 deletions
diff --git a/gnu/usr.bin/perl/cpan/JSON-PP/t/020_unknown.t b/gnu/usr.bin/perl/cpan/JSON-PP/t/020_unknown.t
new file mode 100644
index 00000000000..ef69338f43c
--- /dev/null
+++ b/gnu/usr.bin/perl/cpan/JSON-PP/t/020_unknown.t
@@ -0,0 +1,55 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use Test::More;
+BEGIN { plan tests => 10 };
+BEGIN { $ENV{PERL_JSON_BACKEND} = 0; }
+
+
+use strict;
+use JSON::PP;
+
+my $json = JSON::PP->new;
+
+eval q| $json->encode( [ sub {} ] ) |;
+ok( $@ =~ /encountered CODE/, $@ );
+
+eval q| $json->encode( [ \-1 ] ) |;
+ok( $@ =~ /cannot encode reference to scalar/, $@ );
+
+eval q| $json->encode( [ \undef ] ) |;
+ok( $@ =~ /cannot encode reference to scalar/, $@ );
+
+eval q| $json->encode( [ \{} ] ) |;
+ok( $@ =~ /cannot encode reference to scalar/, $@ );
+
+$json->allow_unknown;
+
+is( $json->encode( [ sub {} ] ), '[null]' );
+is( $json->encode( [ \-1 ] ), '[null]' );
+is( $json->encode( [ \undef ] ), '[null]' );
+is( $json->encode( [ \{} ] ), '[null]' );
+
+
+SKIP: {
+
+ skip "this test is for Perl 5.8 or later", 2 if( $] < 5.008 );
+
+$json->allow_unknown(0);
+
+my $fh;
+open( $fh, '>hoge.txt' ) or die $!;
+
+eval q| $json->encode( [ $fh ] ) |;
+ok( $@ =~ /encountered GLOB/, $@ );
+
+$json->allow_unknown(1);
+
+is( $json->encode( [ $fh ] ), '[null]' );
+
+close $fh;
+
+unlink('hoge.txt');
+
+}