root/JSON-Syck/trunk/t/01_json.t

Revision 1741 (checked in by miyagawa, 14 years ago)

merge audrey's changes and added Unicode test: still failing

  • Property svn:mime-type set to text/plain
Line 
1 use strict;
2 use Data::Dumper;
3 use Test::More;
4 use JSON::Syck;
5 use Storable;
6
7 our $HAS_JSON = 0;
8 eval { require JSON; $HAS_JSON = 1 };
9
10 $Data::Dumper::Indent = 0;
11 $Data::Dumper::Terse  = 1;
12
13 #$JSON::Syck::ImplicitUnicode = 1;
14
15 my @tests = (
16     '"foo"',
17     '[1, 2, 3]',
18     '[1, 2, 3]',
19     '2',
20     '2.1',
21     '"foo\'bar"',
22     '[1,2,3]',
23     '[1.1, 2.2, 3.3]',
24     '[1.1,2.2,3.3]',
25     '{"foo": "bar"}',
26     '{"foo":"bar"}',
27     '[{"foo": 2}, {"foo": "bar"}]',
28     qq("\xe5\xaa\xbe"),
29 );
30
31 plan tests => scalar @tests * (1 + $HAS_JSON);
32
33 my $conv = $HAS_JSON ? JSON::Converter->new : undef;
34
35 for my $test (@tests) {
36     my $data = eval { JSON::Syck::Load($test) };
37     my $json = JSON::Syck::Dump($data);
38
39     # don't bother white spaces
40     for ($test, $json) {
41         s/([,:]) /$1/eg;
42     }
43     is $json, $test, "roundtrip $test -> " . Dumper($data) . " -> $json";
44
45     # try parsing the data with JSON.pm
46     if ($HAS_JSON) {
47         my $data_pp = eval { JSON::jsonToObj($json) };
48         is_deeply $data_pp, $data, "compatibility with JSON.pm $test";
49     }
50 }
Note: See TracBrowser for help on using the browser.