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

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