Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[S32-array] unfossile tests. Most of that is calling positional argum…
…ents by name
  • Loading branch information
moritz committed May 23, 2011
1 parent 8657a3a commit 87efb8a
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 88 deletions.
12 changes: 0 additions & 12 deletions S32-array/delete.t
Expand Up @@ -106,18 +106,6 @@ Basic C<delete> tests, see S32.
lives_ok { map { 1 }, @array }, 'map @array lives after delete';
}

# As a function (THERE IS NO FUNCTION)
# {
# my @array = <1 2 3 4>;
# is delete(@array, 1), 2, "simple functional(ish) delete returns value deleted";
# is ~@array, "1 Any() 3 4", "simple functional(ish) delete changes array";
##?rakudo skip 'cannot parse named args'
# is delete(:array(@array), 2,), 3, "simple functional(ish) delete with named argument returns value deleted";
##?rakudo skip 'cannot parse named args'
# is ~@array, "1 3 4", "simple functional(ish) delete with named argument changes array";
#
# }

# TODO More exclusive bounds checks

# TODO W/ multiple ranges
Expand Down
23 changes: 1 addition & 22 deletions S32-array/elems.t
Expand Up @@ -3,7 +3,7 @@ use v6;
use Test;

# L<S32::Containers/"Array"/=item "elems">
plan 13;
plan 11;

{
my @a;
Expand All @@ -26,22 +26,6 @@ plan 13;
dies_ok { $a.elems }, ".elems does not work on arbitrary scalars (1)";
}

#?rakudo skip 'unspecced'
{
# (ryporter 2007-09-22): This test fails because a VInt is
# being converted into an array in the final defintion of doArray
# in AST/Internals.hs ("doArray val f"). When I tried replacing
# "val" with "(VList x)", to accept fewer inputs, this test passed,
# but many others failed.
#
# Also relevant is the "(rw!Array)" declaration for List::elems
# in Prim.hs. Changing it to "(Array)", combined with the above
# change, caused both this and the preceding test to succeed.
#
my $a = 42;
dies_ok { $a.elems }, ".elems does not work on arbitrary scalars (2)";
}

{
my $a = [];
is $a.elems, 0, ".elems works on empty arrayrefs";
Expand All @@ -62,11 +46,6 @@ plan 13;
dies_ok { elems(1,2,3,4) }, "elems(1,2,3,4) should not work";
}

#?rakudo skip 'cannot parse named arguments'
{
is elems(:array((1,2,3,4))), 4, "elems (1,2,3,4) should work with named argument";
}

{
is (elems (1,2,3,4)), 4, "elems (1,2,3,4) should work";
}
Expand Down
6 changes: 1 addition & 5 deletions S32-array/end.t
Expand Up @@ -3,7 +3,7 @@ use v6;
use Test;

# L<S32::Containers/"Array"/"end">
plan 13;
plan 12;

{
my @a;
Expand Down Expand Up @@ -52,10 +52,6 @@ plan 13;
dies_ok { end(1,2,3,4) }, "end(1,2,3,4) should not work";
}

{
is end(:array(1,2,3,4)), 3, "end (1,2,3,4) should work with named argument";
}

{
is (end (1,2,3,4)), 3, "end (1,2,3,4) should work";
}
Expand Down
4 changes: 1 addition & 3 deletions S32-array/keys_values.t
Expand Up @@ -2,7 +2,7 @@ use v6;

use Test;

plan 8;
plan 6;

=begin description
Expand All @@ -15,13 +15,11 @@ my @array = <a b c d>;
# L<S32::Containers/"Array"/=item keys>
is(~@array.keys, '0 1 2 3', '@arrays.keys works');
is(~keys(@array), '0 1 2 3', 'keys(@array) works');
is(~keys(:array(@array)), '0 1 2 3', 'keys(:array(@array)) works');
is(+@array.keys, +@array, 'we have the same number of keys as elements in the array');

# L<S32::Containers/"Array"/=item values>
is(~@array.values, 'a b c d', '@array.values works');
is(~values(@array), 'a b c d', 'values(@array) works');
is(~values(:array(@array)), 'a b c d', 'values(:array(@array)) works');
is(+@array.values, +@array, 'we have the same number of values as elements in the array');

# vim: ft=perl6
9 changes: 1 addition & 8 deletions S32-array/kv.t
Expand Up @@ -2,7 +2,7 @@ use v6;

use Test;

plan 20;
plan 18;

=begin description
Expand Down Expand Up @@ -43,13 +43,6 @@ Basic C<kv> tests, see S32.
is(~@kv, "0 a 1 b 2 c 3 d", 'kv(@array) has no inner list');
}

{ # check the non-invocant form with named arguments
my @array = <a b c d>;
my @kv = kv(:array(@array));
is(+@kv, 8, 'kv(:array(@array)) returns the correct number of elems');
is(~@kv, "0 a 1 b 2 c 3 d", 'kv(:array(@array)) has no inner list');
}

is( 42.kv, [0, 42], "(42).kv works");

# bug in Rakudo found by masak++
Expand Down
18 changes: 3 additions & 15 deletions S32-array/pairs.t
@@ -1,9 +1,8 @@
# vim: filetype=perl6
use v6;

use Test;

plan 18;
plan 14;

=begin description
Expand All @@ -26,19 +25,6 @@ Basic C<pairs> tests, see S32.
}
}

{
my @array = <a>;
my @pairs;
ok((@pairs = pairs(:array(@array))), "basic pairs on arrays with a function with named args");
is +@pairs, 1, "pairs on arrays returned the correct number of elems";
if +@pairs != 1 {
skip "skipped tests which depend on a test which failed", 2;
} else {
is @pairs[0].key, 0, "key of pair returned by array.pairs was correct (1)";
is @pairs[0].value, "a", "value of pair returned by array.pairs was correct (1)";
}
}

{
my @array = <a b c>;
my @pairs;
Expand Down Expand Up @@ -67,3 +53,5 @@ Basic C<pairs> tests, see S32.
#?rakudo todo 'Apparently not rw yet?'
is @array[1], 123, 'aliases returned by @array.pairs should be rw (2)';
}

# vim: filetype=perl6
2 changes: 1 addition & 1 deletion S32-array/pop.t
Expand Up @@ -33,7 +33,7 @@ plan 33;
is(+@pop, 1, 'we have 1 element in the array');

{
$a = pop(:array(@pop));
$a = pop(@pop);
is($a, -1, '@pop.pop works');

is(+@pop, 0, 'we have no more element in the array');
Expand Down
9 changes: 1 addition & 8 deletions S32-array/push.t
Expand Up @@ -9,7 +9,7 @@ Push tests
=end description

plan 51;
plan 49;

# basic push tests
{
Expand All @@ -32,13 +32,6 @@ plan 51;
push(@push, 4);
is(+@push, 4, 'we have 4 elements in the array');
is(@push[3], 4, 'we found the right element');

#?rakudo skip 'named args'
{
push(:array(@push), 5);
is(+@push, 5, 'we have 5 elements in the array (with named arg)');
is(@push[4], 5, 'we found the right element (with named arg)');
}
}

{
Expand Down
5 changes: 2 additions & 3 deletions S32-array/shift.t
Expand Up @@ -9,7 +9,7 @@ Shift tests
=end description

plan 32;
plan 31;

{

Expand All @@ -33,8 +33,7 @@ plan 32;

{
is(+@shift, 1, 'we have 1 element in our array');
$a = shift(:array(@shift));
is($a, 5, 'shift(:array(@shift))');
$a = shift(@shift);

is(+@shift, 0, 'we have no elements in our array');
ok(!defined(shift(@shift)), 'after the array is exhausted it gives undefined');
Expand Down
12 changes: 1 addition & 11 deletions S32-array/unshift.t
Expand Up @@ -9,7 +9,7 @@ Unshift tests
=end description

plan 61;
plan 55;

# basic unshift tests

Expand Down Expand Up @@ -39,16 +39,6 @@ plan 61;
is(@unshift[1], 3, 'we found the right element');
is(@unshift[2], 2, 'we found the right element');
is(@unshift[3], 1, 'we found the right element');

{
unshift(:array(@unshift), 5);
is(+@unshift, 5, 'we have 4 element in the array');
is(@unshift[0], 5, 'we found the right element');
is(@unshift[1], 4, 'we found the right element');
is(@unshift[2], 3, 'we found the right element');
is(@unshift[3], 2, 'we found the right element');
is(@unshift[4], 1, 'we found the right element');
}
}

# try other variations on calling unshift()
Expand Down

0 comments on commit 87efb8a

Please sign in to comment.