Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make S02-types/mix.t pass all tests
  • Loading branch information
lizmat committed Aug 28, 2015
1 parent a7dafef commit 869e1a9
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions S02-types/mix.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 176;
plan 181;

sub showkv($x) {
$x.keys.sort.map({ $^k ~ ':' ~ $x{$k} }).join(' ')
Expand Down Expand Up @@ -109,7 +109,10 @@ sub showkv($x) {

#?niecza skip "Unmatched key in Hash.LISTSTORE"
{
throws-like 'my %h = mix <a b o p a p o o>', X::Hash::Store::OddNumber;
my %s = mix <a b o p a p o o>;
is %s, { :2a, :1b, :2p, :3o }, 'flattens under single arg rule';
my %m = mix <a b o p>,< a p o o>;
is %m, { <a b o p> => 1, <a p o o> => 1 }, 'does not flatten under single arg rule';
}
{
my %h := mix <a b o p a p o o>;
Expand All @@ -126,6 +129,11 @@ sub showkv($x) {
{
my $m = mix [ foo => 10, bar => 17, baz => 42, santa => 0 ];
isa-ok $m, Mix, '&Mix.new given an array of pairs produces a Mix';
is +$m, 4, "... with four elements under the single arg rule";
}
{
my $m = mix $[ foo => 10, bar => 17, baz => 42, santa => 0 ];
isa-ok $m, Mix, '&Mix.new given an itemized array of pairs produces a Mix';
is +$m, 1, "... with one element";
}

Expand All @@ -139,9 +147,13 @@ sub showkv($x) {
}

{
# plain {} does not interpolate in list context
my $m = mix { foo => 10, bar => 17, baz => 42, santa => 0 };
isa-ok $m, Mix, '&Mix.new given a Hash produces a Mix';
is +$m, 4, "... with four elements under the single arg rule";
}
{
my $m = mix ${ foo => 10, bar => 17, baz => 42, santa => 0 };
isa-ok $m, Mix, '&Mix.new given an itemized Hash produces a Mix';
is +$m, 1, "... with one element";
}

Expand Down Expand Up @@ -327,23 +339,25 @@ sub showkv($x) {

{
my $m1 = mix ( mix <a b c> ), <c c c d d d d>;
is +$m1, 8, "Three elements";
is $m1<c>, 3, "One of them is 'c'";
is $m1<d>, 4, "One of them is 'd'";
is +$m1, 2, "Two elements";
my $inner-mix = $m1.keys.first(Mix);
#?niecza 2 todo 'Mix in Mix does not work correctly yet'
isa-ok $inner-mix, Mix, "One of the mix's elements is indeed a mix!";
isa-ok $inner-mix, Mix, "One of the mix's elements is indeed a Mix!";
is showkv($inner-mix), "a:1 b:1 c:1", "With the proper elements";
my $inner-list = $m1.keys.first(List);
isa-ok $inner-list, List, "One of the mix's elements is indeed a List!";
is $inner-list, <c c c d d d d>, "With the proper elements";

my $m = mix <a b c>;
$m1 = mix $m, <c d>;
is +$m1, 3, "Three elements";
is $m1<c>, 1, "One of them is 'c'";
is $m1<d>, 1, "One of them is 'd'";
is +$m1, 2, "Two elements";
$inner-mix = $m1.keys.first(Mix);
#?niecza 2 todo 'Mix in Mix does not work correctly yet'
isa-ok $inner-mix, Mix, "One of the mix's elements is indeed a mix!";
is showkv($inner-mix), "a:1 b:1 c:1", "With the proper elements";
my $inner-list = $m1.keys.first(List);
isa-ok $inner-list, List, "One of the mix's elements is indeed a List!";
is $inner-list, <c d>, "With the proper elements";
}

{
Expand Down

0 comments on commit 869e1a9

Please sign in to comment.