fixing the traits
[gitmo/MooseX-Storage.git] / t / 104_io_w_utf8.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 BEGIN {  
9     eval "use JSON::Any";
10     plan skip_all => "JSON::Any is required for this test" if $@;    
11     # NOTE: 
12     # this is because JSON::XS is 
13     # the only one which really gets
14     # utf8 correct
15     # - SL 
16     BEGIN { 
17         $ENV{JSON_ANY_ORDER}  = qw(XS);
18         $ENV{JSON_ANY_CONFIG} = "utf8=1";        
19     }           
20     plan tests => 8;
21     use_ok('MooseX::Storage');
22 }
23
24 use utf8;
25
26 {
27     package Foo;
28     use Moose;
29     use MooseX::Storage;
30
31     with Storage( 'format' => 'JSON', 'io' => 'File' );
32     
33     has 'utf8_string' => (
34         is      => 'rw',
35         isa     => 'Str',
36         default => sub { "ネットスーパー (Internet Shopping)" }
37     );
38 }
39
40 my $file = 'temp.json';
41
42 {
43     my $foo = Foo->new;
44     isa_ok( $foo, 'Foo' );
45        
46     $foo->store($file);         
47 }
48
49 {
50     my $foo = Foo->load($file);
51     isa_ok($foo, 'Foo');
52
53     is($foo->utf8_string, 
54       "ネットスーパー (Internet Shopping)", 
55       '... got the string we expected');
56 }
57
58 no utf8;
59
60 unlink $file;
61
62 {
63     my $foo = Foo->new(
64         utf8_string => 'Escritório'
65     );
66     isa_ok( $foo, 'Foo' );
67        
68     $foo->store($file);         
69 }
70
71 {
72     my $foo = Foo->load($file);
73     isa_ok($foo, 'Foo');
74     
75     ok(utf8::is_utf8($foo->utf8_string), '... the string is still utf8');
76
77     is($foo->utf8_string, 
78       "Escritório", 
79       '... got the string we expected');
80 }
81
82 unlink $file;