summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJames E Keenan <jkeenan@cpan.org>2021-12-01 13:04:45 +0000
committerJames E Keenan <jkeenan@cpan.org>2021-12-07 23:53:35 +0000
commitb2d0d92ba8eefbcb5afd8e04a8f263b4938f26ef (patch)
tree609a32d6c8d60d9cb9269f45c7a40b7f0055d222 /lib
parentad06173e13ddbddbf53a4f776f5c03f061acb68f (diff)
downloadperl-b2d0d92ba8eefbcb5afd8e04a8f263b4938f26ef.tar.gz
Test equivalence of 'true' and 'false' to negated statements
The documentation for lib/builtin.pm asserts that 'true' is equivalent to !!1 or !0, and that false is equivalent to !!0 or !1. Demonstrate that this is so. Per review by Paul Evans in https://github.com/Perl/perl5/pull/19252, we'll use cmp_ok() rather than is() and test for each of 'eq' and '=='.
Diffstat (limited to 'lib')
-rw-r--r--lib/builtin.t12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/builtin.t b/lib/builtin.t
index 4f4e33a49e..b94cef4e40 100644
--- a/lib/builtin.t
+++ b/lib/builtin.t
@@ -112,4 +112,16 @@ package FetchStoreCounter {
ok($recursecoderef->("rec"), 'true in self-recursive anon sub');
}
+{
+ use builtin qw( true false );
+
+ my $val = true;
+ cmp_ok($val, $_, !!1, "true is equivalent to !!1 by $_") for qw( eq == );
+ cmp_ok($val, $_, !0, "true is equivalent to !0 by $_") for qw( eq == );
+
+ $val = false;
+ cmp_ok($val, $_, !!0, "false is equivalent to !!0 by $_") for qw( eq == );
+ cmp_ok($val, $_, !1, "false is equivalent to !1 by $_") for qw( eq == );
+}
+
done_testing();