| 1 |
#!./perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use Test::More tests => 19; |
| 7 |
use Scalar::Util qw(looks_like_number); |
| 8 |
|
| 9 |
foreach my $num (qw(1 -1 +1 1.0 +1.0 -1.0 -1.0e-12)) { |
| 10 |
ok(looks_like_number($num), "'$num'"); |
| 11 |
} |
| 12 |
|
| 13 |
is(!!looks_like_number("Inf"), $] >= 5.006001, 'Inf'); |
| 14 |
is(!!looks_like_number("Infinity"), $] >= 5.008, 'Infinity'); |
| 15 |
is(!!looks_like_number("NaN"), $] >= 5.008, 'NaN'); |
| 16 |
is(!!looks_like_number("foo"), '', 'foo'); |
| 17 |
is(!!looks_like_number(undef), '', 'undef'); |
| 18 |
is(!!looks_like_number({}), '', 'HASH Ref'); |
| 19 |
is(!!looks_like_number([]), '', 'ARRAY Ref'); |
| 20 |
|
| 21 |
use Math::BigInt; |
| 22 |
my $bi = Math::BigInt->new('1234567890'); |
| 23 |
is(!!looks_like_number($bi), 1, 'Math::BigInt'); |
| 24 |
is(!!looks_like_number("$bi"), 1, 'Stringified Math::BigInt'); |
| 25 |
|
| 26 |
{ package Foo; |
| 27 |
sub TIEHASH { bless {} } |
| 28 |
sub FETCH { $_[1] } |
| 29 |
} |
| 30 |
my %foo; |
| 31 |
tie %foo, 'Foo'; |
| 32 |
is(!!looks_like_number($foo{'abc'}), '', 'Tied'); |
| 33 |
is(!!looks_like_number($foo{'123'}), 1, 'Tied'); |
| 34 |
|
| 35 |
is(!!looks_like_number("\x{1815}"), '', 'MONGOLIAN DIGIT FIVE'); |
| 36 |
|
| 37 |
# We should copy some of perl core tests like t/base/num.t here |