/
instantiate.t
51 lines (42 loc) 路 1.21 KB
/
instantiate.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
use v6;
use Test;
plan 7;
# L<S12/Construction and Initialization>
# Basic instantiation.
class Foo1 { };
my $foo1 = Foo1.new();
ok(defined($foo1), 'instantiated a class');
# Instantiation with initializing attributes.
class Foo2 {
has $.a;
has $.b;
method check {
$!a + $!b
}
}
my $foo2 = Foo2.new(:a(39), :b(3));
is($foo2.check(), 42, 'initializing attributes in new');
# RT #62732
{
try { EVAL 'NoSuchClass.new()' };
#?niecza skip 'Exception NYI'
ok $! ~~ Exception, 'death to instantiating nonexistent class';
ok "$!" ~~ / NoSuchClass /,
'error for "NoSuchClass.new()" mentions NoSuchClass';
try { EVAL 'NoSuch::Subclass.new()' };
#?niecza skip 'Exception NYI'
ok $! ~~ Exception, 'death to instantiating nonexistent::class';
#?rakudo todo 'error reporting'
#?niecza todo
ok "$!" ~~ / 'NoSuch::Subclass' /,
'error for "NoSuch::Subclass.new()" mentions NoSuch::Subclass';
}
# RT 65224
#instantiation from class name unexpectedly creates a class object instead of Str object
{
class Foo { };
my $x = 'Foo';
my $y = $x.new;
is($y.WHAT.gist, Str.gist, "instantiating from class name string creates a Str object");
}
# vim: ft=perl6