Update to Scalar-List-Utils-1.15
[p5sagit/p5-mst-13.2.git] / ext / List / Util / t / reftype.t
CommitLineData
1bfb5477 1#!./perl
2
f4a2945e 3BEGIN {
1bfb5477 4 unless (-d 'blib') {
f4a2945e 5 chdir 't' if -d 't';
6 @INC = '../lib';
6b05f64e 7 require Config; import Config;
1bfb5477 8 keys %Config; # Silence warning
6b05f64e 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 14}
15
cf083cf9 16use Test::More tests => 23;
1bfb5477 17
f4a2945e 18use Scalar::Util qw(reftype);
19use vars qw($t $y $x *F);
20use Symbol qw(gensym);
21
22# Ensure we do not trigger and tied methods
23tie *F, 'MyTie';
24
25@test = (
cf083cf9 26 [ undef, 1, 'number' ],
27 [ undef, 'A', 'string' ],
28 [ HASH => {}, 'HASH ref' ],
29 [ ARRAY => [], 'ARRAY ref' ],
30 [ SCALAR => \$t, 'SCALAR ref' ],
31 [ REF => \(\$t), 'REF ref' ],
32 [ GLOB => \*F, 'tied GLOB ref' ],
33 [ GLOB => gensym, 'GLOB ref' ],
34 [ CODE => sub {}, 'CODE ref' ],
f4a2945e 35# [ IO => *STDIN{IO} ] the internal sv_reftype returns UNKNOWN
36);
37
f4a2945e 38foreach $test (@test) {
cf083cf9 39 my($type,$what, $n) = @$test;
40
41 is( reftype($what), $type, $n);
42 next unless ref($what);
43
44 bless $what, "ABC";
45 is( reftype($what), $type, $n);
46
47 bless $what, "0";
48 is( reftype($what), $type, $n);
f4a2945e 49}
50
51package MyTie;
52
53sub TIEHANDLE { bless {} }
54sub DESTROY {}
55
56sub AUTOLOAD {
57 warn "$AUTOLOAD called";
58 exit 1; # May be in an eval
59}