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