diff options
Diffstat (limited to 'gnu/usr.bin/perl/ext/B/t/bool.t')
-rw-r--r-- | gnu/usr.bin/perl/ext/B/t/bool.t | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/gnu/usr.bin/perl/ext/B/t/bool.t b/gnu/usr.bin/perl/ext/B/t/bool.t new file mode 100644 index 00000000000..1af7dfbab0e --- /dev/null +++ b/gnu/usr.bin/perl/ext/B/t/bool.t @@ -0,0 +1,59 @@ +#!./perl + +BEGIN { + unshift @INC, 't'; + require Config; + if (($Config::Config{'extensions'} !~ /\bB\b/) ){ + print "1..0 # Skip -- Perl configured without B module\n"; + exit 0; + } +} + +use strict; +use warnings; + +use B; +use Test::More; + +$| = 1; + +{ + note "testing true"; + my $bool = ( 1 == 1 ); + my $sv = B::svref_2object(\$bool); + ok $sv->IsBOOL, "got a boolean"; + ok $sv->TRUE_nomg, "TRUE_nomg is true"; + ok $sv->TRUE, "TRUE is true"; +} + +{ + note "testing false"; + my $bool = ( 1 == 0 ); + my $sv = B::svref_2object(\$bool); + + ok $sv->IsBOOL, "got a boolean"; + ok !$sv->TRUE_nomg, "TRUE_nomg is false"; + ok !$sv->TRUE, "TRUE is false"; +} + +{ + note "not a boolean"; + my $iv = 42; + my $sv = B::svref_2object(\$iv); + + ok !$sv->IsBOOL, "not a boolean"; + ok $sv->TRUE_nomg, "TRUE_nomg is true"; + ok $sv->TRUE, "TRUE is true"; +} + +{ + note "not a boolean"; + my $iv = 0; + my $sv = B::svref_2object(\$iv); + + ok !$sv->IsBOOL, "not a boolean"; + ok !$sv->TRUE_nomg, "TRUE_nomg is false"; + ok !$sv->TRUE, "TRUE is false"; +} + +done_testing(); |