Acme-FSM
view release on metacpan or search on metacpan
t/action/same.t view on Meta::CPAN
# $Id: same.t 564 2025-02-13 21:33:15Z whynot $
# Copyright 2012, 2013, 2022 Eric Pozharski <whynot@pozharski.name>
# Copyright 2025 Eric Pozharski <wayside.ultimate@tuta.io>
# GNU GPLv3
# AS-IS, NO-WARRANTY, HOPE-TO-BE-USEFUL
use strict;
use warnings;
package main;
use version 0.77; our $VERSION = version->declare( v2.3.3 );
use t::TestSuite qw| :run :diag |;
use Test::More;
plan tests => 41;
use Acme::FSM;
our( %st, $rc, %opts, $stderr );
our @inbase = ( undef,
q|Kraljevo|, undef,
qw| Seattle Charlottesvill |, undef,
qw| Malaysia Marseille LasVegas |, undef,
qw| Purdue Women Pittsburgh Sonoma |, undef );
our @input = @inbase;
$opts{source} = \&AFSMTS_shift;
my $tag;
my %common =
( state => q|STOP|,
diag_level => 1,
namespace => undef,
source => $opts{source},
dumper => undef );
%st =
( START =>
{ switch => sub { $_[0]->{queue} = [ ] },
tturn => [qw| workload VOID |] },
workload =>
{ tturn => [qw| workload SAME |],
fturn => [qw| STOP DONE |] },
STOP => { switch => sub { } } );
$tag = q|{tturn}:(SAME), consuming|;
$st{workload}{switch} =
sub { push @{$_[0]->{queue}}, $_[1]; @{$_[0]->{queue}} < 3 };
$st{workload}{eturn} = [qw| STOP FAIL |];
AFSMTS_wrap;
AFSMTS_deeply @{[[qw| FAIL |], { %common, action => q|FAIL|, queue => [ ]}]},
qq|$tag, consumes empty|;
is $input[0], q|Kraljevo|, qq|0-queue $tag, no items left behind|;
AFSMTS_wrap;
AFSMTS_deeply
@{[[qw| FAIL |],
{ %common, action => q|FAIL|, queue => [qw| Kraljevo |]} ]},
qq|$tag, consumes one|;
is $input[1], q|Seattle|, qq|1-queue $tag, terminator left behind|;
shift @input;
AFSMTS_wrap;
AFSMTS_deeply
@{[[qw| FAIL |],
{ %common, action => q|FAIL|, queue => [qw| Seattle |]} ]},
qq|$tag, consumes two|;
is $input[0], q|Charlottesvill|, qq|2-queue, $tag, 1 item left behind|;
shift @input for 0 .. 1;
AFSMTS_wrap;
AFSMTS_deeply
@{[[qw| FAIL |],
{ %common, action => q|FAIL|, queue => [qw| Malaysia |]} ]},
qq|$tag, consumes three|;
is $input[0], q|Marseille|, qq|3-queue, $tag, 2 items left behind|;
shift @input for 0 .. 2;
AFSMTS_wrap;
AFSMTS_deeply
( run in 1.876 second using v1.01-cache-2.11-cpan-39bf76dae61 )