Skip to content
Newer
Older
100644 49 lines (39 sloc) 851 Bytes
ad116db [t] move operators/recursive_definition.t to spec/, and add a simpler…
moritz authored Sep 27, 2008
1 use v6;
2 use Test;
3
160bc8b @moritz test for overriding invoke with postcircumfix:<( )>
moritz authored Jan 13, 2012
4 plan 4;
ad116db [t] move operators/recursive_definition.t to spec/, and add a simpler…
moritz authored Sep 27, 2008
5
6 #L<S06/Operator overloading>
7
8 {
001e798 @moritz &eval does not catch exceptions.
moritz authored Oct 9, 2011
9 sub postfix:<§> ($x) {
10 $x * 2;
11 };
12 is 3§, 6, 'Can define postfix operator';
ad116db [t] move operators/recursive_definition.t to spec/, and add a simpler…
moritz authored Sep 27, 2008
13 }
14
15 {
001e798 @moritz &eval does not catch exceptions.
moritz authored Oct 9, 2011
16 sub postfix:<!>($arg) {
17 if ($arg == 0) { 1;}
18 else { ($arg-1)! * $arg;}
19 };
20 is 5!, 120, 'Can define recursive postfix operator';
ad116db [t] move operators/recursive_definition.t to spec/, and add a simpler…
moritz authored Sep 27, 2008
21 }
22
4e0660e [S13-overloading/operators.t] added test about postcircumfix:<{ }>
masak authored May 17, 2009
23 {
24 class A does Associative {
25 method postcircumfix:<{ }>(*@ix) {
26 return @ix
27 }
28 };
29
30 is A.new<foo bar>, <foo bar>, 'defining postcircumfix:<{ }> works';
31 }
ad116db [t] move operators/recursive_definition.t to spec/, and add a simpler…
moritz authored Sep 27, 2008
32
160bc8b @moritz test for overriding invoke with postcircumfix:<( )>
moritz authored Jan 13, 2012
33 # overloaded invoke
34 # RT #76330
35 # (even though the ticket title claims it, the actual problem was not related
36 # to monkey typing/augmenting at all)
37
38 {
39 class B {
40 has $.x;
41 method postcircumfix:<( )>($y) {
42 $.x ~ $y;
43 }
44 }
45 is B.new(x => 'a').('b'), 'ab', 'can overload invoke';
46 }
47
ad116db [t] move operators/recursive_definition.t to spec/, and add a simpler…
moritz authored Sep 27, 2008
48 # vim: ft=perl6
Something went wrong with that request. Please try again.