ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/t/08_pc_base.t
(Generate patch)

Comparing JSON-XS/t/08_pc_base.t (file contents):
Revision 1.1 by root, Fri Mar 23 15:10:56 2007 UTC vs.
Revision 1.3 by root, Thu Mar 29 02:45:49 2007 UTC

1use Test::More; 1use Test::More;
2 2
3# copied over from JSON::PC and modified to use JSON::XS 3# copied over from JSON::PC and modified to use JSON::XS
4 4
5use strict; 5use strict;
6BEGIN { plan tests => 22 }; 6BEGIN { plan tests => 20 };
7use JSON::XS; 7use JSON::XS;
8 8
9my ($js,$obj); 9my ($js,$obj);
10 10
11my $pc = new JSON::XS; 11my $pc = new JSON::XS;
79 79
80$js = '{"id":"}'; 80$js = '{"id":"}';
81eval q{ $pc->decode($js) }; 81eval q{ $pc->decode($js) };
82like($@, qr/unexpected end/i); 82like($@, qr/unexpected end/i);
83 83
84$obj = { foo => sub { "bar"; } }; 84$obj = { foo => sub { "bar" } };
85eval q{ $js = $pc->encode($obj) }; 85eval q{ $js = $pc->encode($obj) };
86like($@, qr/JSON can only/i, 'invalid value (coderef)'); 86like($@, qr/JSON can only/i, 'invalid value (coderef)');
87
88
89$obj = { foo => *STDERR };
90$js = $pc->encode($obj);
91is($js, '{"foo":"*main::STDERR"}', "type blog");
92
93$obj = { foo => \*STDERR };
94eval q{ $js = $pc->encode($obj) };
95like($@, qr/JSON can only/i, 'invalid value (ref of type blog)');
96 87
97#$obj = { foo => bless {}, "Hoge" }; 88#$obj = { foo => bless {}, "Hoge" };
98#eval q{ $js = $pc->encode($obj) }; 89#eval q{ $js = $pc->encode($obj) };
99#like($@, qr/JSON can only/i, 'invalid value (blessd object)'); 90#like($@, qr/JSON can only/i, 'invalid value (blessd object)');
100 91
101$obj = { foo => \$js }; 92$obj = { foo => \$js };
102eval q{ $js = $pc->encode($obj) }; 93eval q{ $js = $pc->encode($obj) };
103like($@, qr/JSON can only/i, 'invalid value (ref)'); 94like($@, qr/cannot encode reference/i, 'invalid value (ref)');
104 95

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines