Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 55 lines (41 sloc) 1.645 kb
61d9105 [t/spec] add S06-signature/unpack-array.t
rhr authored
1 use v6;
2 use Test;
9f54ff7 [t/spec] RT #75900
moritz authored
3 plan 13;
61d9105 [t/spec] add S06-signature/unpack-array.t
rhr authored
4
5 # L<S06/Unpacking array parameters>
6
67e4168 [t/spec] improve unpack-array.t a bit; remove item from TASK
moritz authored
7 sub foo($x, [$y, *@z]) {
8 return "$x|$y|" ~ @z.join(';');
61d9105 [t/spec] add S06-signature/unpack-array.t
rhr authored
9 }
10
67e4168 [t/spec] improve unpack-array.t a bit; remove item from TASK
moritz authored
11 my @a = 2, 3, 4, 5;
b1a7ce4 [t/spec] Correct mistake in array unpacking test, and make it work wi…
jnthn authored
12 is foo(1, @a), '1|2|3;4;5', 'array unpacking';
61d9105 [t/spec] add S06-signature/unpack-array.t
rhr authored
13
67e4168 [t/spec] improve unpack-array.t a bit; remove item from TASK
moritz authored
14 sub bar([$x, $y, $z]) {
b1a7ce4 [t/spec] Correct mistake in array unpacking test, and make it work wi…
jnthn authored
15 return $x * $y * $z;
61d9105 [t/spec] add S06-signature/unpack-array.t
rhr authored
16 }
17
67e4168 [t/spec] improve unpack-array.t a bit; remove item from TASK
moritz authored
18 ok bar(@a[0..2]) == 24, 'fixed length array unpacking';
56acbd6 [t/spec] Add more signature unpacking tests to S06-signature/unpack-a…
duff authored
19 dies_ok { bar [1,2] }, 'fixed length array unpacking too short';
20 dies_ok { bar [1,2,3,4] }, 'fixed length array unpacking too long';
21
22 sub baz([$x, $y?, $z?]) {
a8b638a @jnthn Update test for latest stringification spec; correct one test to what…
jnthn authored
23 return "$x|$y.gist()|$z.gist()";
56acbd6 [t/spec] Add more signature unpacking tests to S06-signature/unpack-a…
duff authored
24 }
25
26 dies_ok { baz( [] ) } , 'unpack optional scalars; required scalar missing';
0512ff9 @moritz more Type() -> (Type) gistification
moritz authored
27 is baz( [2] ), "2|(Any)|(Any)", 'unpack optional scalars; one required';
28 is baz( [2,3] ), "2|3|(Any)", 'unpack optional scalars; one required + one optional';
56acbd6 [t/spec] Add more signature unpacking tests to S06-signature/unpack-a…
duff authored
29 is baz( [2,3,4] ), "2|3|4", 'unpack optional scalars; one required + two optional';
30 dies_ok { baz( [2,3,4,5] ) }, 'unpack optional scalars; one required + too many optional';
31
32 sub blat ($x, @a [$a, *@b]) {
33 return $x == 1 ?? @a.join("|") !! "$a-" ~ @b.join('-');
34 }
35
36 is blat( 1, [2,3,4] ), "2|3|4", 'unpack named array';
37 is blat( 2, [2,3,4] ), "2-3-4", 'unpack named array with named pieces';
67e4168 [t/spec] improve unpack-array.t a bit; remove item from TASK
moritz authored
38
9f54ff7 [t/spec] RT #75900
moritz authored
39 # RT #75900
40 {
41 my @my-array = 4,2,3,4;
42
43 sub fsort-only([$p?,*@r]) {
44 return fsort-only(@r.grep( {$_ <= $p} )),$p,fsort-only(@r.grep( {$_ > $p} )) if $p || @r;
45 }
a8b638a @jnthn Update test for latest stringification spec; correct one test to what…
jnthn authored
46 multi fsort-multi([$p?,*@r]) {
9f54ff7 [t/spec] RT #75900
moritz authored
47 return fsort-multi(@r.grep( {$_ <= $p} )),$p,fsort-multi(@r.grep( {$_ > $p} )) if $p || @r;
48 }
49
50 is fsort-only(@my-array).join(' '), '2 3 4 4', 'array unpacking and only-subs';
51 is fsort-multi(@my-array).join(' '), '2 3 4 4', 'array unpacking and only-multi';
52 }
53
67e4168 [t/spec] improve unpack-array.t a bit; remove item from TASK
moritz authored
54 # vim: ft=perl6
Something went wrong with that request. Please try again.