-
Notifications
You must be signed in to change notification settings - Fork 135
/
isa.t
69 lines (47 loc) · 1.64 KB
/
isa.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
use v6;
use Test;
=begin kwid
.isa() tests
These tests are specific to the .isa() which is attached to the
Perl6 Array "class". Which is actually @array.HOW.isa(), which
is actually just the normal OO .isa(). This test does not attempt
to test anything other than the "normal" behavior of @array.isa()
Further clarification of .isa() can be found here:
L<"http://www.nntp.perl.org/group/perl.perl6.language/20974">
L<S29/Any/=item isa/>
=end kwid
plan 10;
{ # invocant notation
my @arr = <1 2 3 4>;
ok(@arr.isa(Array), '... @arr is-a Array (invocant notation)');
# check a failing case
ok(!@arr.isa(Hash), '... @arr is-not-a Hash (invocant notation)');
}
{ # invocant notation
my $arr_ref = <1 2 3 4>;
# check a failing case
nok($arr_ref.isa(Hash), '... $arr is-not-a Hash (invocant notation)');
}
# check error cases
{
my @arr = <1 2 3 4>;
eval_dies_ok 'isa(@arr, Array)', 'no sub called isa()';
dies_ok { @arr.isa() }, '... isa() with a single arg is a failing case (invocant notation)';
dies_ok { @arr.isa(Array, Hash) }, '... isa() with a extra args is a failing case (invocant notation)';
}
## some edge cases, and weirdness
{ # check .isa() on inline values
ok([1, 2, 3, 4].isa(Array), '... [1, 2, 3, 4].isa("Array") works');
ok(![1, 2, 3, 4].isa(Hash), '... [1, 2, 3, 4].isa("Hash") fail predicably');
}
class Thing {};
{
my $thing = Thing.new();
ok($thing.isa(Thing), '.isa named class');
}
class Thing::something {};
{
my $thing = Thing::something.new();
ok($thing.isa(Thing::something), '.isa named class with colons');
}
# vim: ft=perl6