Skip to content

Commit

Permalink
Add basic parameterized Set/Bag/Mix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Jan 15, 2019
1 parent 7c08f8f commit 73e63d5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
10 changes: 9 additions & 1 deletion S02-types/bag.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 234;
plan 237;

sub showkv($x) {
$x.keys.sort.map({ $^k ~ ':' ~ $x{$k} }).join(' ')
Expand Down Expand Up @@ -453,6 +453,14 @@ sub showkv($x) {
is $e.fmt('%s,%s',':'), "", '.fmt(%s%s,sep) works (empty)';
}

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

# RT #124454
isnt
'91D95D6EDD0F0C61D02A2989781C5AEB10832C94'.Bag.WHICH,
Expand Down
10 changes: 9 additions & 1 deletion S02-types/mix.t
Expand Up @@ -3,7 +3,7 @@ use Test;
use lib $?FILE.IO.parent(2).add("packages/Test-Helpers");
use Test::Util;

plan 224;
plan 227;

sub showkv($x) {
$x.keys.sort.map({ $^k ~ ':' ~ $x{$k} }).join(' ')
Expand Down Expand Up @@ -407,6 +407,14 @@ sub showkv($x) {
is $e.fmt('%s,%s',':'), "", '.fmt(%s%s,sep) works (empty)';
}

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

# RT #124454
isnt
'91D95D6EDD0F0C61D02A2989781C5AEB10832C94'.Mix.WHICH,
Expand Down
10 changes: 9 additions & 1 deletion S02-types/set.t
Expand Up @@ -3,7 +3,7 @@ use Test;
use lib $?FILE.IO.parent(2).add: 'packages/Test-Helpers';
use Test::Util;

plan 226;
plan 229;

sub showset($s) { $s.keys.sort.join(' ') }

Expand Down Expand Up @@ -489,6 +489,14 @@ subtest '.hash does not cause keys to be stringified' => {
'coercion of object Hash to Set 2';
}

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

{
throws-like { ^Inf .Set }, X::Cannot::Lazy, :what<Set>;
throws-like { Set.new-from-pairs(^Inf) }, X::Cannot::Lazy, :what<Set>;
Expand Down

0 comments on commit 73e63d5

Please sign in to comment.