Permalink
Browse files

[t/spec]: Update map/grep/reduce/kv tests to work with scalar invocants.

git-svn-id: http://svn.pugscode.org/pugs@24602 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
1 parent 5474487 commit 5caad32ca190e657564524a33f4d9e1978717750 pmichaud committed Dec 24, 2008
Showing with 13 additions and 28 deletions.
  1. +1 −2 S29-array/kv.t
  2. +3 −8 S29-list/grep.t
  3. +6 −14 S29-list/map.t
  4. +3 −4 S29-list/reduce.t
View
@@ -43,5 +43,4 @@ Basic C<kv> tests, see S29.
is(~@kv, "0 a 1 b 2 c 3 d", 'kv(@array) has no inner list');
}
-# Check that (42).kv does *not* work, as this it the same as $some_int.kv:
-dies_ok { (42).kv }, "(42).kv should not and does not work";
+is( 42.kv, [1, 42], "(42).kv works");
View
@@ -9,7 +9,7 @@ built-in grep tests
=end pod
-plan 29;
+plan 28;
my @list = (1 .. 10);
@@ -56,15 +56,10 @@ my @list = (1 .. 10);
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";
- dies_ok { "str".grep: { $_ } }, "method form of grep should not work on strings";
- #?rakudo skip "Arity problem"
- is ~(42,).grep: { 1 }, "42", "method form of grep should work on arrays";
+ is(42.grep({ 1 }), "42", "method form of grep works on numbers");
+ is('str'.grep({ 1 }), 'str', "method form of grep works on strings");
}
#
View
@@ -1,6 +1,6 @@
use v6;
use Test;
-plan 60;
+plan 59;
# L<S29/"List"/"=item map">
@@ -108,15 +108,11 @@ my @list = (1 .. 5);
is ~(1,2,3,4).map:{ $^a+$^b+$^c+$^d+$^e }, "10", "map() works with 5-ary functions";
}
-# .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 "adverbial block"
- is ~(42,).map:{ $_ }, "42", "method form of map should work on arrays";
-};
+ is(42.map({$_}), 42, "method form of map works on numbers");
+ is('str'.map({$_}), 'str', "method form of map works on strings");
+}
=begin pod
@@ -131,15 +127,11 @@ should be equivalent to
=end pod
-## 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;
+ @expected = map { substr($_,1,1) }, @expected;
- is(("foo","bar").map: { $_.substr(1,1) }, @expected, "map of constant list works");
+ is((("foo","bar").map: { $_.substr(1,1) }), @expected, "map of constant list works");
}
View
@@ -34,12 +34,11 @@ plan 12;
is (@array.reduce: { $^a + $^b * $^c }), $result, "n-ary reduce() works";
}
-# .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 works on numbers");
+ is( 'str'.reduce( {$^a+$^b} ), 'str', "method form of reduce works on strings");
is ((42,).reduce: { $^a + $^b }), 42, "method form of reduce should work on arrays";
}

0 comments on commit 5caad32

Please sign in to comment.