Commit | Line | Data |
6237d568 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More; |
5e5d4e28 |
7 | use File::Temp qw(tempdir); |
8 | use File::Spec::Functions; |
9 | my $dir = tempdir( CLEANUP => 1 ); |
6237d568 |
10 | |
0b173188 |
11 | use Test::Requires { |
12 | 'JSON::Any' => 0.01, # skip all if not installed |
13 | 'IO::AtomicFile' => 0.01, |
14 | }; |
15 | |
b5f363ac |
16 | BEGIN { |
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 | |
30 | use utf8; |
31 | |
32 | { |
33 | package Foo; |
34 | use Moose; |
35 | use MooseX::Storage; |
36 | |
37 | with Storage( 'format' => 'JSON', 'io' => 'File' ); |
b5f363ac |
38 | |
6237d568 |
39 | has 'utf8_string' => ( |
40 | is => 'rw', |
41 | isa => 'Str', |
42 | default => sub { "ネットスーパー (Internet Shopping)" } |
43 | ); |
44 | } |
45 | |
5e5d4e28 |
46 | my $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 | |
64 | no utf8; |
65 | |
66 | unlink $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 | |