Revert "Whitespace trim tests", this was clearly retarded of
[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 use File::Temp qw(tempdir);
8 use File::Spec::Functions;
9 my $dir = tempdir( CLEANUP => 1 );
10
11 BEGIN {  
12     eval "use JSON::Any";
13     plan skip_all => "JSON::Any is required for this test" if $@;    
14     # NOTE: 
15     # this is because JSON::XS is 
16     # the only one which really gets
17     # utf8 correct
18     # - SL 
19     BEGIN { 
20         $ENV{JSON_ANY_ORDER}  = qw(XS);
21         $ENV{JSON_ANY_CONFIG} = "utf8=1";        
22     }           
23     plan tests => 8;
24     use_ok('MooseX::Storage');
25 }
26
27 use utf8;
28
29 {
30     package Foo;
31     use Moose;
32     use MooseX::Storage;
33
34     with Storage( 'format' => 'JSON', 'io' => 'File' );
35     
36     has 'utf8_string' => (
37         is      => 'rw',
38         isa     => 'Str',
39         default => sub { "ネットスーパー (Internet Shopping)" }
40     );
41 }
42
43 my $file = catfile($dir,'temp.json');
44
45 {
46     my $foo = Foo->new;
47     isa_ok( $foo, 'Foo' );
48        
49     $foo->store($file);         
50 }
51
52 {
53     my $foo = Foo->load($file);
54     isa_ok($foo, 'Foo');
55
56     is($foo->utf8_string, 
57       "ネットスーパー (Internet Shopping)", 
58       '... got the string we expected');
59 }
60
61 no utf8;
62
63 unlink $file;
64
65 {
66     my $foo = Foo->new(
67         utf8_string => 'Escritório'
68     );
69     isa_ok( $foo, 'Foo' );
70        
71     $foo->store($file);         
72 }
73
74 {
75     my $foo = Foo->load($file);
76     isa_ok($foo, 'Foo');
77     
78     ok(utf8::is_utf8($foo->utf8_string), '... the string is still utf8');
79
80     is($foo->utf8_string, 
81       "Escritório", 
82       '... got the string we expected');
83 }
84