implemented cycle handling
[gitmo/MooseX-Storage.git] / t / 004_w_cycles.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More no_plan => 1;
7 use Test::Exception;
8
9 BEGIN {
10     use_ok('MooseX::Storage');
11 }
12
13 {
14
15     package Circular;
16     use Moose;
17     use MooseX::Storage;
18
19     with Storage;
20
21     has 'cycle' => (is => 'rw', isa => 'Circular');
22 }
23
24 {
25     my $circular = Circular->new;
26     isa_ok($circular, 'Circular');
27     
28     $circular->cycle($circular);
29     
30     throws_ok {
31         $circular->pack;
32     } qr/^Basic Engine does not support cycles/, 
33     '... cannot collapse a cycle with the basic engine';
34 }
35
36 {
37     my $packed_circular = { __CLASS__ => 'Circular' };
38     $packed_circular->{cycle} = $packed_circular;
39
40     throws_ok {
41         Circular->unpack($packed_circular);
42     } qr/^Basic Engine does not support cycles/, 
43     '... cannot expand a cycle with the basic engine';
44 }
45
46
47