1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
use Test2::V0;
use Config;
use Scalar::Type qw(:all);
if(Scalar::Type::bool_supported) {
is(
type(1 == 1),
'BOOL',
'type(1 == 1) is BOOL'
);
is(
type(1 == 0),
'BOOL',
'type(1 == 0) is BOOL'
);
ok(is_bool(1 == 1), 'is_bool says yes for (1 == 1)');
ok(is_bool(1 == 0), 'is_bool says yes for (1 == 0)');
ok(!is_bool(1), 'but it says no for plain old 1 (otherwise indistinguishable from (1 == 1))');
ok(!is_bool(''), "and it says no for plain old '' (otherwise indistinguishable from (1 == 0))");
} else {
# the :all above only included is_bool if bool_supported so we need to use the full name here
like
dies { Scalar::Type::is_bool(1 == 1) },
qr/::is_bool not supported on your perl/,
"is_bool carks it on Ye Olde Perle $]";
is(
type(1 == 1),
'INTEGER',
'type(1 == 1) is INTEGER'
);
is(
type(1 == 0),
'SCALAR',
'type(1 == 0) is SCALAR'
);
# finally, test that we can't explicitly import is_bool on Ye Olde Perle
like
dies { Scalar::Type->import('is_bool') },
qr/is_bool/,
"can't import is_bool on Ye Olde Perle $]";
}
done_testing;
|