Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add immutability tests for Bag/Mix
  • Loading branch information
lizmat committed Oct 4, 2015
1 parent 778d230 commit 877e74c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
21 changes: 20 additions & 1 deletion S02-types/bag.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 197;
plan 201;

sub showkv($x) {
$x.keys.sort.map({ $^k ~ ':' ~ $x{$k} }).join(' ')
Expand Down Expand Up @@ -492,4 +492,23 @@ sub showkv($x) {
is showkv($b), 'a:5 b:1 foo:2', '...with the right elements';
}

{
my $b = <a>.Bag;
throws-like { $b<a> = 42 },
X::Assignment::RO,
'Make sure we cannot assign on a key';

throws-like { $_ = 666 for $b.values },
X::Assignment::RO,
'Make sure we cannot assign on a .values alias';

throws-like { .value = 999 for $b.pairs },
X::Assignment::RO,
'Make sure we cannot assign on a .pairs alias';

throws-like { for $b.kv -> \k, \v { v = 22 } },
X::Assignment::RO,
'Make sure we cannot assign on a .kv alias';
}

# vim: ft=perl6
21 changes: 20 additions & 1 deletion S02-types/mix.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 178;
plan 182;

sub showkv($x) {
$x.keys.sort.map({ $^k ~ ':' ~ $x{$k} }).join(' ')
Expand Down Expand Up @@ -427,4 +427,23 @@ sub showkv($x) {
'Faulty .WHICH creation';
}

{
my $m = <a>.Mix;
throws-like { $m<a> = 42.1 },
X::Assignment::RO,
'Make sure we cannot assign on a key';

throws-like { $_ = 666.1 for $m.values },
X::Assignment::RO,
'Make sure we cannot assign on a .values alias';

throws-like { .value = 999.1 for $m.pairs },
X::Assignment::RO,
'Make sure we cannot assign on a .pairs alias';

throws-like { for $m.kv -> \k, \v { v = 22.1 } },
X::Assignment::RO,
'Make sure we cannot assign on a .kv alias';
}

# vim: ft=perl6

0 comments on commit 877e74c

Please sign in to comment.