Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(808)

Unified Diff: third_party/JSON/JSON-2.59/t/20_unknown.t

Issue 15736030: Add JSON.pm to third_party (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix permissions and shebangs Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/JSON/JSON-2.59/t/19_incr.t ('k') | third_party/JSON/JSON-2.59/t/21_evans_bugrep.t » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/JSON/JSON-2.59/t/20_unknown.t
diff --git a/third_party/JSON/JSON-2.59/t/20_unknown.t b/third_party/JSON/JSON-2.59/t/20_unknown.t
new file mode 100644
index 0000000000000000000000000000000000000000..7686929ee0a5f7c0d4a01efd2a3ba892cec61366
--- /dev/null
+++ b/third_party/JSON/JSON-2.59/t/20_unknown.t
@@ -0,0 +1,54 @@
+
+use strict;
+
+use Test::More;
+BEGIN { plan tests => 10 };
+BEGIN { $ENV{PERL_JSON_BACKEND} = "JSON::backportPP"; }
+
+
+use strict;
+use JSON;
+
+my $json = JSON->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');
+
+}
« no previous file with comments | « third_party/JSON/JSON-2.59/t/19_incr.t ('k') | third_party/JSON/JSON-2.59/t/21_evans_bugrep.t » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698