Commit | Line | Data |
---|---|---|
1bfb5477 GB |
1 | #!./perl |
2 | ||
f4a2945e | 3 | BEGIN { |
1bfb5477 | 4 | unless (-d 'blib') { |
f4a2945e JH |
5 | chdir 't' if -d 't'; |
6 | @INC = '../lib'; | |
6b05f64e | 7 | require Config; import Config; |
1bfb5477 | 8 | keys %Config; # Silence warning |
6b05f64e PP |
9 | if ($Config{extensions} !~ /\bList\/Util\b/) { |
10 | print "1..0 # Skip: List::Util was not built\n"; | |
11 | exit 0; | |
12 | } | |
1bfb5477 | 13 | } |
f4a2945e JH |
14 | } |
15 | ||
2ff28616 | 16 | use Test::More tests => 11; |
f4a2945e | 17 | use Scalar::Util qw(blessed); |
cf083cf9 | 18 | use vars qw($t $x); |
f4a2945e | 19 | |
98eca5fa SH |
20 | ok(!defined blessed(undef), 'undef is not blessed'); |
21 | ok(!defined blessed(1), 'Numbers are not blessed'); | |
22 | ok(!defined blessed('A'), 'Strings are not blessed'); | |
23 | ok(!defined blessed({}), 'Unblessed HASH-ref'); | |
24 | ok(!defined blessed([]), 'Unblessed ARRAY-ref'); | |
25 | ok(!defined blessed(\$t), 'Unblessed SCALAR-ref'); | |
f4a2945e JH |
26 | |
27 | $x = bless [], "ABC"; | |
cf083cf9 | 28 | is(blessed($x), "ABC", 'blessed ARRAY-ref'); |
f4a2945e | 29 | |
cf083cf9 GB |
30 | $x = bless {}, "DEF"; |
31 | is(blessed($x), "DEF", 'blessed HASH-ref'); | |
2ff28616 GB |
32 | |
33 | $x = bless {}, "0"; | |
34 | cmp_ok(blessed($x), "eq", "0", 'blessed HASH-ref'); | |
35 | ||
36 | { | |
2dc8d725 CBW |
37 | my $blessed = do { |
38 | my $depth; | |
2ff28616 | 39 | no warnings 'redefine'; |
2dc8d725 CBW |
40 | local *UNIVERSAL::can = sub { die "Burp!" if ++$depth > 2; blessed(shift) }; |
41 | $x = bless {}, "DEF"; | |
42 | blessed($x); | |
43 | }; | |
44 | is($blessed, "DEF", 'recursion of UNIVERSAL::can'); | |
2ff28616 GB |
45 | } |
46 | ||
47 | { | |
48 | package Broken; | |
49 | sub isa { die }; | |
50 | sub can { die }; | |
51 | ||
52 | my $obj = bless [], __PACKAGE__; | |
53 | ::is( ::blessed($obj), __PACKAGE__, "blessed on broken isa() and can()" ); | |
54 | } | |
55 |