diff options
author | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2006-05-05 12:48:19 +0000 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2006-05-05 12:48:19 +0000 |
commit | a59118671308b89f1214a83fc0db2e393a19affb (patch) | |
tree | 54c564f767ad68dcbdbe66a3e5560f40066dfcfb /t/op/state.t | |
parent | 49c03c8934c87a2dcd3f60cea1f51beb84f61bd4 (diff) | |
download | perl-a59118671308b89f1214a83fc0db2e393a19affb.tar.gz |
Implement state array and state hashes. Initialisation assignment
to state arrays or hashes is not implemented yet.
p4raw-id: //depot/perl@28106
Diffstat (limited to 't/op/state.t')
-rw-r--r-- | t/op/state.t | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/t/op/state.t b/t/op/state.t index 7a82f8a440..ebe8d9b5c3 100644 --- a/t/op/state.t +++ b/t/op/state.t @@ -10,7 +10,7 @@ BEGIN { use strict; use feature "state"; -plan tests => 26; +plan tests => 30; ok( ! defined state $uninit, q(state vars are undef by default) ); @@ -110,3 +110,30 @@ sub stateless { } is( stateless(), 43, 'stateless function, first time' ); is( stateless(), 43, 'stateless function, second time' ); + +# array state vars + +sub stateful_array { + state @x; + push @x, 'x'; + return $#x; +} + +my $xsize = stateful_array(); +is( $xsize, 0, 'uninitialized state array' ); + +$xsize = stateful_array(); +is( $xsize, 1, 'uninitialized state array after one iteration' ); + +# hash state vars + +sub stateful_hash { + state %hx; + return $hx{foo}++; +} + +my $xhval = stateful_hash(); +is( $xhval, 0, 'uninitialized state hash' ); + +$xhval = stateful_hash(); +is( $xhval, 1, 'uninitialized state hash after one iteration' ); |