Permalink
Browse files

Add tests for Set et al :exists and :delete.

  • Loading branch information...
1 parent ecd13f4 commit df27e0df3100494f30bdfa05aa2f4fadf6cb5eab @colomon colomon committed Feb 11, 2012
Showing with 34 additions and 4 deletions.
  1. +8 −1 S02-types/bag.t
  2. +9 −1 S02-types/keybag.t
  3. +9 −1 S02-types/keyset.t
  4. +8 −1 S02-types/set.t
View
9 S02-types/bag.t
@@ -1,7 +1,7 @@
use v6;
use Test;
-plan 103;
+plan 106;
sub showkv($x) {
$x.keys.sort.map({ $^k ~ ':' ~ $x{$^k} }).join(' ')
@@ -44,6 +44,13 @@ sub showkv($x) {
}
{
+ my $s = bag <a a b foo>;
+ is $s<a>:exists, True, ':exists with existing element';
+ is $s<santa>:exists, False, ':exists with nonexistent element';
+ dies_ok { $s<a>:delete }, ':delete does not work on bag';
+}
+
+{
my $b = bag 'a', False, 2, 'a', False, False;
my @ks = $b.keys;
#?niecza 2 todo
View
10 S02-types/keybag.t
@@ -1,7 +1,7 @@
use v6;
use Test;
-plan 140;
+plan 144;
# L<S02/Mutable types/KeyHash of UInt>
@@ -66,6 +66,14 @@ sub showkv($x) {
}
{
+ my $s = KeyBag.new(<a a b foo>);
+ is $s<a>:exists, True, ':exists with existing element';
+ is $s<santa>:exists, False, ':exists with nonexistent element';
+ is $s<a>:delete, 2, ':delete works on KeyBag';
+ is showkv($s), 'b:1 foo:1', '...and actually deletes';
+}
+
+{
my $b = KeyBag.new('a', False, 2, 'a', False, False);
my @ks = $b.keys;
#?niecza 2 todo
View
10 S02-types/keyset.t
@@ -1,7 +1,7 @@
use v6;
use Test;
-plan 108;
+plan 112;
# L<S02/Mutable types/"KeyHash of Bool">
@@ -68,6 +68,14 @@ sub showset($s) { $s.keys.sort.join(' ') }
}
{
+ my $s = KeySet.new(<a b foo>);
+ is $s<a>:exists, True, ':exists with existing element';
+ is $s<santa>:exists, False, ':exists with nonexistent element';
+ is $s<a>:delete, True, ':delete returns current value on set';
+ is showset($s), 'b foo', '...and actually deletes';
+}
+
+{
my %h := KeySet.new(<a c>);
is +%h.elems, 2, 'Inititalization worked';
View
9 S02-types/set.t
@@ -1,7 +1,7 @@
use v6;
use Test;
-plan 90;
+plan 93;
sub showset($s) { $s.keys.sort.join(' ') }
@@ -40,6 +40,13 @@ sub showset($s) { $s.keys.sort.join(' ') }
}
{
+ my $s = set <a b foo>;
+ is $s<a>:exists, True, ':exists with existing element';
+ is $s<santa>:exists, False, ':exists with nonexistent element';
+ dies_ok { $s<a>:delete }, ':delete does not work on set';
+}
+
+{
my $s = set 2, 'a', False;
my @ks = $s.keys;
#?niecza 3 todo

0 comments on commit df27e0d

Please sign in to comment.