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