state $foo if 0 shouldn't warn. Spotted by Abigail.
[p5sagit/p5-mst-13.2.git] / t / op / state.t
index 57b46ab..f7db804 100644 (file)
@@ -10,7 +10,7 @@ BEGIN {
 use strict;
 use feature "state";
 
-plan tests => 46;
+plan tests => 38;
 
 ok( ! defined state $uninit, q(state vars are undef by default) );
 
@@ -20,7 +20,7 @@ sub stateful {
     state $x;
     state $y = 1;
     my $z = 2;
-    state ($t) = 3;
+    state ($t) //= 3;
     return ($x++, $y++, $z++, $t++);
 }
 
@@ -109,12 +109,11 @@ is( gen_cashier()->{bal}->(), 42, '$42 in my drawer' );
 # stateless assignment to a state variable
 
 sub stateless {
-    no warnings 'misc';
-    (state $reinitme, my $foo) = (42, 'bar');
+    state $reinitme = 42;
     ++$reinitme;
 }
 is( stateless(), 43, 'stateless function, first time' );
-is( stateless(), 43, 'stateless function, second time' );
+is( stateless(), 44, 'stateless function, second time' );
 
 # array state vars
 
@@ -130,18 +129,6 @@ is( $xsize, 0, 'uninitialized state array' );
 $xsize = stateful_array();
 is( $xsize, 1, 'uninitialized state array after one iteration' );
 
-sub stateful_array_init {
-    state @x = (1, 2);
-    push @x, 'x';
-    return $#x;
-}
-
-$xsize = stateful_array_init();
-is( $xsize, 2, 'initialized state array' );
-
-$xsize = stateful_array_init();
-is( $xsize, 3, 'initialized state array after one iteration' );
-
 # hash state vars
 
 sub stateful_hash {
@@ -155,44 +142,6 @@ is( $xhval, 0, 'uninitialized state hash' );
 $xhval = stateful_hash();
 is( $xhval, 1, 'uninitialized state hash after one iteration' );
 
-sub stateful_hash_init {
-    state %hx = (foo => 10);
-    return $hx{foo}++;
-}
-
-$xhval = stateful_hash_init();
-is( $xhval, 10, 'initialized state hash' );
-
-$xhval = stateful_hash_init();
-is( $xhval, 11, 'initialized state hash after one iteration' );
-
-# state declaration with a list
-
-sub statelist {
-    # note that this should be a state assignment, while (state $lager, state $stout) shouldn't
-    state($lager, $stout) = (11, 22);
-    $lager++;
-    $stout++;
-    "$lager/$stout";
-}
-
-my $ls = statelist();
-is($ls, "12/23", 'list assignment to state scalars');
-$ls = statelist();
-is($ls, "13/24", 'list assignment to state scalars');
-
-sub statelist2 {
-    state($sherry, $bourbon) = (1 .. 2);
-    $sherry++;
-    $bourbon++;
-    "$sherry/$bourbon";
-}
-
-$ls = statelist2();
-is($ls, "2/3", 'list assignment to state scalars');
-$ls = statelist2();
-is($ls, "3/4", 'list assignment to state scalars');
-
 # Recursion
 
 sub noseworth {