Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Add ResizablePMCArray .delete and .exists .
  • Loading branch information
pmichaud committed Jun 24, 2010
1 parent a3d5c5b commit ebaf06c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/setting/ResizablePMCArray.pm
Expand Up @@ -11,6 +11,22 @@ more methods typical of Perl 6 lists and arrays.

module ResizablePMCArray {

=begin item delete
Remove item at C<$pos>
=end item

method delete($pos) {
pir::delete__vQi(self, $pos);
}

=begin item exists
Return true if item exists at C<$pos>
=end item

method exists($pos) {
pir::exists__IQi(self, $pos);
}

=begin item join
Return all elements joined by $sep.
=end item
Expand Down
10 changes: 9 additions & 1 deletion t/setting/01-resizablepmcarray.t
Expand Up @@ -5,7 +5,7 @@ pir::load_bytecode('nqp-setting.pbc');
my @array := <0 1 2>;
my @reversed := @array.reverse();

plan(5);
plan(10);

ok( @reversed[0] == 2, 'First element correct');
ok( @reversed[1] == 1, 'Second element correct');
Expand All @@ -16,4 +16,12 @@ ok( $join eq '0|1|2', 'Join elements');

ok( join(':', 'foo', 'bar', 'baz') eq 'foo:bar:baz', 'Join as standalone function');

my @test := <apple banana cherry>;
ok( @test.exists(2), 'Item exists at @test[2]' );
ok( !@test.exists(3), 'Item does not exist at @test[3]');
@test.delete(1);
ok( @test[1] eq 'cherry', '@test[1] was deleted');
ok( +@test == 2, '@test[1] has two items');
ok( !@test.exists(2), '@test[2] no longer exists');

# vim: ft=perl6

0 comments on commit ebaf06c

Please sign in to comment.