File: iarray.t

package info (click to toggle)
libiterator-util-perl 0.02%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 136 kB
  • ctags: 12
  • sloc: perl: 234; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,229 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use strict;
use Test::More tests => 6;
use Iterator::Util;

# Check that iarray works as promised.

sub begins_with
{
    my ($actual, $expected, $test_name) = @_;

    $actual = substr($actual, 0, length $expected);
    @_ =  ($actual, $expected, $test_name);
    goto &is;
}

my ($iter, $x, @vals, @reported);

@vals = (1, 2, 'foo', [qw/a b c/]);

# basic iarray. (3)
eval
{
    $iter = iarray \@vals;
};

is $@, q{},   q{Created iarray iterator, no errors};
@reported = ();

eval
{
    push @reported, $iter->value  while $iter->isnt_exhausted;
};
is $@, q{},   q{Executed array iterator, no errors};
is_deeply (\@reported, [1, 2, 'foo', [qw/a b c/]], q{iarray returned expected values});


# changing iarray. (3)
eval
{
    $iter = iarray \@vals;
};

is $@, q{},   q{Created iarray iterator, no errors};
@reported = ();

eval
{
    push @reported, $iter->value  for (1..3);
    # Change the underlying array:
    push @vals, 'Mark Jason Dominus is God';
    $vals[0] = '666';
    push @reported, $iter->value  while $iter->isnt_exhausted;
};
is $@, q{},   q{Executed array iterator, no errors};
is_deeply (\@reported, [1, 2, 'foo', [qw/a b c/], q{Mark Jason Dominus is God}],
           q{iarray returned expected values});