8d2e299d0784bb42826bec1d10478871ad4af528
[gitmo/MooseX-Storage.git] / t / 040_basic_utils.t
1 use strict;
2 use warnings;
3
4 use Test::More tests => 5;
5
6 BEGIN {
7     use_ok('MooseX::Storage');
8     use_ok('MooseX::Storage::Util');
9 }
10
11 my $packed = {
12     __CLASS__ => 'Foo',
13     number    => 10,
14     string    => 'foo',
15     float     => 10.5,
16     array     => [ 1 .. 10 ],
17     hash      => { map { $_ => undef } ( 1 .. 10 ) },
18     object    => {
19        __CLASS__ => 'Foo',
20        number    => 2
21     },
22 };
23
24 my $json = '{"array":[1,2,3,4,5,6,7,8,9,10],"hash":{"6":null,"3":null,"7":null,"9":null,"2":null,"8":null,"1":null,"4":null,"10":null,"5":null},"float":10.5,"object":{"number":2,"__CLASS__":"Foo"},"number":10,"__CLASS__":"Foo","string":"foo"}';
25 my $yaml = q{---
26 __CLASS__: Foo
27 array:
28   - 1
29   - 2
30   - 3
31   - 4
32   - 5
33   - 6
34   - 7
35   - 8
36   - 9
37   - 10
38 float: 10.5
39 hash:
40   1: ~
41   10: ~
42   2: ~
43   3: ~
44   4: ~
45   5: ~
46   6: ~
47   7: ~
48   8: ~
49   9: ~
50 number: 10
51 object:
52   __CLASS__: Foo
53   number: 2
54 string: foo
55 };
56
57 is('Foo', MooseX::Storage::Util->peek($packed),
58    '... got the right class name from the packed item');
59
60 SKIP: {
61     my $classname = eval {
62         MooseX::Storage::Util->peek($json => ('format' => 'JSON'))
63     };
64     if ($@ =~ /^Could not load JSON module because/) {
65         skip "No JSON module found", 1;
66     }
67
68     is('Foo', $classname,
69        '... got the right class name from the json item');
70 }
71
72 SKIP: {
73     my $classname = eval {
74         MooseX::Storage::Util->peek($yaml => ('format' => 'YAML'))
75     };
76     if ($@ =~ /^Could not load YAML module because/
77         or $@ =~ /^Can't locate Best/
78     ) {
79         skip "No YAML module found", 1;
80     }
81
82     is('Foo', $classname,
83        '... got the right class name from the yaml item');
84 }
85
86