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

Unified Diff: third_party/JSON/JSON-2.59/t/02_error.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/01_utf8.t ('k') | third_party/JSON/JSON-2.59/t/03_types.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/02_error.t
diff --git a/third_party/JSON/JSON-2.59/t/02_error.t b/third_party/JSON/JSON-2.59/t/02_error.t
new file mode 100644
index 0000000000000000000000000000000000000000..0c757d357c863e44f64a21caf32df6def0e9c6b4
--- /dev/null
+++ b/third_party/JSON/JSON-2.59/t/02_error.t
@@ -0,0 +1,51 @@
+# copied over from JSON::XS and modified to use JSON
+
+use strict;
+use Test::More;
+BEGIN { plan tests => 31 };
+
+BEGIN { $ENV{PERL_JSON_BACKEND} = "JSON::backportPP"; }
+
+BEGIN {
+ use lib qw(t);
+ use _unicode_handling;
+}
+
+use utf8;
+use JSON;
+
+
+eval { JSON->new->encode ([\-1]) }; ok $@ =~ /cannot encode reference/;
+eval { JSON->new->encode ([\undef]) }; ok $@ =~ /cannot encode reference/;
+eval { JSON->new->encode ([\2]) }; ok $@ =~ /cannot encode reference/;
+eval { JSON->new->encode ([\{}]) }; ok $@ =~ /cannot encode reference/;
+eval { JSON->new->encode ([\[]]) }; ok $@ =~ /cannot encode reference/;
+eval { JSON->new->encode ([\\1]) }; ok $@ =~ /cannot encode reference/;
+eval { JSON->new->allow_nonref (1)->decode ('"\u1234\udc00"') }; ok $@ =~ /missing high /;
+eval { JSON->new->allow_nonref->decode ('"\ud800"') }; ok $@ =~ /missing low /;
+eval { JSON->new->allow_nonref (1)->decode ('"\ud800\u1234"') }; ok $@ =~ /surrogate pair /;
+eval { JSON->new->decode ('null') }; ok $@ =~ /allow_nonref/;
+eval { JSON->new->allow_nonref (1)->decode ('+0') }; ok $@ =~ /malformed/;
+eval { JSON->new->allow_nonref->decode ('.2') }; ok $@ =~ /malformed/;
+eval { JSON->new->allow_nonref (1)->decode ('bare') }; ok $@ =~ /malformed/;
+eval { JSON->new->allow_nonref->decode ('naughty') }; ok $@ =~ /null/;
+eval { JSON->new->allow_nonref (1)->decode ('01') }; ok $@ =~ /leading zero/;
+eval { JSON->new->allow_nonref->decode ('00') }; ok $@ =~ /leading zero/;
+eval { JSON->new->allow_nonref (1)->decode ('-0.') }; ok $@ =~ /decimal point/;
+eval { JSON->new->allow_nonref->decode ('-0e') }; ok $@ =~ /exp sign/;
+eval { JSON->new->allow_nonref (1)->decode ('-e+1') }; ok $@ =~ /initial minus/;
+eval { JSON->new->allow_nonref->decode ("\"\n\"") }; ok $@ =~ /invalid character/;
+eval { JSON->new->allow_nonref (1)->decode ("\"\x01\"") }; ok $@ =~ /invalid character/;
+eval { JSON->new->decode ('[5') }; ok $@ =~ /parsing array/;
+eval { JSON->new->decode ('{"5"') }; ok $@ =~ /':' expected/;
+eval { JSON->new->decode ('{"5":null') }; ok $@ =~ /parsing object/;
+
+eval { JSON->new->decode (undef) }; ok $@ =~ /malformed/;
+eval { JSON->new->decode (\5) }; ok !!$@; # Can't coerce readonly
+eval { JSON->new->decode ([]) }; ok $@ =~ /malformed/;
+eval { JSON->new->decode (\*STDERR) }; ok $@ =~ /malformed/;
+eval { JSON->new->decode (*STDERR) }; ok !!$@; # cannot coerce GLOB
+
+eval { decode_json ("\"\xa0") }; ok $@ =~ /malformed.*character/;
+eval { decode_json ("\"\xa0\"") }; ok $@ =~ /malformed.*character/;
+
« no previous file with comments | « third_party/JSON/JSON-2.59/t/01_utf8.t ('k') | third_party/JSON/JSON-2.59/t/03_types.t » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698