This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
t/op/bop.t: Verify bitwise & ^ | retain UTF-8
authorKarl Williamson <khw@cpan.org>
Wed, 7 Jun 2017 19:57:41 +0000 (13:57 -0600)
committerKarl Williamson <khw@cpan.org>
Wed, 7 Jun 2017 21:05:17 +0000 (15:05 -0600)
If one of the inputs is encoded in UTF-8, the behavior has been to have
the output be also in UTF-8.  This has not been really documented, but I
think that is the way it should be.  In any case, this commit adds tests
to make sure it doesn't inadvertently get changed.

t/op/bop.t

index 45ebb00..1837e96 100644 (file)
@@ -19,7 +19,7 @@ BEGIN {
 # If you find tests are failing, please try adding names to tests to track
 # down where the failure is, and supply your new names as a patch.
 # (Just-in-time test naming)
-plan tests => 334;
+plan tests => 340;
 
 # numerics
 ok ((0xdead & 0xbeef) == 0x9ead);
@@ -268,6 +268,26 @@ ok(utf8::is_utf8($a)); # make sure UTF8 flag is still there
 $a = ~$a;
 is($a, "\xFF", "~ works with utf-8");
 
+$a = "\0\x{100}"; chop($a);
+undef $b;
+$b = $a | "\xFF";
+ok(utf8::is_utf8($b), "Verify UTF-8 | non-UTF-8 retains UTF-8 flag");
+undef $b;
+$b = "\xFF" | $a;
+ok(utf8::is_utf8($b), "Verify non-UTF-8 | UTF-8 retains UTF-8 flag");
+undef $b;
+$b = $a & "\xFF";
+ok(utf8::is_utf8($b), "Verify UTF-8 & non-UTF-8 retains UTF-8 flag");
+undef $b;
+$b = "\xFF" & $a;
+ok(utf8::is_utf8($b), "Verify non-UTF-8 & UTF-8 retains UTF-8 flag");
+undef $b;
+$b = $a ^ "\xFF";
+ok(utf8::is_utf8($b), "Verify UTF-8 ^ non-UTF-8 retains UTF-8 flag");
+undef $b;
+$b = "\xFF" ^ $a;
+ok(utf8::is_utf8($b), "Verify non-UTF-8 ^ UTF-8 retains UTF-8 flag");
+
 # [rt.perl.org 33003]
 # This would cause a segfault without malloc wrap
 SKIP: {