/
meta-class.t
80 lines (61 loc) 路 2.09 KB
/
meta-class.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use v6;
use Test;
plan 17;
=begin pod
Very basic meta-class tests from L<S12/Introspection>
=end pod
class Foo:ver<0.0.1>:auth<ority> {
method bar ($param) returns Str {
return "baz" ~ $param
}
};
# L<S12/Introspection/should be called through the meta object>
ok(Foo.HOW.can(Foo, 'bar'), '... Foo can bar');
ok(HOW(Foo).can(Foo, 'bar'), '... Foo can bar (anthoer way)');
ok(Foo.^can('bar'), '... Foo can bar (as class method)');
ok(Foo.HOW.isa(Foo, Foo), '... Foo is-a Foo (of course)');
ok(Foo.^isa(Foo), '... Foo is-a Foo (of course) (as class method)');
lives-ok { 4.HOW.HOW }, 'Can access meta class of meta class';
# L<S12/Introspection/Class traits may include:>
is Foo.^name(), 'Foo', '... the name() property is Foo';
is Foo.^ver(), v0.0.1, '... the ver() property is 0.0.1';
is Foo.^auth(), 'ority', '... the auth() property is ority';
is Foo.REPR, 'P6opaque', '.REPR';
subtest { plan 3;
my module M:ver<1.2.3>:auth<me> {};
is M.^name, 'M', '.name is correct';
is M.^ver, '1.2.3', '.ver is correct';
is M.^auth, 'me', '.auth is correct';
}, 'metamethods on a module';
# RT #128579
subtest { plan 2;
my package P:ver<1.2.3>:auth<me> {};
throws-like { P.^ver }, X::Method::NotFound, '.ver is absent';
throws-like { P.^auth }, X::Method::NotFound, '.auth is absent';
}, 'ID metamethods on a package are absent by design';
# RT #115208
eval-lives-ok "True.HOW.say", "can output the .gist of a .HOW";
# RT #114130
{
throws-like 'Any.HOW(Foo)', X::Syntax::Argument::MOPMacro;
}
# RT #121885
class IntrospectAtBEGINTime {
is BEGIN { IntrospectAtBEGINTime.^name }, 'IntrospectAtBEGINTime', '.^foo works at BEGIN time';
}
# RT #80694
{
my class A {
method foo { 'abc' };
A.^add_method('bar', A.^can('foo'));
}
dies-ok { A.new().bar() }, 'Using .^add_method with what .^can returns (a list) will never work';
}
{
my class A {
method foo { 'abc' };
A.^add_method('bar', A.^lookup('foo'));
}
is A.new().bar(), 'abc', 'Can .^add_method what .^lookup returns under another name and it works';
}
# vim: ft=perl6