Skip to content

Commit 06359ee

Browse files
committed
Add tests for using 'constant' to alias operators.
1 parent 6f2a9f0 commit 06359ee

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

β€ŽS04-declarations/constant.t

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use v6;
22

33
use Test;
4-
plan 63;
4+
plan 70;
55

66
# L<S04/The Relationship of Blocks and Declarations/"The new constant declarator">
77

@@ -358,4 +358,32 @@ throws-like q[constant Mouse = Rat; constant Mouse = Rat], X::Redeclaration,
358358
is @x[1], 4, "can subscript into constant @ (2)";
359359
}
360360

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+
361389
# vim: ft=perl6

0 commit comments

Comments
Β (0)