Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 52 lines (42 sloc) 1.031 kB
ad116db [t] move operators/recursive_definition.t to spec/, and add a simpler…
moritz authored
1 use v6;
2 use Test;
3
11ec63a @usev6 Add test for RT #119473
usev6 authored
4 plan 5;
ad116db [t] move operators/recursive_definition.t to spec/, and add a simpler…
moritz authored
5
6 #L<S06/Operator overloading>
7
8 {
001e798 @moritz &eval does not catch exceptions.
moritz authored
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
13 }
14
15 {
001e798 @moritz &eval does not catch exceptions.
moritz authored
16 sub postfix:<!>($arg) {
17 if ($arg == 0) { 1;}
18 else { ($arg-1)! * $arg;}
19 };
20 is 5!, 120, 'Can define recursive postfix operator';
11ec63a @usev6 Add test for RT #119473
usev6 authored
21 # RT #119473
22 is 5.!, 120, 'Can use newly defined postfix operator with leading dot';
ad116db [t] move operators/recursive_definition.t to spec/, and add a simpler…
moritz authored
23 }
24
4e0660e [S13-overloading/operators.t] added test about postcircumfix:<{ }>
masak authored
25 {
26 class A does Associative {
45d205f @lizmat Fudge all cases where [] or {} were being overloaded as methods
lizmat authored
27 method postcircumfix:<{ }>(*@ix) { # METHOD TO SUB CASUALTY
4e0660e [S13-overloading/operators.t] added test about postcircumfix:<{ }>
masak authored
28 return @ix
29 }
30 };
31
45d205f @lizmat Fudge all cases where [] or {} were being overloaded as methods
lizmat authored
32 #?rakudo skip 'cannot easily override {} at the moment'
4e0660e [S13-overloading/operators.t] added test about postcircumfix:<{ }>
masak authored
33 is A.new<foo bar>, <foo bar>, 'defining postcircumfix:<{ }> works';
34 }
ad116db [t] move operators/recursive_definition.t to spec/, and add a simpler…
moritz authored
35
160bc8b @moritz test for overriding invoke with postcircumfix:<( )>
moritz authored
36 # overloaded invoke
37 # RT #76330
38 # (even though the ticket title claims it, the actual problem was not related
39 # to monkey typing/augmenting at all)
40
41 {
42 class B {
43 has $.x;
44 method postcircumfix:<( )>($y) {
45 $.x ~ $y;
46 }
47 }
48 is B.new(x => 'a').('b'), 'ab', 'can overload invoke';
49 }
50
ad116db [t] move operators/recursive_definition.t to spec/, and add a simpler…
moritz authored
51 # vim: ft=perl6
Something went wrong with that request. Please try again.