7 # this is because JSON::XS (and Cpanel::JSON::XS) is
8 # the only one which really gets utf8 correct
11 $ENV{JSON_ANY_ORDER} = 'XS CPANEL';
12 $ENV{JSON_ANY_CONFIG} = "utf8=0,canonical=1";
16 'Encode' => 0.01, # skip all if not installed
21 use_ok('MooseX::Storage');
28 with Storage( 'format' => 'JSON' );
30 has 'utf8_string' => (
33 default => sub { "ネットスーパー (Internet Shopping)" }
39 isa_ok( $foo, 'Foo' );
41 my $json = $foo->freeze;
44 '{"__CLASS__":"Foo","utf8_string":"ネットスーパー (Internet Shopping)"}',
45 '... got the right JSON');
47 my $foo2 = Foo->thaw($json);
48 isa_ok( $foo, 'Foo' );
50 is($foo2->utf8_string,
51 "ネットスーパー (Internet Shopping)",
52 '... got the string we expected');
55 '{"__CLASS__":"Foo","utf8_string":"ネットスーパー (Internet Shopping)"}',
56 '... got the right JSON');
63 $test_string = "ネットスーパー (Internet Shopping)";
67 ok(utf8::is_utf8($test_string), '... got a utf8 string');
68 ok(utf8::valid($test_string), '... got a valid utf8 string');
70 Encode::_utf8_off($test_string);
72 ok(!utf8::is_utf8($test_string), '... no longer is utf8 string');
73 ok(utf8::valid($test_string), '... got a valid utf8 string');
76 utf8_string => $test_string
78 isa_ok( $foo, 'Foo' );
80 ok(!utf8::is_utf8($foo->utf8_string), '... not a utf8 string');
81 ok(utf8::valid($foo->utf8_string), '... but is a valid utf8 string');
83 my $json = $foo->freeze;
85 ok(utf8::is_utf8($json), '... is a utf8 string now');
86 ok(utf8::valid($json), '... got a valid utf8 string');
89 '{"__CLASS__":"Foo","utf8_string":"ネットスーパー (Internet Shopping)"}',
90 '... got the right JSON');