Skip to content

Commit

Permalink
Add tests for inter-QuantHash coercions
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Jun 24, 2019
1 parent 270e09c commit a178a56
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 6 deletions.
11 changes: 10 additions & 1 deletion S02-types/bag.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 237;
plan 242;

sub showkv($x) {
$x.keys.sort.map({ $^k ~ ':' ~ $x{$k} }).join(' ')
Expand Down Expand Up @@ -582,4 +582,13 @@ subtest '.hash does not cause keys to be stringified' => {
# R#2289
is-deeply (1,2,3).Bag.ACCEPTS( ().Bag ), False, 'can we smartmatch empty';

{
my $bag = <a b c>.Bag;
is-deeply $bag.Set, <a b c>.Set, 'coerce Bag -> Set';
is-deeply $bag.SetHash, <a b c>.SetHash, 'coerce Bag -> SetHash';
is-deeply $bag.BagHash, <a b c>.BagHash, 'coerce Bag -> BagHash';
is-deeply $bag.Mix, <a b c>.Mix, 'coerce Bag -> Mix';
is-deeply $bag.MixHash, <a b c>.MixHash, 'coerce Bag -> MixHash';
}

# vim: ft=perl6
11 changes: 10 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 308;
plan 313;

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

Expand Down Expand Up @@ -730,4 +730,13 @@ is-deeply ('foo' => 10000000000000000000).BagHash.grab(1), ('foo',),
# R#2289
is-deeply (1,2,3).BagHash.ACCEPTS(().BagHash), False, 'can we smartmatch empty';

{
my $bag = <a b c>.BagHash;
is-deeply $bag.Set, <a b c>.Set, 'coerce BagHash -> Set';
is-deeply $bag.SetHash, <a b c>.SetHash, 'coerce BagHash -> SetHash';
is-deeply $bag.Bag, <a b c>.Bag, 'coerce BagHash -> Bag';
is-deeply $bag.Mix, <a b c>.Mix, 'coerce BagHash -> Mix';
is-deeply $bag.MixHash, <a b c>.MixHash, 'coerce BagHash -> MixHash';
}

# vim: ft=perl6
11 changes: 10 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 227;
plan 232;

sub showkv($x) {
$x.keys.sort.map({ $^k ~ ':' ~ $x{$k} }).join(' ')
Expand Down Expand Up @@ -544,4 +544,13 @@ subtest '.hash does not cause keys to be stringified' => {
# R#2289
is-deeply (1,2,3).Mix.ACCEPTS(().Mix), False, 'can we smartmatch empty';

{
my $mix = <a b c>.Mix;
is-deeply $mix.Set, <a b c>.Set, 'coerce Mix -> Set';
is-deeply $mix.SetHash, <a b c>.SetHash, 'coerce Mix -> SetHash';
is-deeply $mix.Bag, <a b c>.Bag, 'coerce Mix -> Bag';
is-deeply $mix.BagHash, <a b c>.BagHash, 'coerce Mix -> BagHash';
is-deeply $mix.MixHash, <a b c>.MixHash, 'coerce Mix -> MixHash';
}

# vim: ft=perl6
11 changes: 10 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 274;
plan 279;

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

Expand Down Expand Up @@ -635,4 +635,13 @@ subtest "elements with negative weights are allowed in MixHashes" => {
# R#2289
is-deeply (1,2,3).MixHash.ACCEPTS(().MixHash), False, 'can we smartmatch empty';

{
my $mix = <a b c>.MixHash;
is-deeply $mix.Set, <a b c>.Set, 'coerce MixHash -> Set';
is-deeply $mix.SetHash, <a b c>.SetHash, 'coerce MixHash -> SetHash';
is-deeply $mix.Bag, <a b c>.Bag, 'coerce MixHash -> Bag';
is-deeply $mix.BagHash, <a b c>.BagHash, 'coerce MixHash -> BagHash';
is-deeply $mix.Mix, <a b c>.Mix, 'coerce MixHash -> Mix';
}

# vim: ft=perl6
11 changes: 10 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 229;
plan 234;

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

Expand Down Expand Up @@ -580,4 +580,13 @@ is +set(.3e0, .1e0+.2e0, 1e0, 1e0+4e-15), 4,
# R#2289
is-deeply (1,2,3).Set.ACCEPTS(().Set), False, 'can we smartmatch empty';

{
my $set = <a b c>.Set;
is-deeply $set.SetHash, <a b c>.SetHash, 'coerce Set -> SetHash';
is-deeply $set.Bag, <a b c>.Bag, 'coerce Set -> Bag';
is-deeply $set.BagHash, <a b c>.BagHash, 'coerce Set -> BagHash';
is-deeply $set.Mix, <a b c>.Mix, 'coerce Set -> Mix';
is-deeply $set.MixHash, <a b c>.MixHash, 'coerce Set -> MixHash';
}

# vim: ft=perl6
11 changes: 10 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 262;
plan 267;

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

Expand Down Expand Up @@ -661,4 +661,13 @@ subtest "elements with negative weights are allowed in SetHashes" => {
# R#2289
is-deeply (1,2,3).SetHash.ACCEPTS(().SetHash), False, 'can we smartmatch empty';

{
my $set = <a b c>.SetHash;
is-deeply $set.Set, <a b c>.Set, 'coerce SetHash -> Set';
is-deeply $set.Bag, <a b c>.Bag, 'coerce SetHash -> Bag';
is-deeply $set.BagHash, <a b c>.BagHash, 'coerce SetHash -> BagHash';
is-deeply $set.Mix, <a b c>.Mix, 'coerce SetHash -> Mix';
is-deeply $set.MixHash, <a b c>.MixHash, 'coerce SetHash -> MixHash';
}

# vim: ft=perl6

0 comments on commit a178a56

Please sign in to comment.