/
calling_syntax.t
50 lines (40 loc) 路 1.34 KB
/
calling_syntax.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
use Test;
plan 12;
=begin description
Test for
=end description
# L<S02/Bare identifiers/"$x.foo;">
class Foo {
method foo {
42
}
method bar() {
101
}
method identity($x) {
$x
}
}
my $x = Foo.new();
is($x.foo, 42, 'called a method without parens');
is($x.foo(), 42, 'called a method without parens');
is($x.bar, 101, 'called a method with parens');
is($x.bar(), 101, 'called a method with parens');
is($x.identity("w00t"), "w00t", 'called a method with a parameter');
# L<S12/Methods/"You can replace the identifier with a quoted string">
throws-like q{$x.'foo'}, Exception, 'indirect method call using quotes, no parens';
is($x.'bar'(), 101, 'indirect method call using quotes, with parens'); #OK use of quotes
is($x.'identity'('qwerty'), 'qwerty', 'indirect method call using quotes, with parameter'); #OK use of quotes
{
my $name = 'foo';
throws-like q{$x."$name"}, Exception, 'indirect method call, no parens';
is($x."$name"(), 42, 'indirect method call, with parens');
}
{
my $name = 'identity';
is($x."$name"('asdf'), 'asdf', 'indirect method call, with parameter');
}
# https://github.com/Raku/old-issue-tracker/issues/6303
is-deeply my class RT131478 { method Str { $.^name } }.Str, 'RT131478',
'`$.` syntax shorthand works with meta-methods';
# vim: expandtab shiftwidth=4