Commit | Line | Data |
9e7deb6c |
1 | #!/usr/bin/perl -w |
9e7deb6c |
2 | |
3 | BEGIN { |
4 | unless (-d 'blib') { |
5 | chdir 't' if -d 't'; |
6 | @INC = '../lib'; |
7 | require Config; import Config; |
8 | keys %Config; # Silence warning |
9 | if ($Config{extensions} !~ /\bList\/Util\b/) { |
10 | print "1..0 # Skip: List::Util was not built\n"; |
11 | exit 0; |
12 | } |
13 | } |
14 | } |
15 | |
cf083cf9 |
16 | use strict; |
2ff28616 |
17 | use Test::More tests => 18; |
9e7deb6c |
18 | use Scalar::Util qw(looks_like_number); |
19 | |
cf083cf9 |
20 | foreach my $num (qw(1 -1 +1 1.0 +1.0 -1.0 -1.0e-12)) { |
21 | ok(looks_like_number($num), "'$num'"); |
22 | } |
9e7deb6c |
23 | |
cf083cf9 |
24 | is(!!looks_like_number("Inf"), $] >= 5.006001, 'Inf'); |
25 | is(!!looks_like_number("Infinity"), $] >= 5.008, 'Infinity'); |
26 | is(!!looks_like_number("NaN"), $] >= 5.008, 'NaN'); |
27 | is(!!looks_like_number("foo"), '', 'foo'); |
4984adac |
28 | is(!!looks_like_number(undef), '', 'undef'); |
29 | is(!!looks_like_number({}), '', 'HASH Ref'); |
30 | is(!!looks_like_number([]), '', 'ARRAY Ref'); |
31 | |
32 | use Math::BigInt; |
33 | my $bi = Math::BigInt->new('1234567890'); |
2ff28616 |
34 | is(!!looks_like_number($bi), 1, 'Math::BigInt'); |
4984adac |
35 | is(!!looks_like_number("$bi"), 1, 'Stringified Math::BigInt'); |
9e7deb6c |
36 | |
2ff28616 |
37 | { package Foo; |
38 | sub TIEHASH { bless {} } |
39 | sub FETCH { $_[1] } |
40 | } |
41 | my %foo; |
42 | tie %foo, 'Foo'; |
43 | is(!!looks_like_number($foo{'abc'}), '', 'Tied'); |
44 | is(!!looks_like_number($foo{'123'}), 1, 'Tied'); |
45 | |
cf083cf9 |
46 | # We should copy some of perl core tests like t/base/num.t here |