### ----------------------------------------------------
### -- Iter::Able
### -- Licenses: Artistic-2.0
### -- Authors: 
### -- File: t/05-enumerate.rakutest
### ----------------------------------------------------
use Test;
use Iter::Able::Enumerate;

my &id = -> \g, \e, Str $desc? { g | e ~~ Seq:D ?? cmp-ok(g, "eqv", e, $desc) !! is-deeply(g, e, $desc) };

plan 10;

my $s;
$s := [2, 2, 3, 4];
id enumerate($s), [(0, 2), (1, 2), (2, 3), (3, 4)].Seq, "Random list with default start";

$s := [2, 2, 3, 4];
id enumerate($s, start => 1), [(1, 2), (2, 2), (3, 3), (4, 4)].Seq, "Random list with start => 1";

$s := [2, 2, 3, 4].Seq;
id enumerate($s, start => -1), [(-1, 2), (0, 2), (1, 3), (2, 4)].Seq, "Seq with start => -1";

$s := [2, 2, 3, 4];
id enumerate($s, start => 0), [(0, 2), (1, 2), (2, 3), (3, 4)].Seq, "Random list with start => 0 explicitly";

$s := [];
id enumerate($s), [].Seq,  "Empty-list";

$s := "yes";
id enumerate($s), [(0, "y"), (1, "e"), (2, "s")].Seq, "String with default start";

$s := (3, 3, 3, 4, 4, 4, 4, 5, 3);
my \it = $s.iterator;
it.pull-one for ^3;
my \newit = enumerate(it, start => pi);
it.pull-one;  # should affect `newit`s behaviour
does-ok newit, Iterator, "Iterator (returned an Iterator, not a Seq)";
id Seq.new(newit), [(pi, 4), (pi + 1, 4), (pi + 2, 4), (pi + 3, 5), (pi + 4, 3)].Seq, "Iterator (values)";
ok it.pull-one =:= IterationEnd, "Iterator (original, exhausted)";
ok newit.pull-one =:= IterationEnd, "Iterator (new, exhausted)";

done-testing;


