### ----------------------------------------------------
### -- Iter::Able
### -- Licenses: Artistic-2.0
### -- Authors: 
### -- File: t/12-flatten.rakutest
### ----------------------------------------------------
use Test;
use Iter::Able::Flatten;

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

plan 9;

my $s;
$s := [1, 2, 3];
id flatten($s), $s.Seq, "Random list with 0 level";

$s := ((1, 2), (3, 4, 5), 6);
id flatten($s), (1, 2, 3, 4, 5, 6).Seq, "Random list with 0, 1 level";

$s := [[[2, 4],], [[5, 6], [7, 77, 777]]].Seq;
id flatten($s), [2, 4, 5, 6, 7, 77, 777].Seq, "Seq with 2 levels";

$s := [["a", ("b", "c")], [("d",), "e", "f", ["g", ("h", "i")]]];
id $s.&flatten, "abcdefghi".comb, "Ragged list";

# Note: following 2 are *not* expected to return Seqs
$s := ((1, (2, 3)), (4, 5, 6), 7);
id $s.&flatten(:1level), (1, (2, 3), 4, 5, 6, 7), "Explicit 1-level flattening";

$s := [["a", ("b", ("c", "d"))], [[[["e"],],],]];
id $s.&flatten(:2levels), ["a", "b", ("c", "d"), [["e"],]], "Explicit 2-level flattening and using the alias";

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

$s := [(3, 4), 5, (6,)];
id flatten($s), [3, 4, 5, 6].Seq, "Itemizations are not respected";

$s := [[1, 2], [[[3, 4], [5]], [[[[6, 7],],],]]];
my \it = $s.iterator;
it.pull-one;
id it.&flatten, [3, 4, 5, 6, 7].Seq, "Iterator flattening";

done-testing;


