Skip to content

Commit

Permalink
Add test and docs for (to be written) ^^ operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Martijn Lievaart authored and leonerd committed Feb 18, 2024
1 parent 5fdf6e9 commit 52b49c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 8 additions & 1 deletion pod/perlop.pod
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ values only, not array values.
left & &.
left | |. ^ ^.
left &&
left || //
left || ^^ //
nonassoc .. ...
right ?:
right = += -= *= etc. goto last next redo dump
Expand Down Expand Up @@ -1019,6 +1019,13 @@ if the left operand is true, the right operand is not even evaluated.
Scalar or list context propagates down to the right operand if it
is evaluated.

=head2 C-style Logical Xor
X<^^> X<operator, logical, xor>

Binary C<"^^"> performs a logical XOR operation. Both operands are
evaluated and the result is true only if exactly one of the operands is true.
Scalar or list context propagates down to the right operand.

=head2 Logical Defined-Or
X<//> X<operator, logical, defined-or>

Expand Down
11 changes: 9 additions & 2 deletions t/op/lop.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!./perl

#
# test the logical operators '&&', '||', '!', 'and', 'or', , 'xor', 'not'
# test the logical operators '&&', '||', '^^', '!', 'and', 'or', , 'xor', 'not'
#

BEGIN {
Expand All @@ -10,7 +10,7 @@ BEGIN {
set_up_inc('../lib');
}

plan tests => 33;
plan tests => 47;

for my $i (undef, 0 .. 2, "", "0 but true") {
my $true = 1;
Expand Down Expand Up @@ -104,4 +104,11 @@ for my $test (
) {
my ($a,$b, $exp) = @$test;
is(($a xor $b), $exp, "($a xor $b) == '$exp'");
is(($a ^^ $b), $exp, "($a ^^ $b) == '$exp'");
}

# precedence
is((1 xor 1 and 0), 1, '(1 xor 1 and 0) == 1');
is((1 xor 0 or 1), '', "(1 xor 0 or 1) == ''");
is((1 ^^ 1 && 0), 1, '(1 xor 1 and 0) == 1');
is((1 ^^ 0 || 1), '', "(1 ^^ 0 || 1) == ''");

0 comments on commit 52b49c4

Please sign in to comment.