Skip to content

Commit

Permalink
Some updates to S29-list.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.pugscode.org/pugs@21162 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information
pmichaud committed Jul 2, 2008
1 parent 368ec90 commit 0960758
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
20 changes: 11 additions & 9 deletions S29-list/grep.t
Expand Up @@ -23,7 +23,7 @@ my @list = (1 .. 10);
is(@result[4], 9, 'got the value we expected');
}

#?rakudo skip "adverbial closure"
#?rakudo skip "adverbial block"
{
my @result = @list.grep():{ ($_ % 2) };
is(+@result, 5, 'we got a list back');
Expand All @@ -34,7 +34,7 @@ my @list = (1 .. 10);
is(@result[4], 9, 'got the value we expected');
}

#?rakudo skip "adverbial closure"
#?rakudo skip "adverbial block"
{
my @result = @list.grep :{ ($_ % 2) };
is(+@result, 5, 'we got a list back');
Expand All @@ -45,18 +45,20 @@ my @list = (1 .. 10);
is(@result[4], 9, 'got the value we expected');
}

#?rakudo skip "adverbial closure"
#?rakudo skip "closure as non-final argument"
{
my @result = grep { ($_ % 2) }: @list;
is(+@result, 5, 'we got a list back');
is(@result[0], 1, 'got the value we expected');
is(@result[1], 3, 'got the value we expected');
is(@result[2], 5, 'got the value we expected');
is(@result[3], 7, 'got the value we expected');
is(@result[4], 9, 'got the value we expected');
is(+@result, 5, 'we got a list back');
is(@result[0], 1, 'got the value we expected');
is(@result[1], 3, 'got the value we expected');
is(@result[2], 5, 'got the value we expected');
is(@result[3], 7, 'got the value we expected');
is(@result[4], 9, 'got the value we expected');
}

# .grep shouldn't work on non-arrays
## XXX pmichaud, 2008-07-01:
## p6l says that .grep should work on non-list values.
{
#?pugs 2 todo 'bug'
dies_ok { 42.grep: { $_ } }, "method form of grep should not work on numbers";
Expand Down
16 changes: 10 additions & 6 deletions S29-list/map.t
Expand Up @@ -23,7 +23,7 @@ my @list = (1 .. 5);
is(@result[4], 10, 'got the value we expected');
}

#?rakudo skip "adverbial closure"
#?rakudo skip "adverbial block"
{
my @result = @list.map():{ $_ * 2 };
is(+@result, 5, 'we got a list back');
Expand All @@ -44,7 +44,7 @@ my @list = (1 .. 5);
is(@result[4], 10, 'got the value we expected');
}

#?rakudo skip "colon invocant syntax"
#?rakudo skip "closure as non-final argument"
{
my @result = map { $_ * 2 }: @list;
is(+@result, 5, 'we got a list back');
Expand Down Expand Up @@ -100,7 +100,7 @@ my @list = (1 .. 5);
}

# map with n-ary functions
#?rakudo skip "colon invocant syntax"
#?rakudo skip "adverbial block"
{
is ~(1,2,3,4).map:{ $^a + $^b }, "3 7", "map() works with 2-ary functions";
is ~(1,2,3,4).map:{ $^a + $^b + $^c }, "6 4", "map() works with 3-ary functions";
Expand All @@ -109,11 +109,12 @@ my @list = (1 .. 5);
}

# .map shouldn't work on non-arrays
## XXX pmichaud, 2008-07-01: .map should work on non-list values
{
#?pugs 2 todo 'bug'
dies_ok { 42.map: { $_ } }, "method form of map should not work on numbers";
dies_ok { "str".map: { $_ } }, "method form of map should not work on strings";
#?rakudo skip "colon invocant syntax"
#?rakudo skip "adverbial block"
is ~(42,).map:{ $_ }, "42", "method form of map should work on arrays";
};

Expand All @@ -130,7 +131,10 @@ should be equivalent to
=end pod

#?rakudo skip "colon invocant syntax"
## XXX pmichaud, 2008-07-01: As the test is written below, the
## @expected and "map of ..." arguments are arguments of .map(...)
## and not of is(...). See S12:406.
#?rakudo skip "syntax error in test"
{
my @expected = ("foo","bar");
@expected = map { substr($_,1,1) }: @expected;
Expand All @@ -139,7 +143,7 @@ should be equivalent to
}


#?rakudo skip "no hashes at the moment"
#?rakudo skip '{} hash composer not implemented'
{
my @a = (1, 2, 3);
# XXX is hash { ... } legal?
Expand Down
6 changes: 4 additions & 2 deletions S29-list/reduce.t
Expand Up @@ -20,8 +20,9 @@ plan 11;
my $sum = 5 + -3 + 7 + 0 + 1 + -9; # laziness :)

is((reduce { $^a + $^b }, 0, @array), $sum, "basic reduce works (1)");
#?rakudo 2 skip 'adverbial closure'
#?rakudo skip 'closure as non-final argument'
is((reduce { $^a + $^b }: 100, @array), 100 + $sum, "basic reduce works (2)");
#?rakudo skip 'method fallback to sub unimpl'
is(({ $^a * $^b }.reduce: 1,2,3,4,5), 120, "basic reduce works (3)");
}

Expand All @@ -34,14 +35,15 @@ plan 11;
}

# .reduce shouldn't work on non-arrays
## XXX pmichaud, 2008-07-01: .reduce should work on non-list values
{
#?pugs 2 todo 'bug'
dies_ok { 42.reduce: { $^a + $^b } }, "method form of reduce should not work on numbers";
dies_ok { "str".reduce: { $^a + $^b } }, "method form of reduce should not work on strings";
is ((42,).reduce: { $^a + $^b }), 42, "method form of reduce should work on arrays";
}

#?rakudo 4 skip 'parsefail'
#?rakudo 4 skip '{} hash composer not implemented'
{
my $hash = {a => {b => {c => 42}}};
my @reftypes;
Expand Down
9 changes: 5 additions & 4 deletions S29-list/sort.t
Expand Up @@ -36,16 +36,16 @@ plan 21;
is(@s, @e, '... with explicit spaceship');
}

#?rakudo skip "adverbial closure"
#?rakudo skip "closure as non-final argument"
{
my @a = (2, 45, 6, 1, 3);
my @e = (1, 2, 3, 6, 45);

my @s = sort { $^a <=> $^b }: @a;
is(@s, @e, '... with closure as indirect invocant');
is(@s, @e, '... with closure as indirect invocant');
}

#?rakudo skip "adverbial closure"
#?rakudo skip "method fallback to sub unimpl"
{
my @a = (2, 45, 6, 1, 3);
my @e = (1, 2, 3, 6, 45);
Expand Down Expand Up @@ -152,7 +152,8 @@ plan 21;
}

# .sort shouldn't work on non-arrays
#?rakudo skip 'adverbial closure'
## XXX pmichaud, 2008-07-01: .sort should work on non-list values
#?rakudo skip 'test errors, adverbial block'
{
#?pugs 2 todo 'bug'
dies_ok { 42.sort: { 0 } }, "method form of sort should not work on numbers";
Expand Down

0 comments on commit 0960758

Please sign in to comment.