Skip to content

Commit

Permalink
Add basic parameterized SetHash/BagHash/MixHash tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Jan 15, 2019
1 parent 7df0786 commit 2df8f54
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
12 changes: 11 additions & 1 deletion S02-types/baghash.t
Expand Up @@ -3,7 +3,7 @@ use Test;
use lib $?FILE.IO.parent(2).add: 'packages/Test-Helpers';
use Test::Util;

plan 304;
plan 308;

# L<S02/Mutable types/QuantHash of UInt>

Expand Down Expand Up @@ -415,6 +415,16 @@ sub showkv($x) {
is $b.elems, 0, '.grabpairs *should* change BagHash';
}

{
my $b = BagHash[Str].new( <a b c> );
is-deeply $b.keys.sort.List, <a b c>, 'can we parameterize for strings?';
ok BagHash[Str].keyof =:= Str, 'does .keyof return the correct type';
throws-like { $b{42} = 1 }, X::TypeCheck::Binding,
'does attempt to add item of wrong type croak';
throws-like { BagHash[Int].new( <a b c> ) }, X::TypeCheck::Binding,
'do wrong values make initialization croak';
}

# RT #124490
{
my %h is BagHash = a => 1, b => 0, c => 2;
Expand Down
12 changes: 11 additions & 1 deletion S02-types/mixhash.t
Expand Up @@ -3,7 +3,7 @@ use lib $?FILE.IO.parent(2).add("packages/Test-Helpers");
use Test::Util;
use Test;

plan 270;
plan 274;

# L<S02/Mutable types/QuantHash of UInt>

Expand Down Expand Up @@ -579,6 +579,16 @@ group-of 10 => 'MixHash autovivification of non-existent keys' => {
}
}

{
my $m = MixHash[Str].new( <a b c> );
is-deeply $m.keys.sort.List, <a b c>, 'can we parameterize for strings?';
ok MixHash[Str].keyof =:= Str, 'does .keyof return the correct type';
throws-like { $m{42} = 1 }, X::TypeCheck::Binding,
'does attempt to add item of wrong type croak';
throws-like { MixHash[Int].new( <a b c> ) }, X::TypeCheck::Binding,
'do wrong values make initialization croak';
}

# RT #131561
{
is-deeply (a => -1, a => 1).MixHash, MixHash.new,
Expand Down
12 changes: 11 additions & 1 deletion S02-types/sethash.t
Expand Up @@ -3,7 +3,7 @@ use Test;
use lib $?FILE.IO.parent(2).add: 'packages/Test-Helpers';
use Test::Util;

plan 258;
plan 262;

# L<S02/Mutable types/"QuantHash of Bool">

Expand Down Expand Up @@ -442,6 +442,16 @@ sub showset($s) { $s.keys.sort.join(' ') }
is $e.fmt('%s,%s',':'), "", '.fmt(%s%s,sep) works (empty)';
}

{
my $s = SetHash[Str].new( <a b c> );
is-deeply $s.keys.sort.List, <a b c>, 'can we parameterize for strings?';
ok SetHash[Str].keyof =:= Str, 'does .keyof return the correct type';
throws-like { $s{42} = 1 }, X::TypeCheck::Binding,
'does attempt to add item of wrong type croak';
throws-like { SetHash[Int].new( <a b c> ) }, X::TypeCheck::Binding,
'do wrong values make initialization croak';
}

# RT #125611
{
class RT125611 is SetHash {
Expand Down

0 comments on commit 2df8f54

Please sign in to comment.