bop.t revision 7c478bd95313f5f23a4c958a745db2134aa03244
#!./perl
#
# test the bit operators '&', '|', '^', '~', '<<', and '>>'
#
BEGIN {
chdir 't' if -d 't';
}
print "1..44\n";
# numerics
print ((0xdead & 0xbeef) == 0x9ead ? "ok 1\n" : "not ok 1\n");
print ((0xdead | 0xbeef) == 0xfeef ? "ok 2\n" : "not ok 2\n");
print ((0xdead ^ 0xbeef) == 0x6042 ? "ok 3\n" : "not ok 3\n");
print ((~0xdead & 0xbeef) == 0x2042 ? "ok 4\n" : "not ok 4\n");
# shifts
print ((257 << 7) == 32896 ? "ok 5\n" : "not ok 5\n");
print ((33023 >> 7) == 257 ? "ok 6\n" : "not ok 6\n");
# signed vs. unsigned
print ((~0 > 0 && do { use integer; ~0 } == -1)
? "ok 7\n" : "not ok 7\n");
my $bits = 0;
? "ok 8\n" : "not ok 8\n");
? "ok 9\n" : "not ok 9\n");
? "ok 10\n" : "not ok 10\n");
? "ok 11\n" : "not ok 11\n");
? "ok 12\n" : "not ok 12\n");
# short strings
# long strings
# & truncates
# | does not truncate
# ^ does not truncate
#
print "ok \xFF\xFF\n" & "ok 19\n";
print "ok 20\n" | "ok \0\0\n";
print "o\000 \0001\000" ^ "\000k\0002\000\n";
#
print "ok \x{FF}\x{FF}\n" & "ok 22\n";
print "ok 23\n" | "ok \x{0}\x{0}\n";
print "o\x{0} \x{0}4\x{0}" ^ "\x{0}k\x{0}2\x{0}\n";
#
#
#
#
my $a = v120.300;
my $b = v200.400;
$a ^= $b;
my $a = v120.300;
my $b = v200.400;
$a |= $b;
#
# UTF8 ~ behaviour
#
my @not36;
for (0x100...0xFFF) {
}
print "# test 36 failed\n";
print "not ";
}
print "ok 36\n";
my @not37;
for my $i (0xEEE...0xF00) {
for my $j (0x0..0x120) {
}
}
print "# test 37 failed\n";
print "not ";
}
print "ok 37\n";
print "ok 38\n";
my @not39;
for my $i (0x100..0x120) {
for my $j (0x100...0x120) {
}
}
print "# test 39 failed\n";
print "not ";
}
print "ok 39\n";
my @not40;
for my $i (0x100..0x120) {
for my $j (0x100...0x120) {
}
}
print "# test 40 failed\n";
print "not ";
}
print "ok 40\n";
# More variations on 19 and 22.
print "ok \xFF\x{FF}\n" & "ok 41\n";
print "ok \x{FF}\xFF\n" & "ok 42\n";
# Tests to see if you really can do casts negative floats to unsigned properly
$neg1 = -1.0;
$neg7 = -7.0;