Skip to content

Commit

Permalink
[t/spec] Fudge state.t for forthcoming Rakudo commit; we can pass hal…
Browse files Browse the repository at this point in the history
…f of it (of the missing ten tests, six we can't do yet due to other missing features, four a probably bugs in the first cut of state).

git-svn-id: http://svn.pugscode.org/pugs@25865 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information
jnthn committed Mar 17, 2009
1 parent a29ae0f commit a269417
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions S04-declarations/state.t
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ plan 20;

# state will first {...}
#?pugs eval "parse error"
#?rakudo todo 'will first { ... }'
{
my ($a, $b);
my $gen = {
Expand All @@ -66,6 +67,7 @@ plan 20;
}

# Return of a reference to a state() var
#?rakudo skip 'references'
{
my $gen = {
state $svar = 42;
Expand All @@ -83,6 +85,7 @@ plan 20;
# Anonymous state vars
# L<http://groups.google.de/group/perl.perl6.language/msg/07aefb88f5fc8429>
#?pugs todo 'anonymous state vars'
#?rakudo skip 'references and anonymous state vars'
{
# XXX -- currently this is parsed as \&state()
my $gen = eval '{ try { \state } }';
Expand Down Expand Up @@ -112,6 +115,7 @@ plan 20;
}

# state() inside regular expressions
#?rakudo skip 'embedded closures in regexen'
{
my $str = "abc";

Expand All @@ -130,14 +134,13 @@ plan 20;
}

# state() inside subs, chained declaration
#?rakudo skip 'state bug'
{
sub step () {
state $svar = state $svar2 = 42;
try {
$svar++;
$svar2--;
return (+$svar, +$svar2);
}
$svar++;
$svar2--;
return (+$svar, +$svar2);
};

is(step().perl, "(43, 41)", "chained state (#1)");
Expand All @@ -158,24 +161,26 @@ plan 20;
}

# recursive state with list assignment initialization happens only first time
#?rakudo skip 'recurses infinitely'
{
my $seensize;
my sub fib (UInt $n) {
state @seen = 0,1,1;
$seensize = +@seen;
@seen[$n] //= fib($n-1) + fib($n-2);
my sub fib (Int $n) {
state @seen = 0,1,1;
$seensize = +@seen;
@seen[$n] //= fib($n-1) + fib($n-2);
}
is fib(10), 55, "fib 1 works";
is $seensize, 11, "list assignment state in fib memoizes";
}

# recursive state with [list] assignment initialization happens only first time
#?rakudo skip '@$foo syntax'
{
my $seensize;
my sub fib (UInt $n) {
state $seen = [0,1,1];
$seensize = +@$seen;
$seen[$n] //= fib($n-1) + fib($n-2);
my sub fib (Int $n) {
state $seen = [0,1,1];
$seensize = +@$seen;
$seen[$n] //= fib($n-1) + fib($n-2);
}
is fib(10), 55, "fib 2 works";
is $seensize, 11, "[list] assignment state in fib memoizes";
Expand Down

0 comments on commit a269417

Please sign in to comment.