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