Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 143 lines (113 sloc) 4.971 kb
58135b3 [t/spec] changed 'use v6-alpha;' to 'use v6;'
moritz authored
1 use v6;
089213c [spec] migrate some S12 methods tests
particle authored
2
3 use Test;
4
8aaac76 Matthew Wilson fix a bunch of smartlinks in S12, broken by me and TimToady++
diakopter authored
5 # L<S12/Method calls/"Indirect object notation now requires a colon after the invocant, even if there are no arguments">
089213c [spec] migrate some S12 methods tests
particle authored
6
f211650 Larry Wall also test parenthesized invocant colon
TimToady authored
7 plan 37;
089213c [spec] migrate some S12 methods tests
particle authored
8
9
10 ##### Without arguments
88c52fa Larry Wall unfudge colon invocant tests
TimToady authored
11 class T1 {
12 method a {
089213c [spec] migrate some S12 methods tests
particle authored
13 'test';
14 }
15 }
16
17 {
6c91a96 [gsoc_spectest] indirect method call tests. (added 7 tests)
Auzon authored
18 my T1 $o .= new;
88c52fa Larry Wall unfudge colon invocant tests
TimToady authored
19 ok( $o, "Still alive after new" );
089213c [spec] migrate some S12 methods tests
particle authored
20
88c52fa Larry Wall unfudge colon invocant tests
TimToady authored
21 is( $o.a(), 'test', "The direct object notation call without arguments" );
f211650 Larry Wall also test parenthesized invocant colon
TimToady authored
22 #?niecza 2 skip 'Invocant handling is NYI'
23 is( (a $o:), 'test', "The indirect object notation call without arguments without ()" );
24 is( a($o:), 'test', "The indirect object notation call without arguments with ()" );
089213c [spec] migrate some S12 methods tests
particle authored
25 }
26
27 ##### With arguments
88c52fa Larry Wall unfudge colon invocant tests
TimToady authored
28 class T2 {
29 method a( $x ) {
089213c [spec] migrate some S12 methods tests
particle authored
30 $x;
31 }
88c52fa Larry Wall unfudge colon invocant tests
TimToady authored
32 method b( $x,$y ) {
33 $x + $y;
34 }
089213c [spec] migrate some S12 methods tests
particle authored
35 }
36
37 {
6c91a96 [gsoc_spectest] indirect method call tests. (added 7 tests)
Auzon authored
38 my T2 $o .= new;
88c52fa Larry Wall unfudge colon invocant tests
TimToady authored
39 ok( $o, "Still alive after new" );
8f4e54f [t/*] fix all the rands and $*PID."... instances
lwall authored
40 my $seed = 1000.rand;
88c52fa Larry Wall unfudge colon invocant tests
TimToady authored
41 is( $o.a( $seed ), $seed, "The direct object notation call with argument" );
f211650 Larry Wall also test parenthesized invocant colon
TimToady authored
42 #?niecza 2 skip 'Invocant handling is NYI'
43 is( (a $o: $seed), $seed, "The indirect object notation call with argument without ()" );
44 is( a($o: $seed), $seed, "The indirect object notation call with argument with ()" );
88c52fa Larry Wall unfudge colon invocant tests
TimToady authored
45
6c91a96 [gsoc_spectest] indirect method call tests. (added 7 tests)
Auzon authored
46 my $name = 'a';
47 eval_dies_ok('$name $o: $seed', 'Indirect object notation and indirect method calls cannot be combined');
88c52fa Larry Wall unfudge colon invocant tests
TimToady authored
48
f211650 Larry Wall also test parenthesized invocant colon
TimToady authored
49 #?niecza 2 skip 'Invocant handling is NYI'
50 is (b $o: 21, 21), 42, "The indirect object notation call with multiple arguments without ()";
51 is b($o: 21, 21), 42, "The indirect object notation call with multiple arguments with ()";
089213c [spec] migrate some S12 methods tests
particle authored
52 }
a60a70c [t/spec] more tests in indirect_notation.t, for example for RT #61106
moritz authored
53
54
8aaac76 Matthew Wilson fix a bunch of smartlinks in S12, broken by me and TimToady++
diakopter authored
55 # L<S12/Fancy method calls/"There are several forms of indirection for the method name">
a60a70c [t/spec] more tests in indirect_notation.t, for example for RT #61106
moritz authored
56
57 {
58 class A {
59 method abc { 'abc' };
60 method bcd { 'bcd' };
61 }
62 my $o = A.new();
63
f341480 [t/spec] more warning suppressions; remaining STD warnings are mostly bu...
lwall authored
64 is $o."abc"(), 'abc', 'calling method with $object."methodname"'; #OK use of quotes
a60a70c [t/spec] more tests in indirect_notation.t, for example for RT #61106
moritz authored
65 my $bc = 'bc';
9e020b5 [t/spec/S12] require () on .'method' and friends
lwall authored
66 is $o."a$bc"(), 'abc', 'calling method with $object."method$name"';
67 is $o."{$bc}d"(), 'bcd', 'calling method with $object."method$name"';
a60a70c [t/spec] more tests in indirect_notation.t, for example for RT #61106
moritz authored
68
69
70 my $meth = method { self.abc ~ self.bcd };
71 is $o.$meth, 'abcbcd', 'calling method with $object.$methodref';
72 }
73
8aaac76 Matthew Wilson fix a bunch of smartlinks in S12, broken by me and TimToady++
diakopter authored
74 # L<S12/Fancy method calls/"$obj.@candidates(1,2,3)">
d405e21 [t/spec] Re-fudge indirect_notation.t for Rakudo and toss some tests tha...
jnthn authored
75 #?rakudo skip '.@foo not yet working'
535c5e1 Solomon Foster Fudge for niecza.
colomon authored
76 #?niecza skip 'Unable to resolve method postcircumfix:<( )> in class Array'
0b0a1eb [t/spec]
moritz authored
77 {
78 class T3 {
79 has $.x;
80 has $.y;
f5da901 [t/spec] Correct tests for $foo.@candidates, which made wrong assumption...
jnthn authored
81 has $.called is rw = 0;
0b0a1eb [t/spec]
moritz authored
82
f5da901 [t/spec] Correct tests for $foo.@candidates, which made wrong assumption...
jnthn authored
83 our method m1 () { $!called++; "$.x|$.y" };
84 our method m2 () { $!called++; "$.x,$.y"; nextsame() };
85 our method m3 () { $!called++; "$.x~$.y" };
86 our method m4 () { $!called++; callsame(); };
0b0a1eb [t/spec]
moritz authored
87 }
f5da901 [t/spec] Correct tests for $foo.@candidates, which made wrong assumption...
jnthn authored
88 my @c = (&T3::m1, &T3::m2, &T3::m3);
0b0a1eb [t/spec]
moritz authored
89 my $o = T3.new(:x<p>, :y<q>);
f5da901 [t/spec] Correct tests for $foo.@candidates, which made wrong assumption...
jnthn authored
90
91 is $o.@c(), 'p|q', 'called the first candidate in the list, which did not defer';
92 is $o.called, 1, 'called only one method dispatch';
0b0a1eb [t/spec]
moritz authored
93
f5da901 [t/spec] Correct tests for $foo.@candidates, which made wrong assumption...
jnthn authored
94 @c.shift();
95 $o.called = 0;
13cc9c4 [t/spec] 71 typos in 32 files.
Util authored
96 is $o.@c, 'p~q', 'got result from method we deferred to';
f5da901 [t/spec] Correct tests for $foo.@candidates, which made wrong assumption...
jnthn authored
97 is $o.called, 2, 'called total two methods during dispatch';
98
99 @c.unshift(&T3::m4);
100 $o.called = 0;
13cc9c4 [t/spec] 71 typos in 32 files.
Util authored
101 is $o.@c, 'p~q', 'got result from method we deferred to, via call';
f5da901 [t/spec] Correct tests for $foo.@candidates, which made wrong assumption...
jnthn authored
102 is $o.called, 3, 'called total three methods during dispatch';
0b0a1eb [t/spec]
moritz authored
103 }
104
f341480 [t/spec] more warning suppressions; remaining STD warnings are mostly bu...
lwall authored
105 dies_ok { 23."nonexistingmethod"() }, "Can't call nonexisting method"; #OK use of quotes
01d2675 remove bogus test
moritz authored
106
d405e21 [t/spec] Re-fudge indirect_notation.t for Rakudo and toss some tests tha...
jnthn authored
107 #?rakudo skip '.*, .+ and .? with @foo'
535c5e1 Solomon Foster Fudge for niecza.
colomon authored
108 #?niecza skip 'Two definitions found for symbol ::GLOBAL::T4::&m, etc'
ff72236 [t/spec] test $obj.*@candidates
moritz authored
109 {
110 class T4 {
111 has $.called = 0;
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
112 our multi method m(Int $x) { $!called++; 'm-Int' } #OK not used
113 our multi method m(Num $x) { $!called++; 'm-Num' } #OK not used
ff72236 [t/spec] test $obj.*@candidates
moritz authored
114
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
115 our multi method n(Int $x) { $!called++; 'n-Int' } #OK not used
116 our multi method n(Num $x) { $!called++; 'n-Num' } #OK not used
ff72236 [t/spec] test $obj.*@candidates
moritz authored
117 }
118
119 my $o = T4.new();
b55ec7c [t/spec] Correct and unfudge tests for dispatches of the form $obj.*@can...
jnthn authored
120 my @cand-num = &T4::m, &T4::n;
ff72236 [t/spec] test $obj.*@candidates
moritz authored
121 is ~$o.*@cand-num(3.4).sort, 'm-Num n-Num', '$o.*@cand(arg) (1)';
122 is ~$o.*@cand-num(3).sort, 'm-Int m-Num n-Int n-Num', '$o.*@cand(arg) (2)';
123 is $o.called, 6, 'right number of method calls';
f9931a0 [t/spec] Tests for $obj.+@foo and $obj.?@foo.
jnthn authored
124 lives_ok { $o.*@cand-num() }, "it's ok with .* if no candidate matched (arity)";
125 lives_ok { $o.*@cand-num([]) }, "it's ok with .* if no candidate matched (type)";
126
127 $o = T4.new();
128 is ~$o.+@cand-num(3.4).sort, 'm-Num n-Num', '$o.+@cand(arg) (1)';
129 is ~$o.+@cand-num(3).sort, 'm-Int m-Num n-Int n-Num', '$o.+@cand(arg) (2)';
130 is $o.called, 6, 'right number of method calls';
131 dies_ok { $o.+@cand-num() }, "it's not ok with .+ if no candidate matched (arity)";
132 dies_ok { $o.+@cand-num([]) }, "it's not ok with .+ if no candidate matched (type)";
133
134 $o = T4.new();
135 is ~$o.?@cand-num(3.4).sort, 'm-Num', '$o.?@cand(arg) (1)';
136 is ~$o.?@cand-num(3).sort, 'm-Int', '$o.?@cand(arg) (2)';
137 is $o.called, 2, 'right number of method calls';
138 lives_ok { $o.?@cand-num() }, "it's ok with .? if no candidate matched (arity)";
139 lives_ok { $o.?@cand-num([]) }, "it's ok with .? if no candidate matched (type)";
ff72236 [t/spec] test $obj.*@candidates
moritz authored
140 }
141
a60a70c [t/spec] more tests in indirect_notation.t, for example for RT #61106
moritz authored
142 # vim: ft=perl6
Something went wrong with that request. Please try again.