Skip to content

Commit

Permalink
Cover meta assign opts and bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet authored and ugexe committed Dec 15, 2018
1 parent 4da4be8 commit 8f7dd6f
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions S03-metaops/misc.t
@@ -0,0 +1,67 @@
use v6;
use Test;

plan 1;

=begin pod
=head1 DESCRIPTION
Miscellaneous metaop tests that don't fit into other files in this directory.
=end pod

# Covers opts in https://github.com/rakudo/rakudo/commit/b9b0838dd8
subtest 'cover metaop call simplification optimization' => {
plan 7;
subtest '(//=) +=' => {
plan 2;
my $a;
($a //= 42) += 10;
is-deeply $a, 52, '(1)';
($a //= 42) += 10;
is-deeply $a, 62, '(2)';
}
subtest 'R+= (||=)' => {
plan 2;
my $a;
10 R+= ($a ||= 42);
is-deeply $a, 52, '(1)';
10 R+= ($a ||= 42);
is-deeply $a, 62, '(2)';
}
subtest '(((R+= ([R-]=)) //=) +=)' => {
plan 1;
my $a = 12;
((10 R+= ($a [R-]= 42)) //= 100) += 1000;
is-deeply $a, 1040, '(1)';
}
subtest '(((R+= ([R-]=)) //=) +=)' => {
plan 1;
my $a = 12;
((10 R+= ($a [R-]= 42)) //= 100) += 1000;
is-deeply $a, 1040, '(1)';
}
subtest 'array var with ((||=) += )' => {
my @a = 20; (@a ||= 42) += 10; dd @a
}

# https://github.com/rakudo/rakudo/issues/1989
subtest 'metassign to array/hash returned from a method' => {
plan 2;
my class Foo { has @.a is rw; has %.h is rw };
my $o := Foo.new: :h{:42foo};
is-deeply ($o.a += <a b c>), [3], '+= to array';
is-deeply ($o.h ,= :100bar), {:42foo, :100bar}, ',= to hash';
}
subtest 'failure modes' => {
plan 5;
throws-like my $a := 42; ($a //= 42) += 10, X::Assignment::RO, '(1)';
throws-like my $a := 42; ($a ||= 42) R+= 10, X::Assignment::RO, '(2)';
throws-like my $a = 42; ($a ||= 42) R+= 10, X::Assignment::RO, '(3)';
throws-like my $a = 42; 1000 += ((10 R+= ($a [R-]= 42)) //= 100), X::Assignment::RO,
'(4)';
# https://github.com/rakudo/rakudo/issues/1987
throws-like '42.abs += 42', X::Assignment::RO, '(5)';
}
}

0 comments on commit 8f7dd6f

Please sign in to comment.