This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Bump the perl version in various places for 5.37.8
[perl5.git] / lib / bytes.t
CommitLineData
ba6f05db
TR
1#!perl
2
3use strict;
4use warnings;
2f3efc97 5
4e002eb0
JH
6BEGIN {
7 chdir 't' if -d 't';
8 @INC = '../lib';
1ae0ae17 9 require './test.pl';
4e002eb0
JH
10}
11
ac993614 12plan tests => 24;
4e002eb0 13
1ae0ae17 14my $a = chr(0x100);
4e002eb0 15
1ae0ae17
JH
16is(ord($a), 0x100, "ord sanity check");
17is(length($a), 1, "length sanity check");
579f6b36
JH
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");
ba6f05db
TR
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}
4e002eb0
JH
26
27{
28 use bytes;
1ae0ae17
JH
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");
579f6b36 32 is(bytes::ord($b), 0, "bytes::ord truncated under use bytes");
1ae0ae17 33 is(bytes::length($b), 1, "bytes::length truncated under use bytes");
579f6b36 34 is(bytes::substr($b, 0, 1), "\0", "bytes::substr truncated under use bytes");
4e002eb0
JH
35}
36
1ae0ae17 37my $c = chr(0x100);
ac993614
TC
38my $c2 = chr(0x2c7); # a unicode character that doesn't fold
39utf8::encode(my $c2_utf8 = $c2);
4e002eb0
JH
40
41{
42 use bytes;
83bcbc61 43 if ($::IS_EBCDIC) { # EBCDIC?
1ae0ae17 44 is(ord($c), 0x8c, "ord under use bytes looks at the 1st byte");
0ef00eb6 45 } else {
1ae0ae17 46 is(ord($c), 0xc4, "ord under use bytes looks at the 1st byte");
0ef00eb6 47 }
1ae0ae17
JH
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");
83bcbc61 50 if ($::IS_EBCDIC) { # EBCDIC?
579f6b36
JH
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 }
2f3efc97 55 # In z/OS \x41,\x8c are the codepoints corresponding to \x80,\xc4 respectively under ASCII platform
83bcbc61 56 if ($::IS_EBCDIC) { # EBCDIC?
2f3efc97
JH
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
ac993614
TC
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");
ac993614
TC
72 is(lcfirst($c2), $c2_utf8, "lcfirst under use bytes returns bytes");
73 is(ucfirst($c2), $c2_utf8, "unfirst under use bytes returns bytes");
4e002eb0 74}
5b5a256a
TS
75
76{
77 fresh_perl_like ('use bytes; bytes::moo()',
78 qr/Undefined subroutine bytes::moo/, {stderr=>1},
79 "Check Carp is loaded for AUTOLOADing errors")
80}