1#!/usr/bin/perl -w
2
3use strict;
4use Test::More;
5use Carp;
6$SIG{__DIE__} = \&Carp::confess;
7BEGIN {
8    eval 'use Storable 2.05 qw(freeze thaw)';
9    plan skip_all => 'Storable 2.05 or later cannot be loaded.' if $@;
10
11    eval 'use B::Deparse 0.61';
12    plan skip_all => 'B::Deparse 0.61 or later cannot be loaded.' if $@;
13
14    plan tests => 12;
15    use_ok 'FSA::Rules' or die;
16}
17
18$Storable::Deparse = $Storable::Deparse || 1;
19$Storable::Eval    = $Storable::Eval || 1;
20
21ok my $fsa = FSA::Rules->new(
22    0 => { rules => [ 1 => [ 1, sub { shift->machine->{count}++ } ] ] },
23    1 => { rules => [ 0 => [ 1, sub { $_[0]->done($_[0]->machine->{count} == 3 ) } ] ] },
24),'Construct a rules object for serialization';
25
26isa_ok $fsa, 'FSA::Rules';
27is $fsa->run, $fsa, '... Run should return the FSA object';
28is $fsa->{count}, 3,
29    '... And it should have run through the proper number of iterations.';
30
31ok my $frozen = freeze($fsa), 'Freeze the FSA object';
32ok $fsa = thaw($frozen), 'Thaw the FSA object';
33isa_ok $fsa, 'FSA::Rules', 'The thawed object';
34is $fsa->{count}, 3,
35    '... And it should still have its internal data';
36
37$fsa->{count} = 0;
38is $fsa->reset, $fsa, '... We should be able to reset';
39
40is $fsa->run, $fsa, '... Run should still return the FSA object';
41is $fsa->{count}, 3,
42    '... And it should have run through the proper number of iterations.';
43
44