"123\n" is a string, not a number
Ivan Bessarabov
8 years ago
370 | 370 |
( \. [0-9]+ )? # there can be decimal part, which is optional
|
371 | 371 |
|
372 | 372 |
( e [+-] [0-9]+ )? # then there can be optional exponential notation part
|
373 | |
$
|
|
373 |
\z
|
374 | 374 |
/x;
|
375 | 375 |
|
376 | 376 |
return $is_number;
|
40 | 40 |
"NaN",
|
41 | 41 |
"abc",
|
42 | 42 |
'1_000',
|
|
43 |
'123\n',
|
|
44 |
"123\n",
|
43 | 45 |
);
|
44 | 46 |
|
45 | 47 |
foreach my $not_a_number (@strings) {
|
|
48 |
|
|
49 |
# If we don't change new line symbol then the test output will be messy:
|
|
50 |
#
|
|
51 |
# ok 20 - _is_number('1_000') return false
|
|
52 |
# ok 21 - _is_number('123
|
|
53 |
# # ') return false
|
|
54 |
# 1..21
|
|
55 |
|
|
56 |
my $number_for_test_name = $not_a_number;
|
|
57 |
$number_for_test_name =~ s/\n/\\n/g;
|
|
58 |
|
46 | 59 |
ok(
|
47 | 60 |
not(Data::Printer::_is_number($not_a_number)),
|
48 | |
"_is_number('$not_a_number') return false",
|
|
61 |
"_is_number('$number_for_test_name') return false",
|
49 | 62 |
);
|
50 | 63 |
}
|
51 | 64 |
|