1N/ABEGIN {
1N/A chdir 't' if -d 't';
1N/A @INC = '../lib';
1N/A require './test.pl';
1N/A}
1N/A
1N/Aplan tests => 19;
1N/A
1N/Amy $a = chr(0x100);
1N/A
1N/Ais(ord($a), 0x100, "ord sanity check");
1N/Ais(length($a), 1, "length sanity check");
1N/Ais(substr($a, 0, 1), "\x{100}", "substr sanity check");
1N/Ais(index($a, "\x{100}"), 0, "index sanity check");
1N/Ais(rindex($a, "\x{100}"), 0, "rindex sanity check");
1N/Ais(bytes::length($a), 2, "bytes::length sanity check");
1N/Ais(bytes::chr(0x100), chr(0), "bytes::chr sanity check");
1N/A
1N/A{
1N/A use bytes;
1N/A my $b = chr(0x100); # affected by 'use bytes'
1N/A is(ord($b), 0, "chr truncates under use bytes");
1N/A is(length($b), 1, "length truncated under use bytes");
1N/A is(bytes::ord($b), 0, "bytes::ord truncated under use bytes");
1N/A is(bytes::length($b), 1, "bytes::length truncated under use bytes");
1N/A is(bytes::substr($b, 0, 1), "\0", "bytes::substr truncated under use bytes");
1N/A}
1N/A
1N/Amy $c = chr(0x100);
1N/A
1N/A{
1N/A use bytes;
1N/A if (ord('A') == 193) { # EBCDIC?
1N/A is(ord($c), 0x8c, "ord under use bytes looks at the 1st byte");
1N/A } else {
1N/A is(ord($c), 0xc4, "ord under use bytes looks at the 1st byte");
1N/A }
1N/A is(length($c), 2, "length under use bytes looks at bytes");
1N/A is(bytes::length($c), 2, "bytes::length under use bytes looks at bytes");
1N/A if (ord('A') == 193) { # EBCDIC?
1N/A is(bytes::ord($c), 0x8c, "bytes::ord under use bytes looks at the 1st byte");
1N/A } else {
1N/A is(bytes::ord($c), 0xc4, "bytes::ord under use bytes looks at the 1st byte");
1N/A }
1N/A is(bytes::substr($c, 0, 1), "\xc4", "bytes::substr under use bytes looks at bytes");
1N/A is(bytes::index($c, "\x80"), 1, "bytes::index under use bytes looks at bytes");
1N/A is(bytes::rindex($c, "\xc4"), 0, "bytes::rindex under use bytes looks at bytes");
1N/A}