Commit | Line | Data |
6237d568 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
08d0f48e |
5 | use File::Temp qw(tempdir); |
5e5d4e28 |
6 | use File::Spec::Functions; |
cfd008fa |
7 | my $dir = tempdir; |
6237d568 |
8 | |
c2d52f94 |
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 | |
0b173188 |
18 | use Test::Requires { |
19 | 'JSON::Any' => 0.01, # skip all if not installed |
20 | 'IO::AtomicFile' => 0.01, |
21 | }; |
22 | |
c2d52f94 |
23 | plan tests => 8; |
24 | use_ok('MooseX::Storage'); |
6237d568 |
25 | |
26 | use utf8; |
27 | |
28 | { |
29 | package Foo; |
30 | use Moose; |
31 | use MooseX::Storage; |
32 | |
33 | with Storage( 'format' => 'JSON', 'io' => 'AtomicFile' ); |
c2dae5d8 |
34 | |
6237d568 |
35 | has 'utf8_string' => ( |
36 | is => 'rw', |
37 | isa => 'Str', |
38 | default => sub { "ネットスーパー (Internet Shopping)" } |
39 | ); |
40 | } |
41 | |
5e5d4e28 |
42 | my $file = catfile($dir, 'temp.json'); |
6237d568 |
43 | |
44 | { |
45 | my $foo = Foo->new; |
46 | isa_ok( $foo, 'Foo' ); |
c2dae5d8 |
47 | |
48 | $foo->store($file); |
6237d568 |
49 | } |
50 | |
51 | { |
52 | my $foo = Foo->load($file); |
53 | isa_ok($foo, 'Foo'); |
54 | |
c2dae5d8 |
55 | is($foo->utf8_string, |
56 | "ネットスーパー (Internet Shopping)", |
6237d568 |
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' ); |
c2dae5d8 |
69 | |
70 | $foo->store($file); |
6237d568 |
71 | } |
72 | |
73 | { |
74 | my $foo = Foo->load($file); |
75 | isa_ok($foo, 'Foo'); |
c2dae5d8 |
76 | |
6237d568 |
77 | ok(utf8::is_utf8($foo->utf8_string), '... the string is still utf8'); |
78 | |
c2dae5d8 |
79 | is($foo->utf8_string, |
80 | "Escritório", |
6237d568 |
81 | '... got the string we expected'); |
82 | } |
83 | |