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

Side by Side Diff: trunk/src/third_party/JSON/JSON-2.59/t/x12_blessed.t

Issue 16539003: Revert 205057 "Add JSON.pm to third_party" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 use strict;
2 use Test::More;
3 BEGIN { plan tests => 16 };
4
5 BEGIN { $ENV{PERL_JSON_BACKEND} = 1; }
6
7 use JSON;
8
9 SKIP: {
10 skip "can't use JSON::XS.", 16, unless( JSON->backend->is_xs );
11
12 my $o1 = bless { a => 3 }, "XX";
13 my $o2 = bless \(my $dummy = 1), "YY";
14
15 sub XX::TO_JSON {
16 {'__',""}
17 }
18
19 my $js = JSON->new;
20
21 eval { $js->encode ($o1) }; ok ($@ =~ /allow_blessed/);
22 eval { $js->encode ($o2) }; ok ($@ =~ /allow_blessed/);
23 $js->allow_blessed;
24 ok ($js->encode ($o1) eq "null");
25 ok ($js->encode ($o2) eq "null");
26 $js->convert_blessed;
27 ok ($js->encode ($o1) eq '{"__":""}');
28
29 ok ($js->encode ($o2) eq "null");
30
31 $js->filter_json_object (sub { 5 });
32 $js->filter_json_single_key_object (a => sub { shift });
33 $js->filter_json_single_key_object (b => sub { 7 });
34
35 ok ("ARRAY" eq ref $js->decode ("[]"));
36 ok (5 eq join ":", @{ $js->decode ('[{}]') });
37 ok (6 eq join ":", @{ $js->decode ('[{"a":6}]') });
38 ok (5 eq join ":", @{ $js->decode ('[{"a":4,"b":7}]') });
39
40 $js->filter_json_object;
41 ok (7 == $js->decode ('[{"a":4,"b":7}]')->[0]{b});
42 ok (3 eq join ":", @{ $js->decode ('[{"a":3}]') });
43
44 $js->filter_json_object (sub { });
45 ok (7 == $js->decode ('[{"a":4,"b":7}]')->[0]{b});
46 ok (9 eq join ":", @{ $js->decode ('[{"a":9}]') });
47
48 $js->filter_json_single_key_object ("a");
49 ok (4 == $js->decode ('[{"a":4}]')->[0]{a});
50
51 $js->filter_json_single_key_object (a => sub {});
52 ok (4 == $js->decode ('[{"a":4}]')->[0]{a});
53
54 }
OLDNEW
« no previous file with comments | « trunk/src/third_party/JSON/JSON-2.59/t/x02_error.t ('k') | trunk/src/third_party/JSON/JSON-2.59/t/x16_tied.t » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698