X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/4e002eb05459a979289e3370d725d5d3a3407109..81d11450691ee281f37c6c4e8055735b972733bd:/lib/bytes.t diff --git a/lib/bytes.t b/lib/bytes.t index 05c748c..4e50ff3 100644 --- a/lib/bytes.t +++ b/lib/bytes.t @@ -1,28 +1,73 @@ + BEGIN { chdir 't' if -d 't'; @INC = '../lib'; + require './test.pl'; } -print "1..6\n"; +plan tests => 24; -my $a = chr(0x0100); +my $a = chr(0x100); -print ord($a) == 0x100 ? "ok 1\n" : "not ok 1\n"; -print length($a) == 1 ? "ok 2\n" : "not ok 2\n"; +is(ord($a), 0x100, "ord sanity check"); +is(length($a), 1, "length sanity check"); +is(substr($a, 0, 1), "\x{100}", "substr sanity check"); +is(index($a, "\x{100}"), 0, "index sanity check"); +is(rindex($a, "\x{100}"), 0, "rindex sanity check"); +is(bytes::length($a), 2, "bytes::length sanity check"); +is(bytes::chr(0x100), chr(0), "bytes::chr sanity check"); { use bytes; - my $b = chr(0x0100); - print ord($b) == 0 ? "ok 3\n" : "not ok 3\n"; + my $b = chr(0x100); # affected by 'use bytes' + is(ord($b), 0, "chr truncates under use bytes"); + is(length($b), 1, "length truncated under use bytes"); + is(bytes::ord($b), 0, "bytes::ord truncated under use bytes"); + is(bytes::length($b), 1, "bytes::length truncated under use bytes"); + is(bytes::substr($b, 0, 1), "\0", "bytes::substr truncated under use bytes"); } -my $c = chr(0x0100); - -print ord($c) == 0x100 ? "ok 4\n" : "not ok 4\n"; +my $c = chr(0x100); +my $c2 = chr(0x2c7); # a unicode character that doesn't fold +utf8::encode(my $c2_utf8 = $c2); { use bytes; - print ord($c) == 0xc4 ? "ok 5\n" : "not ok 5\n"; - print length($c) == 2 ? "ok 6\n" : "not ok 6\n"; + if ($::IS_EBCDIC) { # EBCDIC? + is(ord($c), 0x8c, "ord under use bytes looks at the 1st byte"); + } else { + is(ord($c), 0xc4, "ord under use bytes looks at the 1st byte"); + } + is(length($c), 2, "length under use bytes looks at bytes"); + is(bytes::length($c), 2, "bytes::length under use bytes looks at bytes"); + if ($::IS_EBCDIC) { # EBCDIC? + is(bytes::ord($c), 0x8c, "bytes::ord under use bytes looks at the 1st byte"); + } else { + is(bytes::ord($c), 0xc4, "bytes::ord under use bytes looks at the 1st byte"); + } + # In z/OS \x41,\x8c are the codepoints corresponding to \x80,\xc4 respectively under ASCII platform + if ($::IS_EBCDIC) { # EBCDIC? + is(bytes::substr($c, 0, 1), "\x8c", "bytes::substr under use bytes looks at bytes"); + is(bytes::index($c, "\x41"), 1, "bytes::index under use bytes looks at bytes"); + is(bytes::rindex($c, "\x8c"), 0, "bytes::rindex under use bytes looks at bytes"); + + } + else{ + is(bytes::substr($c, 0, 1), "\xc4", "bytes::substr under use bytes looks at bytes"); + is(bytes::index($c, "\x80"), 1, "bytes::index under use bytes looks at bytes"); + is(bytes::rindex($c, "\xc4"), 0, "bytes::rindex under use bytes looks at bytes"); + } + + # [perl #117355] [lu]cfirst don't respect 'use bytes' + # and if there's other tests for lc/uc under bytes I didn't find them + is(lc($c2), $c2_utf8, "lc under use bytes returns bytes"); + is(uc($c2), $c2_utf8, "uc under use bytes returns bytes"); + is(lcfirst($c2), $c2_utf8, "lcfirst under use bytes returns bytes"); + is(ucfirst($c2), $c2_utf8, "unfirst under use bytes returns bytes"); } +{ + fresh_perl_like ('use bytes; bytes::moo()', + qr/Undefined subroutine bytes::moo/, {stderr=>1}, + "Check Carp is loaded for AUTOLOADing errors") +}