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