| 1 | use v6; |
|---|
| 2 | |
|---|
| 3 | use Test; |
|---|
| 4 | |
|---|
| 5 | plan 18; |
|---|
| 6 | |
|---|
| 7 | my @a = (1, 2, 3); |
|---|
| 8 | ok(@a .= map:{ $_ + 1 }, '.= parses with adverbial block'); |
|---|
| 9 | is(@a[0], 2, 'inplace map [0]'); |
|---|
| 10 | is(@a[1], 3, 'inplace map [1]'); |
|---|
| 11 | is(@a[2], 4, 'inplace map [2]'); |
|---|
| 12 | |
|---|
| 13 | my @b = <foo 123 bar 456 baz>; |
|---|
| 14 | ok(eval('@b.=grep:{/<[a..z]>/}'), '.= parses without surrounding whitespace'); |
|---|
| 15 | is @b[0], 'foo', 'inplace grep [0]'; |
|---|
| 16 | is @b[1], 'bar', 'inplace grep [1]'; |
|---|
| 17 | is @b[2], 'baz', 'inplace grep [2]'; |
|---|
| 18 | |
|---|
| 19 | my $a=3.14; |
|---|
| 20 | $a .= int; |
|---|
| 21 | is($a, 3, "inplace int"); |
|---|
| 22 | |
|---|
| 23 | my $b = "a_string"; $b .= WHAT; |
|---|
| 24 | my $c = 42; $c .= WHAT; |
|---|
| 25 | my $d = 42.23; $d .= WHAT; |
|---|
| 26 | my @e = <a b c d>; @e .= WHAT; |
|---|
| 27 | is($b, "Str", "inplace WHAT of a Str"); |
|---|
| 28 | is($c, "Int", "inplace WHAT of a Num"); |
|---|
| 29 | is($d, "Rat", "inplace WHAT of a Rat"); |
|---|
| 30 | is(@e[0], "Array", "inplace WHAT of an Array"); |
|---|
| 31 | |
|---|
| 32 | my $f = "lowercase"; $f .= uc; |
|---|
| 33 | my $g = "UPPERCASE"; $g .= lc; |
|---|
| 34 | my $h = "lowercase"; $h .= ucfirst; |
|---|
| 35 | my $i = "UPPERCASE"; $i .= lcfirst; |
|---|
| 36 | is($f, "LOWERCASE", "inplace uc"); |
|---|
| 37 | is($g, "uppercase", "inplace lc"); |
|---|
| 38 | is($h, "Lowercase", "inplace ucfist"); |
|---|
| 39 | is($i, "uPPERCASE", "inplace lcfirst"); |
|---|
| 40 | |
|---|
| 41 | # L<S12/"Mutating methods"> |
|---|
| 42 | my @b = <z a b d e>; |
|---|
| 43 | @b .= sort; |
|---|
| 44 | is ~@b, "a b d e z", "inplace sort"; |
|---|