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