1#!perl 2 3use strict; 4use warnings; 5 6BEGIN { 7 chdir 't' if -d 't'; 8 @INC = '../lib'; 9 require './test.pl'; 10} 11 12plan tests => 29; 13 14my $a = chr(0x100); 15 16is(ord($a), 0x100, "ord sanity check"); 17is(length($a), 1, "length sanity check"); 18is(substr($a, 0, 1), "\x{100}", "substr sanity check"); 19is(index($a, "\x{100}"), 0, "index sanity check"); 20is(rindex($a, "\x{100}"), 0, "rindex sanity check"); 21{ 22 no warnings 'prototype'; # bytes::length() called too early to check prototype at... 23 is(bytes::length($a), 2, "bytes::length sanity check"); 24 is(bytes::chr(0x100), chr(0), "bytes::chr sanity check"); 25} 26 27{ 28 use bytes; 29 my $b = chr(0x100); # affected by 'use bytes' 30 is(ord($b), 0, "chr truncates under use bytes"); 31 is(length($b), 1, "length truncated under use bytes"); 32 is(bytes::ord($b), 0, "bytes::ord truncated under use bytes"); 33 is(bytes::length($b), 1, "bytes::length truncated under use bytes"); 34 is(bytes::substr($b, 0, 1), "\0", "bytes::substr truncated under use bytes"); 35} 36 37my $c = chr(0x100); 38my $c2 = chr(0x2c7); # a unicode character that doesn't fold 39utf8::encode(my $c2_utf8 = $c2); 40 41{ 42 use bytes; 43 if ($::IS_EBCDIC) { # EBCDIC? 44 is(ord($c), 0x8c, "ord under use bytes looks at the 1st byte"); 45 } else { 46 is(ord($c), 0xc4, "ord under use bytes looks at the 1st byte"); 47 } 48 is(length($c), 2, "length under use bytes looks at bytes"); 49 is(bytes::length($c), 2, "bytes::length under use bytes looks at bytes"); 50 if ($::IS_EBCDIC) { # EBCDIC? 51 is(bytes::ord($c), 0x8c, "bytes::ord under use bytes looks at the 1st byte"); 52 } else { 53 is(bytes::ord($c), 0xc4, "bytes::ord under use bytes looks at the 1st byte"); 54 } 55 # In z/OS \x41,\x8c are the codepoints corresponding to \x80,\xc4 respectively under ASCII platform 56 if ($::IS_EBCDIC) { # EBCDIC? 57 is(bytes::substr($c, 0, 1), "\x8c", "bytes::substr under use bytes looks at bytes"); 58 is(bytes::index($c, "\x41"), 1, "bytes::index under use bytes looks at bytes"); 59 is(bytes::rindex($c, "\x8c"), 0, "bytes::rindex under use bytes looks at bytes"); 60 61 } 62 else{ 63 is(bytes::substr($c, 0, 1), "\xc4", "bytes::substr under use bytes looks at bytes"); 64 is(bytes::index($c, "\x80"), 1, "bytes::index under use bytes looks at bytes"); 65 is(bytes::rindex($c, "\xc4"), 0, "bytes::rindex under use bytes looks at bytes"); 66 } 67 68 # [perl #117355] [lu]cfirst don't respect 'use bytes' 69 # and if there's other tests for lc/uc under bytes I didn't find them 70 is(lc($c2), $c2_utf8, "lc under use bytes returns bytes"); 71 is(uc($c2), $c2_utf8, "uc under use bytes returns bytes"); 72 is(lcfirst($c2), $c2_utf8, "lcfirst under use bytes returns bytes"); 73 is(ucfirst($c2), $c2_utf8, "unfirst under use bytes returns bytes"); 74} 75 76is(prototype bytes->can($_), prototype CORE->can($_), "bytes::$_ proto matches CORE::$_") 77 for qw( chr index length ord rindex substr ); 78