Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rakudo fix: rakudo/rakudo@b9b0838dd8 Closes rakudo/rakudo#1987 R#1987 Closes rakudo/rakudo#1989 R#1989 Covers rakudo/rakudo@b9b0838dd8
- Loading branch information
1 parent
4da4be8
commit 8f7dd6f
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)'; | ||
} | ||
} |