1use strict; 2use Test::More tests => 6; 3use Iterator::Util; 4 5# Check that iarray works as promised. 6 7sub begins_with 8{ 9 my ($actual, $expected, $test_name) = @_; 10 11 $actual = substr($actual, 0, length $expected); 12 @_ = ($actual, $expected, $test_name); 13 goto &is; 14} 15 16my ($iter, $x, @vals, @reported); 17 18@vals = (1, 2, 'foo', [qw/a b c/]); 19 20# basic iarray. (3) 21eval 22{ 23 $iter = iarray \@vals; 24}; 25 26is $@, q{}, q{Created iarray iterator, no errors}; 27@reported = (); 28 29eval 30{ 31 push @reported, $iter->value while $iter->isnt_exhausted; 32}; 33is $@, q{}, q{Executed array iterator, no errors}; 34is_deeply (\@reported, [1, 2, 'foo', [qw/a b c/]], q{iarray returned expected values}); 35 36 37# changing iarray. (3) 38eval 39{ 40 $iter = iarray \@vals; 41}; 42 43is $@, q{}, q{Created iarray iterator, no errors}; 44@reported = (); 45 46eval 47{ 48 push @reported, $iter->value for (1..3); 49 # Change the underlying array: 50 push @vals, 'Mark Jason Dominus is God'; 51 $vals[0] = '666'; 52 push @reported, $iter->value while $iter->isnt_exhausted; 53}; 54is $@, q{}, q{Executed array iterator, no errors}; 55is_deeply (\@reported, [1, 2, 'foo', [qw/a b c/], q{Mark Jason Dominus is God}], 56 q{iarray returned expected values}); 57 58