X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Fbytes.t;h=ea1b9f629b92c902e2ead43b8475666d193e2b66;hb=34ba6322b644154d55680c95808981776852ae24;hp=28043caa1d43e9f06f899561d32386d5c16cf910;hpb=1ae0ae1779f56be3f5008214f23d0e0a7f3dce42;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/bytes.t b/lib/bytes.t index 28043ca..ea1b9f6 100644 --- a/lib/bytes.t +++ b/lib/bytes.t @@ -4,20 +4,26 @@ BEGIN { require './test.pl'; } -plan tests => 9; +plan tests => 20; my $a = chr(0x100); 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(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(0x100); @@ -31,4 +37,18 @@ my $c = chr(0x100); } 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 (ord('A') == 193) { # 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"); + } + 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"); +} + +{ + fresh_perl_like ('use bytes; bytes::moo()', + qr/Undefined subroutine bytes::moo/, {stderr=>1}, + "Check Carp is loaded for AUTOLOADing errors") }