Lines 1-39
Link Here
|
1 |
|
|
|
2 |
use Modern::Perl; |
3 |
|
4 |
use Test::More tests => 22; |
5 |
use Test::Warn; |
6 |
|
7 |
BEGIN { use_ok( 'C4::Boolean', qw( true_p ) ); } |
8 |
|
9 |
is( true_p('0'), '0', 'recognizes \'0\' as false' ); |
10 |
is( true_p('nil'), '0', 'recognizes \'nil\' as false' ); |
11 |
is( true_p('false'), '0', 'recognizes \'false\' as false' ); |
12 |
is( true_p('off'), '0', 'recognizes \'off\' as false' ); |
13 |
is( true_p('no'), '0', 'recognizes \'no\' as false' ); |
14 |
is( true_p('n'), '0', 'recognizes \'n\' as false' ); |
15 |
is( true_p('NO'), '0', 'verified case insensitivity' ); |
16 |
|
17 |
is( true_p('1'), '1', 'recognizes \'1\' as true' ); |
18 |
is( true_p('-1'), '1', 'recognizes \'-1\' as true' ); |
19 |
is( true_p('t'), '1', 'recognizes \'t\' as true' ); |
20 |
is( true_p('true'), '1', 'recognizes \'true\' as true' ); |
21 |
is( true_p('on'), '1', 'recognizes \'on\' as true' ); |
22 |
is( true_p('yes'), '1', 'recognizes \'yes\' as true' ); |
23 |
is( true_p('y'), '1', 'recognizes \'y\' as true' ); |
24 |
is( true_p('YES'), '1', 'verified case insensitivity' ); |
25 |
|
26 |
my $result; |
27 |
warning_like { $result = true_p(undef) } |
28 |
qr/^The given value does not seem to be interpretable as a Boolean value/, |
29 |
'Invalid boolean (undef) raises warning'; |
30 |
is( $result, undef, 'recognizes undefined as not boolean' ); |
31 |
warning_like { $result = true_p('foo') } |
32 |
qr/^The given value does not seem to be interpretable as a Boolean value/, |
33 |
'Invalid boolean (\'foo\') raises warning'; |
34 |
is( $result, undef, 'recognizes \'foo\' as not boolean' ); |
35 |
warning_like { $result = true_p([]) } |
36 |
qr/^The given value does not seem to be interpretable as a Boolean value/, |
37 |
'Invalid boolean (reference) raises warning'; |
38 |
is( $result, undef, 'recognizes a reference as not a boolean' ); |
39 |
|
40 |
- |