This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Keep Intel C++ from claiming that it is gcc.
[perl5.git] / lib / bytes.t
CommitLineData
4e002eb0
JH
1BEGIN {
2 chdir 't' if -d 't';
3 @INC = '../lib';
1ae0ae17 4 require './test.pl';
4e002eb0
JH
5}
6
5b5a256a 7plan tests => 20;
4e002eb0 8
1ae0ae17 9my $a = chr(0x100);
4e002eb0 10
1ae0ae17
JH
11is(ord($a), 0x100, "ord sanity check");
12is(length($a), 1, "length sanity check");
579f6b36
JH
13is(substr($a, 0, 1), "\x{100}", "substr sanity check");
14is(index($a, "\x{100}"), 0, "index sanity check");
15is(rindex($a, "\x{100}"), 0, "rindex sanity check");
1ae0ae17 16is(bytes::length($a), 2, "bytes::length sanity check");
579f6b36 17is(bytes::chr(0x100), chr(0), "bytes::chr sanity check");
4e002eb0
JH
18
19{
20 use bytes;
1ae0ae17
JH
21 my $b = chr(0x100); # affected by 'use bytes'
22 is(ord($b), 0, "chr truncates under use bytes");
23 is(length($b), 1, "length truncated under use bytes");
579f6b36 24 is(bytes::ord($b), 0, "bytes::ord truncated under use bytes");
1ae0ae17 25 is(bytes::length($b), 1, "bytes::length truncated under use bytes");
579f6b36 26 is(bytes::substr($b, 0, 1), "\0", "bytes::substr truncated under use bytes");
4e002eb0
JH
27}
28
1ae0ae17 29my $c = chr(0x100);
4e002eb0
JH
30
31{
32 use bytes;
1ae0ae17
JH
33 if (ord('A') == 193) { # EBCDIC?
34 is(ord($c), 0x8c, "ord under use bytes looks at the 1st byte");
0ef00eb6 35 } else {
1ae0ae17 36 is(ord($c), 0xc4, "ord under use bytes looks at the 1st byte");
0ef00eb6 37 }
1ae0ae17
JH
38 is(length($c), 2, "length under use bytes looks at bytes");
39 is(bytes::length($c), 2, "bytes::length under use bytes looks at bytes");
579f6b36
JH
40 if (ord('A') == 193) { # EBCDIC?
41 is(bytes::ord($c), 0x8c, "bytes::ord under use bytes looks at the 1st byte");
42 } else {
43 is(bytes::ord($c), 0xc4, "bytes::ord under use bytes looks at the 1st byte");
44 }
45 is(bytes::substr($c, 0, 1), "\xc4", "bytes::substr under use bytes looks at bytes");
46 is(bytes::index($c, "\x80"), 1, "bytes::index under use bytes looks at bytes");
47 is(bytes::rindex($c, "\xc4"), 0, "bytes::rindex under use bytes looks at bytes");
4e002eb0 48}
5b5a256a
ST
49
50{
51 fresh_perl_like ('use bytes; bytes::moo()',
52 qr/Undefined subroutine bytes::moo/, {stderr=>1},
53 "Check Carp is loaded for AUTOLOADing errors")
54}