Skip to content
Newer
Older
100644 167 lines (137 sloc) 6.2 KB
7cc81cc [t/spec] Add a bunch of new tests for .^methods, and move those in me…
jnthn authored
1 use v6;
2
3 use Test;
4
51e1489 @usev6 Fix fudging (and number of tests)
usev6 authored
5 plan 57;
7cc81cc [t/spec] Add a bunch of new tests for .^methods, and move those in me…
jnthn authored
6
7 =begin pod
8
9 Tests for .^methods from L<S12/Introspection>.
10
11 =end pod
12
13 # L<S12/Introspection/"get the method list of MyClass">
14
15 class A {
8dc7d4b [t/spec] mark various tests that intentionally declare things that ar…
lwall authored
16 method foo($param --> Any) { } #OK not used
17 multi method bar($thingy) { } #OK not used
18 multi method bar($thingy, $other_thingy) { } #OK not used
7cc81cc [t/spec] Add a bunch of new tests for .^methods, and move those in me…
jnthn authored
19 }
e154be7 @coke nom fudging
coke authored
20
7cc81cc [t/spec] Add a bunch of new tests for .^methods, and move those in me…
jnthn authored
21 class B is A {
8dc7d4b [t/spec] mark various tests that intentionally declare things that ar…
lwall authored
22 method foo($param) of Num { } #OK not used
7cc81cc [t/spec] Add a bunch of new tests for .^methods, and move those in me…
jnthn authored
23 }
24 class C is A {
25 }
26 class D is B is C {
8dc7d4b [t/spec] mark various tests that intentionally declare things that ar…
lwall authored
27 multi method bar($a, $b, $c) { } #OK not used
28 method foo($param) returns Int { } #OK not used
7cc81cc [t/spec] Add a bunch of new tests for .^methods, and move those in me…
jnthn authored
29 }
30
31 my (@methods, $meth1, $meth2);
32
33 @methods = C.^methods(:local);
34 is +@methods, 0, 'class C has no local methods (proto)';
35
36 @methods = C.new().^methods(:local);
37 is +@methods, 0, 'class C has no local methods (instance)';
38
39 @methods = B.^methods(:local);
40 is +@methods, 1, 'class B has one local methods (proto)';
41 is @methods[0].name(), 'foo', 'method name can be found';
42 ok @methods[0].signature.perl ~~ /'$param'/, 'method signature contains $param';
72d6c38 @jnthn Update methods.t for :excl semantics, new proto semantics and scatter…
jnthn authored
43 is @methods[0].returns.gist, Num.gist, 'method returns a Num (from .returns)';
44 is @methods[0].of.gist, Num.gist, 'method returns a Num (from .of)';
45 ok !@methods[0].is_dispatcher, 'method is not a dispatcher';
7cc81cc [t/spec] Add a bunch of new tests for .^methods, and move those in me…
jnthn authored
46
47 @methods = B.new().^methods(:local);
48 is +@methods, 1, 'class B has one local methods (instance)';
49 is @methods[0].name(), 'foo', 'method name can be found';
50 ok @methods[0].signature.perl ~~ /'$param'/, 'method signature contains $param';
72d6c38 @jnthn Update methods.t for :excl semantics, new proto semantics and scatter…
jnthn authored
51 is @methods[0].returns.gist, Num.gist, 'method returns a Num (from .returns)';
52 is @methods[0].of.gist, Num.gist, 'method returns a Num (from .of)';
53 ok !@methods[0].is_dispatcher, 'method is not a dispatcher';
7cc81cc [t/spec] Add a bunch of new tests for .^methods, and move those in me…
jnthn authored
54
55 @methods = A.^methods(:local);
56 is +@methods, 2, 'class A has two local methods (one only + one multi with two variants)';
72d6c38 @jnthn Update methods.t for :excl semantics, new proto semantics and scatter…
jnthn authored
57 my ($num_dispatchers, $num_onlys);
7cc81cc [t/spec] Add a bunch of new tests for .^methods, and move those in me…
jnthn authored
58 for @methods -> $meth {
59 if $meth.name eq 'foo' {
60 $num_onlys++;
72d6c38 @jnthn Update methods.t for :excl semantics, new proto semantics and scatter…
jnthn authored
61 ok !$meth.is_dispatcher, 'method foo is not a dispatcher';
7cc81cc [t/spec] Add a bunch of new tests for .^methods, and move those in me…
jnthn authored
62 } elsif $meth.name eq 'bar' {
72d6c38 @jnthn Update methods.t for :excl semantics, new proto semantics and scatter…
jnthn authored
63 $num_dispatchers++;
64 ok $meth.is_dispatcher, 'method bar is a dispatcher';
7cc81cc [t/spec] Add a bunch of new tests for .^methods, and move those in me…
jnthn authored
65 }
66 }
67 is $num_onlys, 1, 'class A has one only method';
72d6c38 @jnthn Update methods.t for :excl semantics, new proto semantics and scatter…
jnthn authored
68 is $num_dispatchers, 1, 'class A has one dispatcher method';
7cc81cc [t/spec] Add a bunch of new tests for .^methods, and move those in me…
jnthn authored
69
70 @methods = D.^methods();
72d6c38 @jnthn Update methods.t for :excl semantics, new proto semantics and scatter…
jnthn authored
71 ok +@methods == 5, 'got all methods in hierarchy but NOT those from Any/Mu';
7cc81cc [t/spec] Add a bunch of new tests for .^methods, and move those in me…
jnthn authored
72 ok @methods[0].name eq 'foo' && @methods[1].name eq 'bar' ||
73 @methods[0].name eq 'bar' && @methods[1].name eq 'foo',
74 'first two methods from class D itself';
75 is @methods[2].name, 'foo', 'method from B has correct name';
72d6c38 @jnthn Update methods.t for :excl semantics, new proto semantics and scatter…
jnthn authored
76 is @methods[2].of.gist, Num.gist, 'method from B has correct return type';
7cc81cc [t/spec] Add a bunch of new tests for .^methods, and move those in me…
jnthn authored
77 ok @methods[3].name eq 'foo' && @methods[4].name eq 'bar' ||
78 @methods[3].name eq 'bar' && @methods[4].name eq 'foo',
79 'two methods from class A itself';
80
9c40515 @dnmfarrell fixed appended RT number to be within quoted string
dnmfarrell authored
81 #?rakudo skip 'nom regression RT #125011'
e154be7 @coke nom fudging
coke authored
82 {
83 @methods = D.^methods(:tree);
84 is +@methods, 4, ':tree gives us right number of elements';
85 ok @methods[0].name eq 'foo' && @methods[1].name eq 'bar' ||
86 @methods[0].name eq 'bar' && @methods[1].name eq 'foo',
87 'first two methods from class D itself';
88 is @methods[2].WHAT.gist, Array.gist, 'third item is an array';
89 is +@methods[2], 2, 'nested array for B had right number of elements';
90 is @methods[3].WHAT.gist, Array.gist, 'forth item is an array';
91 is +@methods[3], 1, 'nested array for C had right number of elements';
92 is @methods[2], B.^methods(:tree), 'nested tree for B is correct';
93 is @methods[3], C.^methods(:tree), 'nested tree for C is correct';
94 }
cf1eda7 [t/spec] Tests for :tree modifier on .^methods, plus one for .perl on…
jnthn authored
95
7cc81cc [t/spec] Add a bunch of new tests for .^methods, and move those in me…
jnthn authored
96 @methods = List.^methods();
97 ok +@methods > 0, 'can get methods for List (proto)';
98 @methods = (1, 2, 3).^methods();
99 ok +@methods > 0, 'can get methods for List (instance)';
100
101 @methods = Str.^methods();
102 ok +@methods > 0, 'can get methods for Str (proto)';
103 @methods = "i can haz test pass?".^methods();
104 ok +@methods > 0, 'can get methods for Str (instance)';
105
72d6c38 @jnthn Update methods.t for :excl semantics, new proto semantics and scatter…
jnthn authored
106 ok +List.^methods(:all) > +Any.^methods(:all), 'List has more methods than Any';
107 ok +Any.^methods(:all) > +Mu.^methods(), 'Any has more methods than Mu';
7cc81cc [t/spec] Add a bunch of new tests for .^methods, and move those in me…
jnthn authored
108
109 ok +(D.^methods>>.name) > 0, 'can get names of methods in and out of our own classes';
cf1eda7 [t/spec] Tests for :tree modifier on .^methods, plus one for .perl on…
jnthn authored
110 ok D.^methods.perl, 'can get .perl of output of .^methods';
111
f3884f9 [t/spec] Tests for :private flag on .^methods.
jnthn authored
112 class PT1 {
113 method !pm1() { }
114 method foo() { }
115 }
116 class PT2 is PT1 {
117 method !pm2() { }
118 method bar() { }
119 }
cf1eda7 [t/spec] Tests for :tree modifier on .^methods, plus one for .perl on…
jnthn authored
120
72d6c38 @jnthn Update methods.t for :excl semantics, new proto semantics and scatter…
jnthn authored
121 @methods = PT2.^methods(:all); # (all since we want at least one more)
f3884f9 [t/spec] Tests for :private flag on .^methods.
jnthn authored
122 is @methods[0].name, 'bar', 'methods call found public method in subclass';
123 is @methods[1].name, 'foo', 'methods call found public method in superclass (so no privates)';
124 ok @methods[2].name ne '!pm1', 'methods call did not find private method in superclass';
125
9c40515 @dnmfarrell fixed appended RT number to be within quoted string
dnmfarrell authored
126 #?rakudo skip 'nom regression RT #125012'
51e1489 @usev6 Fix fudging (and number of tests)
usev6 authored
127 {
128 @methods = PT2.^methods(:private);
129 ok @methods[0].name eq '!pm2' || @methods[1].name eq '!pm2',
130 'methods call with :private found private method in subclass';
131 ok @methods[2].name eq '!pm1' || @methods[3].name eq '!pm1',
132 'methods call with :private found private method in superclass';
133 }
f3884f9 [t/spec] Tests for :private flag on .^methods.
jnthn authored
134
135 @methods = PT2.^methods(:local);
136 is +@methods, 1, 'methods call without :private omits private methods (with :local)';
137 is @methods[0].name, 'bar', 'methods call found public method in subclass (with :local)';
138
9c40515 @dnmfarrell fixed appended RT number to be within quoted string
dnmfarrell authored
139 #?rakudo skip 'nom regression RT #125013'
e154be7 @coke nom fudging
coke authored
140 {
141 @methods = PT2.^methods(:local, :private);
142 is +@methods, 2, 'methods call with :private includes private methods (with :local)';
143 ok @methods[0].name eq '!pm2' || @methods[1].name eq '!pm2',
144 'methods call with :private found private method in subclass (with :local)';
145 }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
146
4ac2c2b @jnthn Test for RT#115658.
jnthn authored
147 {
9f47446 @lizmat s/lives_ok/lives-ok/g
lizmat authored
148 lives-ok { Sub.^methods.gist }, 'Can .gist methods of a subroutine';
149 lives-ok { Sub.^methods.perl }, 'Can .perl methods of a subroutine';
150 lives-ok { Method.^methods.gist }, 'Can .gist methods of a method';
151 lives-ok { Method.^methods.perl }, 'Can .perl methods of a method';
152 lives-ok { { $^a }.^methods.gist }, 'Can .gist methods of a block';
153 lives-ok { { $^a }.^methods.perl }, 'Can .perl methods of a block';
b4d71e8 @jnthn Test for RT #108968.
jnthn authored
154 # RT #108968
9f47446 @lizmat s/lives_ok/lives-ok/g
lizmat authored
155 lives-ok { :(Int).^methods>>.gist }, 'Can >>.gist methods of a Signature';
4ac2c2b @jnthn Test for RT#115658.
jnthn authored
156 }
157
951c516 @coke add test for RT # 76648
coke authored
158 # RT #76648
159 # order of ^methods
160
161 {
162 class Foo { has $.bar; has $.baz; has $.antler };
163 is Foo.^methods.join(","), "bar,baz,antler", "order of ^methods consistent";
164 }
165
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
166 # vim: ft=perl6
Something went wrong with that request. Please try again.