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

plan 26;

my @a is ValueList = ^10;
is-deeply @a.Bool, True, 'a ValueList with elements is True';

my @b is ValueList = ^10;
is @b.WHICH, @a.WHICH, 'are @b and @a the same value type';

my $c = ValueList.new(^10);
is $c.WHICH, @a.WHICH, 'are $c and @a the same value type';

my $d = ValueList.new(^10);
is $d.WHICH, @a.WHICH, 'are $d and @a the same value type';

my $e = ValueList.new(@a);
is $e.WHICH, @a.WHICH, 'are $e and @a the same value type';

my $f = ValueList.new(@a);
is $f.WHICH, @a.WHICH, 'are $f and @a the same value type';

is $f.gist, '(0 1 2 3 4 5 6 7 8 9)', 'does .gist give the same as a List';
is $f.Str, $f.raku,  'does .Str give the same as .raku';

dies-ok { @a = 4,5,6 },  'can we not re-assign to a ValueList';
dies-ok { @a[0] = 42 },  'can we not assign to a ValueList element';
dies-ok { @a[0] := 42 }, 'can we not bind to a ValueList element';

for <
  ASSIGN-POS BIND-POS push append pop shift unshift prepend
> -> $method {
    dies-ok { @a."$method"() }, "does calling .$method die";
}

my %s is Set = ValueList.new(^2), ValueList.new(^2);
is %s.elems, 1, 'did we get 1 ValueList with "is Set"';
is set( ValueList.new(^2), ValueList.new(^2) ).elems, 1,
  'did we get 1 ValueList "set()"';

dies-ok { $_ = 42 for @a },
  'are iterated values also immutable';
dies-ok { .value = 42 for @a.pairs },
  'are iterated pairs also immutable';
dies-ok { for @a.kv -> \k, \v { v = 42 } },
  'are iterated kv also immutable';

my @g is ValueList;
is-deeply @g.Bool, False, 'an empty ValueList @g is False';

my $h = ValueList.new;
is-deeply $h.Bool, False, 'an empty ValueList $h is False';

# vim: expandtab shiftwidth=4


