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

Side by Side Diff: trunk/src/third_party/JSON/JSON-2.59/t/e13_overloaded_eq.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 #!/usr/bin/perl
2
3 use strict;
4 use Test::More tests => 4;
5
6 BEGIN {
7 $ENV{ PERL_JSON_BACKEND } = "JSON::backportPP";
8 }
9
10 use JSON;
11
12 my $json = JSON->new->convert_blessed;
13
14 my $obj = OverloadedObject->new( 'foo' );
15 ok( $obj eq 'foo' );
16 is( $json->encode( [ $obj ] ), q{["foo"]} );
17
18 # rt.cpan.org #64783
19 my $foo = bless {}, 'Foo';
20 my $bar = bless {}, 'Bar';
21
22 eval q{ $json->encode( $foo ) };
23 ok($@);
24 eval q{ $json->encode( $bar ) };
25 ok(!$@);
26
27
28 package Foo;
29
30 use strict;
31 use overload (
32 'eq' => sub { 0 },
33 '""' => sub { $_[0] },
34 fallback => 1,
35 );
36
37 sub TO_JSON {
38 return $_[0];
39 }
40
41 package Bar;
42
43 use strict;
44 use overload (
45 'eq' => sub { 0 },
46 '""' => sub { $_[0] },
47 fallback => 1,
48 );
49
50 sub TO_JSON {
51 return overload::StrVal($_[0]);
52 }
53
54
55 package OverloadedObject;
56
57 use overload 'eq' => sub { $_[0]->{v} eq $_[1] }, '""' => sub { $_[0]->{v} }, fa llback => 1;
58
59
60 sub new {
61 bless { v => $_[1] }, $_[0];
62 }
63
64
65 sub TO_JSON { "$_[0]"; }
66
OLDNEW
« no previous file with comments | « trunk/src/third_party/JSON/JSON-2.59/t/e12_upgrade.t ('k') | trunk/src/third_party/JSON/JSON-2.59/t/e14_decode_prefix.t » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698