MooseX::Storage - added peek()
[gitmo/MooseX-Storage.git] / t / 040_basic_utils.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 5;
7
8 BEGIN {
9     use_ok('MooseX::Storage');
10     use_ok('MooseX::Storage::Util');    
11 }
12
13 my $packed = {
14     __CLASS__ => 'Foo',
15     number    => 10,
16     string    => 'foo',
17     float     => 10.5,
18     array     => [ 1 .. 10 ],
19     hash      => { map { $_ => undef } ( 1 .. 10 ) },
20     object    => { 
21        __CLASS__ => 'Foo',                
22        number    => 2 
23     },            
24 };
25
26 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"}';
27 my $yaml = q{--- 
28 __CLASS__: Foo
29 array: 
30   - 1
31   - 2
32   - 3
33   - 4
34   - 5
35   - 6
36   - 7
37   - 8
38   - 9
39   - 10
40 float: 10.5
41 hash: 
42   1: ~
43   10: ~
44   2: ~
45   3: ~
46   4: ~
47   5: ~
48   6: ~
49   7: ~
50   8: ~
51   9: ~
52 number: 10
53 object: 
54   __CLASS__: Foo
55   number: 2
56 string: foo
57 };
58
59 is(
60 'Foo', 
61 MooseX::Storage::Util->peek($packed), 
62 '... got the right class name from the packed item');
63
64 is(
65 'Foo', 
66 MooseX::Storage::Util->peek($json => ('format' => 'JSON')), 
67 '... got the right class name from the json item');
68
69 is(
70 'Foo', 
71 MooseX::Storage::Util->peek($yaml => ('format' => 'YAML')), 
72 '... got the right class name from the yaml item');
73
74