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