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 | |
0b173188 |
9 | use Test::Requires { |
10 | 'JSON::Any' => 0.01, # skip all if not installed |
11 | 'IO::AtomicFile' => 0.01, |
12 | }; |
13 | |
c2dae5d8 |
14 | BEGIN { |
15 | # NOTE: |
b9f532ee |
16 | # this is because JSON::XS (and Cpanel::JSON::XS) is |
6237d568 |
17 | # the only one which really gets |
18 | # utf8 correct |
c2dae5d8 |
19 | # - SL |
0b173188 |
20 | BEGIN { |
b9f532ee |
21 | $ENV{JSON_ANY_ORDER} = 'XS CPANEL'; |
cd4cef76 |
22 | $ENV{JSON_ANY_CONFIG} = "utf8=0,canonical=1"; |
0b173188 |
23 | } |
6237d568 |
24 | plan tests => 8; |
25 | use_ok('MooseX::Storage'); |
26 | } |
27 | |
28 | use 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 |
44 | my $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 | |
62 | no utf8; |
63 | |
64 | unlink $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 | |