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