Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a cacophony of slice assignment tests involving Seqs
  • Loading branch information
skids committed Sep 4, 2015
1 parent 2e1575f commit ccb5d4e
Showing 1 changed file with 81 additions and 1 deletion.
82 changes: 81 additions & 1 deletion S32-list/seq.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 8;
plan 26;

my @result = 1,2,3;

Expand Down Expand Up @@ -32,4 +32,84 @@ is-deeply @searches[0].Array, @expected-searches, 'seq => array works 3';
@n[0, 1] = <a b>.sort;
# bug found by the IRC::Utils test suite
is @n.join('|'), 'a|b', 'can assign a Seq to an array slice';
@n = 1,2;
@n[0,1] = @n Z~ <a b>;
is @n, ("1a","2b"), 'assign slice from Seq that references same array';
@n = 1,2;
@n[0,1,2] = <a b>.sort;
is @n, ["a","b", Any], 'slice assignment from seq Nils out unused indices';
@n = 2,1;
@n[@n.sort] = <a b>.sort;
is @n, (2,"a","b"), 'assign slice indexed by self-referential Seq (1)';
@n = 2,3;
@n[@n.map(*+0)] = <a b>.sort;
is @n, (2,3,"a","b"), 'assign slice indexed by self-referential Seq (2)';
@n = 0,1;
@n[@n.push(2,3)] = <a b>.sort;
is @n, ("a","b",Any,Any), 'array slice assigned from Seq evals indices first';
@n = 5,6;
@n[@n.map({ ($++,).Slip })] = <a b>.sort;
is @n, <a b>, 'array slice assigned from Seq evals index Seq first';
@n = 0,1;
@n[*-1,*-2] = <a b>.sort;
is @n, <b a>, 'WhateverCode works on array slice assigned from Seq';
@n = 0,1;
@n[*] = <a b>.sort;
is @n, <a b>, 'Whatever array slice assigned from Seq works';
@n = 0,1,2;
@n[*] = <a b>.sort;
is @n, ("a", "b", Any), 'Whatever array slice assigned from Seq Nils unassigned indices';
@n = 0,1;
my $b = 0;
@n[0,1] = (1,2).map({$b = $_});
is $b, 2, 'Array slice assigned from Seq is eager';
my @m = 0,1;
@n = 0,1;
@m[0,1] = @n[1,0,2] = <a b>.sort;
is (@m,@n), (<a b>,("b","a",Any)), 'Chained array assignment from Seq';
@n = 0,1;
@n[0,] = <a b>.sort;
is @n, ("a",1), 'single index array slice assignment from Seq';
@n = 0,1;
@n[0] = <a b>.sort;
is @n, (<a b>,1), 'single index assignment from Seq';
}
# Lazy assignment. This behavior is experimental.
{
my @n = 0,1;
eager @n.map(-> $v is rw {$v})[0,1] = <a b>.sort;
is @n, <a b>, 'Seq slice assignment works';
@n = 0,1;
my $b = 0;
@n.map(-> $v is rw {$b++; $v})[0,1] = <a b>.sort;
is $b, 0, 'Seq slice assignment is lazy';
@n = 0,1;
my @log;
eager @n.map(-> $v is rw {@log.push("A " ~ $++); $v;})[0,1] = @n.map(-> $v is rw {@log.push("B " ~ $++); $v})[0,1] = <a b>.sort;
is @n, <a b>, 'Chained Seq slice assignment works';
is @log, ("A 0","B 0","A 1","B 1"), 'Chained Seq slice assignment is lazy';
@n = 0,1;
# (NYI need to cache in sub eagerize when reifying for elems)
{ eager @n.map(-> $v is rw {$v})[*-2,*-1] = <a b>.sort, <a b>, 'WhateverCode in Seq slice assignment'; CATCH { default { $_.defined } } };
#?rakudo todo 'Cannot assign immutable'
is @n, <a b>, 'WhateverCode in Seq slice assignment';
}

0 comments on commit ccb5d4e

Please sign in to comment.