### ----------------------------------------------------
### -- OneSeq
### -- Licenses: Artistic-2.0
### -- Authors: Elizabeth Mattijsen
### -- File: t/01-basic.rakutest
### ----------------------------------------------------
use Test;
use OneSeq;

plan 21;

my @a = ^5;
my @b = @a >>> @a;
is-deeply @b, [0,1,2,3,4,0,1,2,3,4], '>>> works';

my @c = @a <<< @a;
is-deeply @c, [4,3,2,1,0,4,3,2,1,0], '<<< works';

is-deeply  [>>>],         ().Seq, '>>> used as meta-op without args';
is-deeply ([>>>] @a),     @a.Seq, '>>> used as meta-op with one args';
is-deeply ([>>>] @a, @a), @b.Seq, '>>> used as meta-op with two args';

is-deeply  [<<<],         ().Seq, '>>> used as meta-op without args';
is-deeply ([<<<] @a), @a.reverse.Seq, '>>> used as meta-op with one args';
is-deeply ([<<<] @a, @a), @c.Seq, '>>> used as meta-op with two args';

class A {
    method iterator() {
        (1,2,3,4,5).iterator
    }
}
class B {
}

is-deeply A >>> A, (1,2,3,4,5,1,2,3,4,5).Seq, '>>> just needs an iterator';
is-deeply B >>> B, (B,B).Seq, '>>> without a specific iterator';
is-deeply A <<< A, (5,4,3,2,1,5,4,3,2,1).Seq, '<<< just needs an iterator';
is-deeply B <<< B, (B,B).Seq, '<<< without a specific iterator';

my %h = a => [1,2,3], b => [4,5,6];
is-deeply ([>>>] %h.sort(*.key)>>.value), (1,2,3,4,5,6).Seq,
  '>>> can use .values';
is-deeply ([<<<] %h.sort(*.key)>>.value), (6,5,4,3,2,1).Seq,
  '<<< can use .values';

$_++ for [>>>] %h.values;
is-deeply %h, { a => [2,3,4], b => [5,6,7] }, '>>> returns containers';
$_++ for [<<<] %h.values;
is-deeply %h, { a => [3,4,5], b => [6,7,8] }, '>>> returns containers';

my @d = [>>>] 1,[2,3,4,5],6,7,[8,9],42;
is-deeply @d, [1,2,3,4,5,6,7,8,9,42], '>>> ignores containers';

@d = [<<<] 1,[2,3,4,5],6,7,[8,9],42;
is-deeply @d, [42,9,8,7,6,5,4,3,2,1], '<<< ignores containers';

my @e = @a >>> @a >>> @a;
is-deeply @e, [0,1,2,3,4,0,1,2,3,4,0,1,2,3,4], 'list-associativiy >>> works';

my @f = @a <<< @a <<< @a;
is-deeply @f, [4,3,2,1,0,4,3,2,1,0,4,3,2,1,0], 'list-associativiy <<< works';

# as a meta-op
%h = a => [0,1,2], b => [3,4,5], c => [6,7,8,9];
my @g;
@g[$_] = $_ + 1 for [>>>] %h.values;
is-deeply  @g, [1,2,3,4,5,6,7,8,9,10], 'works on arrays hash values';

# vim: expandtab shiftwidth=4


