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