This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate:
[perl5.git] / lib / bytes.t
1 BEGIN {
2     chdir 't' if -d 't';
3     @INC = '../lib';
4     require './test.pl';
5 }
6
7 plan tests => 9;
8
9 my $a = chr(0x100);
10
11 is(ord($a), 0x100, "ord sanity check");
12 is(length($a), 1,  "length sanity check");
13 is(bytes::length($a), 2,  "bytes::length sanity check");
14
15 {
16     use bytes;
17     my $b = chr(0x100); # affected by 'use bytes'
18     is(ord($b), 0, "chr truncates under use bytes");
19     is(length($b), 1, "length truncated under use bytes");
20     is(bytes::length($b), 1, "bytes::length truncated under use bytes");
21 }
22
23 my $c = chr(0x100);
24
25 {
26     use bytes;
27     if (ord('A') == 193) { # EBCDIC?
28         is(ord($c), 0x8c, "ord under use bytes looks at the 1st byte");
29     } else {
30         is(ord($c), 0xc4, "ord under use bytes looks at the 1st byte");
31     }
32     is(length($c), 2, "length under use bytes looks at bytes");
33     is(bytes::length($c), 2, "bytes::length under use bytes looks at bytes");
34 }