Acme-FSM

 view release on metacpan or  search on metacpan

t/process/parse.t  view on Meta::CPAN

    eturn  => [qw| STOP      finish |],
    tturn  => [qw| BREAK        fix |],
    fturn  => [qw| white_queen SAME |]                    },
  BREAK           =>
  { switch => sub { my $self = shift @_; $self->{octet} } },
  CONTINUE        =>
  { switch => sub {                 1 },
    eturn  => [qw| STOP       finish |],
    tturn  => [qw| white_rabbit SAME |]                   } );

@inbase =
([ q||,                    undef, undef ],
 [ q|0|,                   undef,     0 ],
 [ q|3|,                   undef,     3 ],
 [ q| 8|,                  undef,     8 ],
 [ q|4 |,                  undef,     4 ],
 [ q| 7 |,                 undef,     7 ],
 [ q|x6|,             q|no left|, undef ],
 [ q|3s|,               q|no op|,     3 ],
 [ q|h6n|,            q|no left|, undef ],
 [ q|71|,                  undef,    71 ],
 [ q| 99|,                 undef,    99 ],
 [ q|06 |,                 undef,     6 ],
 [ q|40+|,           q|no right|,    40 ],
 [ q|38-|,           q|no right|,    38 ],
 [ q|+16|,            q|no left|, undef ],
 [ q|-84|,            q|no left|, undef ],
 [ q|93+81|,               undef,   174 ],
 [ q| 76+75|,              undef,   151 ],
 [ q|56 +15|,              undef,    71 ],
 [ q|21+ 64|,              undef,    85 ],
 [ q|38+35 |,              undef,    73 ],
 [ q| 36 + 22 |,           undef,    58 ],
 [ q|1+0|,                 undef,     1 ],
 [ q|0+26|,                undef,    26 ],
 [ q|36+y|,          q|no right|,    36 ],
 [ q|17++|,          q|no right|,    17 ],
 [ q|75+13+22|,            undef,   110 ],
 [ q|42+16 + 35|,          undef,    93 ],
 [ q|5+52+w|,        q|no right|,    57 ],
 [ q|22+8i|,            q|no op|,    22 ],
 [ q|10+75+-|,       q|no right|,    85 ],
 [ q| 36 + 62 + 88 + 39 |, undef,   225 ] );

plan tests => scalar @inbase;

sub do_stuff ( )    {
    $bb->action eq q|fail|                                         and return;
    $bb->{fail} = q|no right|           if $bb->{op} && !defined $bb->{right};
    $bb->{fail}                                                    and return;
    $bb->{left} = eval qq|$bb->{left} $bb->{op} $bb->{right}|               if
      $bb->{op} && defined $bb->{right};
    $bb->{left} = eval qq|$bb->{left}|                 if defined $bb->{left};
    delete $bb->{right};
    delete $bb->{op} }

while( my $input = shift @inbase )                                {
    @input = split m{}, $input->[0];
    AFSMTS_wrap;
    do_stuff;
    until( $bb->state eq q|STOP| ) { AFSMTS_method_wrap q|process|; do_stuff }
    is_deeply
    [ $bb->action, @$bb{qw| fail left |} ], [ q|finish|, @$input[1 .. 2] ],
      sprintf q|(%s) (%s) (%s)|,
        $input->[0], $bb->{left} // q|(undef)|, $bb->{fail} // q|| }

# vim: set filetype=perl



( run in 0.471 second using v1.01-cache-2.11-cpan-39bf76dae61 )