|
1 | 1 | use v6;
|
2 | 2 |
|
3 | 3 | use Test;
|
4 |
| -plan 63; |
| 4 | +plan 70; |
5 | 5 |
|
6 | 6 | # L<S04/The Relationship of Blocks and Declarations/"The new constant declarator">
|
7 | 7 |
|
@@ -358,4 +358,32 @@ throws-like q[constant Mouse = Rat; constant Mouse = Rat], X::Redeclaration,
|
358 | 358 | is @x[1], 4, "can subscript into constant @ (2)";
|
359 | 359 | }
|
360 | 360 |
|
| 361 | +# test use of 'constant' to make synonym to operator |
| 362 | +{ |
| 363 | + constant &infix:<`> = &infix:<+>; |
| 364 | + |
| 365 | + is 1 ` 5, 6, "can add operator synonym via 'constant'"; |
| 366 | + is 1 ` 2 * 3, 7, "new synonym has same precedence as what it's aliasing"; |
| 367 | +} |
| 368 | + |
| 369 | +{ |
| 370 | + constant &postfix:<`> = &prefix:<?>; |
| 371 | + |
| 372 | + is 1`, True, "can create synonym of operator in different grammatical category"; |
| 373 | +} |
| 374 | + |
| 375 | +{ |
| 376 | + multi sub infix:<β>(Int $a, Int $b) { $a * $b } |
| 377 | + |
| 378 | + constant &infix:<β> := &infix:<β>; |
| 379 | + |
| 380 | + is 7 β 6, 42, "Operator multi defined on snowman works using snowman"; |
| 381 | + is 6 β 6, 36, "Operator multi defined on snowman works using comet"; |
| 382 | + |
| 383 | + multi sub infix:<β>(Str $a, Int $b) { $a x $b } |
| 384 | + |
| 385 | + is "A" β 5, "AAAAA", "Operator multi defined on comet works using comet"; |
| 386 | + is "B" β 4, "BBBB", "Operator multi defined on comet works using snowman"; |
| 387 | +} |
| 388 | + |
361 | 389 | # vim: ft=perl6
|
0 commit comments