### ----------------------------------------------------
### -- Iter::Able
### -- Licenses: Artistic-2.0
### -- Authors: 
### -- File: t/08-map-indexed.rakutest
### ----------------------------------------------------
use Test;
use Iter::Able::Map-Indexed;

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 := [3, 2, 1];
id $s.&map-indexed(* * *), (0, 2, 2).Seq, "Random list with `* * *`";

$s := (4, 7, 12, -3);
id $s.&map-indexed(* + *, start => 1), (5, 9, 15, 1).Seq, "Random list with `* + *` and nondefault `start`";

$s := (4, 7, 12, -3);
id $s.&map-indexed, ((0, 4), (1, 7), (2, 12), (3, -3)).Seq, "Random list with default mapper";

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

$s := [0, 0, 0, 0].Seq;
id map-indexed($s, * R/ *, start => 1), [0, 0, 0, 0]>>.Rat.Seq, "All zeros with index / item, starting at 1";

$s := "train";
id $s.&map-indexed(* Rx *, start => 1), ("t", "rr", "aaa", "iiii", "nnnnn").Seq, "String with repetition";

$s := (-2, -1, 0, 7, 77, 777);
my \it = $s.iterator;
it.pull-one for ^2;
my \newit = map-indexed(it, * R** *, start => 1);
it.pull-one;  # should affect `newit`s behaviour
does-ok newit, Iterator, "Iterator (returned an Iterator, not a Seq)";
id Seq.new(newit), ($s.skip(3) >>**<< [1, 2, 3]).Seq, "Iterator (values)";
ok it.pull-one =:= IterationEnd, "Iterator (original, exhausted)";
ok newit.pull-one =:= IterationEnd, "Iterator (new, exhausted)";

done-testing;


