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