Changeset 1749

Show
Ignore:
Timestamp:
01/15/06 00:55:33
Author:
miyagawa
Message:

0.03: ImplicitUnicode? option and tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • JSON-Syck/trunk/Changes

    r1744 r1749  
     10.03 2006/01/13 
     2        * Adds Unicode flag document and tests 
     3 
    140.02 2006/01/12 
    25        * Now handles non-ASCII utf-8 byte strings correctly 
  • JSON-Syck/trunk/MANIFEST

    r1726 r1749  
    2424ppport.h 
    2525ppport_math.h 
    26 Storable.xs 
    2726syck.h 
    2827Syck.xs 
  • JSON-Syck/trunk/lib/JSON/Syck.pm

    r1744 r1749  
    55use DynaLoader; 
    66 
    7 our $VERSION = '0.02'; 
     7our $VERSION = '0.03'; 
    88our @EXPORT_OK  = qw( Dump Load ); 
    99our @ISA     = qw( Exporter DynaLoader ); 
     
    5353Oh, and JSON::Syck doesn't use camelCase method names :-) 
    5454 
     55=head1 UNICODE FLAGS 
     56 
     57By default this module doesn't touch any of Unicode flags, and assumes 
     58UTF-8 bytes to be passed and emit as an interface. However, when you 
     59set C<$JSON::Syck::ImplicitUnicode> to 1, this module properly decodes 
     60UTF-8 binaries and sets Unicode flag everywhere, as in: 
     61 
     62  JSON (UTF-8 bytes)     => Perl (Unicode flagged) 
     63  JSON (Unicode flagged) => Perl (Unicode flagged) 
     64  Perl (UTF-8 bytes)     => JSON (Unicode flagged) 
     65  Perl (Unicode flagged) => JSON (Unicode flagged) 
     66 
    5567=head1 AUTHORS 
    5668 
  • JSON-Syck/trunk/perl_syck.h

    r1744 r1749  
    3535#  define SEQ_NONE      seq_none 
    3636#  define MAP_NONE      map_none 
    37 #  define COND_FOLD(x)  (SvUTF8(sv) 
     37#  define COND_FOLD(x)  (SvUTF8(sv)) 
    3838#  define TYPE_IS_NULL(x) (x == NULL) 
    3939#  define OBJOF(a)        (*tag ? tag : a) 
  • JSON-Syck/trunk/t/01_json.t

    r1744 r1749  
    2727); 
    2828 
    29 plan tests => scalar @tests * (1 + $HAS_JSON)
     29plan tests => scalar @tests * (1 + $HAS_JSON) * 2
    3030 
    31 for my $test (@tests) { 
    32     my $data = eval { JSON::Syck::Load($test) }; 
    33     my $json = JSON::Syck::Dump($data); 
     31for my $unicode (0, 1) { 
     32    local $JSON::Syck::ImplicitUnicode = $unicode; 
     33    for my $test (@tests) { 
     34        my $data = eval { JSON::Syck::Load($test) }; 
     35        my $json = JSON::Syck::Dump($data); 
     36        utf8::encode($json) if !ref($json) && $unicode; 
    3437 
    35     # don't bother white spaces 
    36     for ($test, $json) { 
    37         s/([,:]) /$1/eg; 
    38    
     38        # don't bother white spaces 
     39        for ($test, $json) { 
     40            s/([,:]) /$1/eg; 
     41       
    3942 
    40     my $desc = "roundtrip $test -> " . Dumper($data) . " -> $json"; 
    41     utf8::encode($desc); 
    42     is $json, $test, $desc; 
     43        my $desc = "roundtrip $test -> " . Dumper($data) . " -> $json"; 
     44        utf8::encode($desc); 
     45        is $json, $test, $desc; 
    4346 
    44     # try parsing the data with JSON.pm 
    45     if ($HAS_JSON) { 
    46         my $data_pp = eval { JSON::jsonToObj($json) }; 
    47         is_deeply $data_pp, $data, "compatibility with JSON.pm $test"; 
     47        # try parsing the data with JSON.pm 
     48        if ($HAS_JSON) { 
     49            utf8::encode($data) if !ref($data) && $unicode; 
     50            my $data_pp = eval { JSON::jsonToObj($json) }; 
     51            is_deeply $data_pp, $data, "compatibility with JSON.pm $test"; 
     52        } 
    4853    } 
    4954} 
     55