This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move a test from t/lib/warnings/sv to .../9uninit
[perl5.git] / lib / bytes.t
1
2 BEGIN {
3     chdir 't' if -d 't';
4     @INC = '../lib';
5     require './test.pl';
6 }
7
8 plan tests => 20;
9
10 my $a = chr(0x100);
11
12 is(ord($a), 0x100, "ord sanity check");
13 is(length($a), 1,  "length sanity check");
14 is(substr($a, 0, 1), "\x{100}",  "substr sanity check");
15 is(index($a, "\x{100}"),  0, "index sanity check");
16 is(rindex($a, "\x{100}"), 0, "rindex sanity check");
17 is(bytes::length($a), 2,  "bytes::length sanity check");
18 is(bytes::chr(0x100), chr(0),  "bytes::chr sanity check");
19
20 {
21     use bytes;
22     my $b = chr(0x100); # affected by 'use bytes'
23     is(ord($b), 0, "chr truncates under use bytes");
24     is(length($b), 1, "length truncated under use bytes");
25     is(bytes::ord($b), 0, "bytes::ord truncated under use bytes");
26     is(bytes::length($b), 1, "bytes::length truncated under use bytes");
27     is(bytes::substr($b, 0, 1), "\0", "bytes::substr truncated under use bytes");
28 }
29
30 my $c = chr(0x100);
31
32 {
33     use bytes;
34     if (ord('A') == 193) { # EBCDIC?
35         is(ord($c), 0x8c, "ord under use bytes looks at the 1st byte");
36     } else {
37         is(ord($c), 0xc4, "ord under use bytes looks at the 1st byte");
38     }
39     is(length($c), 2, "length under use bytes looks at bytes");
40     is(bytes::length($c), 2, "bytes::length under use bytes looks at bytes");
41     if (ord('A') == 193) { # EBCDIC?
42         is(bytes::ord($c), 0x8c, "bytes::ord under use bytes looks at the 1st byte");
43     } else {
44         is(bytes::ord($c), 0xc4, "bytes::ord under use bytes looks at the 1st byte");
45     }
46     # In z/OS \x41,\x8c are the codepoints corresponding to \x80,\xc4 respectively under ASCII platform
47     if (ord('A') == 193) { # EBCDIC?
48         is(bytes::substr($c, 0, 1), "\x8c", "bytes::substr under use bytes looks at bytes");
49         is(bytes::index($c, "\x41"), 1, "bytes::index under use bytes looks at bytes");
50         is(bytes::rindex($c, "\x8c"), 0, "bytes::rindex under use bytes looks at bytes");
51
52     }
53     else{
54         is(bytes::substr($c, 0, 1), "\xc4", "bytes::substr under use bytes looks at bytes");
55         is(bytes::index($c, "\x80"), 1, "bytes::index under use bytes looks at bytes");
56         is(bytes::rindex($c, "\xc4"), 0, "bytes::rindex under use bytes looks at bytes");
57     }
58     
59 }
60
61 {
62     fresh_perl_like ('use bytes; bytes::moo()',
63                      qr/Undefined subroutine bytes::moo/, {stderr=>1},
64                     "Check Carp is loaded for AUTOLOADing errors")
65 }