X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F011_basic_json_w_utf8.t;h=7a84b40a9855cbd32b51a9d10a2945c322cd1b00;hb=5ea6506e2028474a7392705366283b607d2c8abb;hp=329f64b75c02de3cbb2a9fcb78f4779791e68021;hpb=81a84db6ebe5ec540d0035fc6d1104cc49c81e25;p=gitmo%2FMooseX-Storage.git diff --git a/t/011_basic_json_w_utf8.t b/t/011_basic_json_w_utf8.t index 329f64b..7a84b40 100644 --- a/t/011_basic_json_w_utf8.t +++ b/t/011_basic_json_w_utf8.t @@ -3,25 +3,22 @@ use warnings; use Test::More; +# NOTE: +# this is because JSON::XS (and Cpanel::JSON::XS) is +# the only one which really gets utf8 correct +# - SL +BEGIN { + $ENV{JSON_ANY_ORDER} = 'XS CPANEL'; + $ENV{JSON_ANY_CONFIG} = "utf8=0,canonical=1"; +} + use Test::Requires { 'Encode' => 0.01, # skip all if not installed 'JSON::Any' => 0.01, }; -BEGIN { - # NOTE: - # this is because JSON::XS is - # the only one which really gets - # utf8 correct - # - SL - BEGIN { - $ENV{JSON_ANY_ORDER} = qw(XS); - $ENV{JSON_ANY_CONFIG} = "utf8=0,canonical=1"; - } - - plan tests => 16; - use_ok('MooseX::Storage'); -} +plan tests => 16; +use_ok('MooseX::Storage'); { package Foo; @@ -29,7 +26,7 @@ BEGIN { use MooseX::Storage; with Storage( 'format' => 'JSON' ); - + has 'utf8_string' => ( is => 'rw', isa => 'Str', @@ -49,14 +46,14 @@ BEGIN { my $foo2 = Foo->thaw($json); isa_ok( $foo, 'Foo' ); - - is($foo2->utf8_string, - "ネットスーパー (Internet Shopping)", + + is($foo2->utf8_string, + "ネットスーパー (Internet Shopping)", '... got the string we expected'); - + is($foo2->freeze, '{"__CLASS__":"Foo","utf8_string":"ネットスーパー (Internet Shopping)"}', - '... got the right JSON'); + '... got the right JSON'); } { @@ -66,15 +63,15 @@ BEGIN { $test_string = "ネットスーパー (Internet Shopping)"; no utf8; } - + ok(utf8::is_utf8($test_string), '... got a utf8 string'); - ok(utf8::valid($test_string), '... got a valid utf8 string'); - + ok(utf8::valid($test_string), '... got a valid utf8 string'); + Encode::_utf8_off($test_string); - + ok(!utf8::is_utf8($test_string), '... no longer is utf8 string'); - ok(utf8::valid($test_string), '... got a valid utf8 string'); - + ok(utf8::valid($test_string), '... got a valid utf8 string'); + my $foo = Foo->new( utf8_string => $test_string ); @@ -84,11 +81,11 @@ BEGIN { ok(utf8::valid($foo->utf8_string), '... but is a valid utf8 string'); my $json = $foo->freeze; - + ok(utf8::is_utf8($json), '... is a utf8 string now'); - ok(utf8::valid($json), '... got a valid utf8 string'); + ok(utf8::valid($json), '... got a valid utf8 string'); is($json, '{"__CLASS__":"Foo","utf8_string":"ネットスーパー (Internet Shopping)"}', - '... got the right JSON'); + '... got the right JSON'); }