This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
test.pl-ify and add a couple of tests.
[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
1ae0ae17 7plan tests => 9;
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");
13is(bytes::length($a), 2, "bytes::length sanity check");
4e002eb0
JH
14
15{
16 use bytes;
1ae0ae17
JH
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");
4e002eb0
JH
21}
22
1ae0ae17 23my $c = chr(0x100);
4e002eb0
JH
24
25{
26 use bytes;
1ae0ae17
JH
27 if (ord('A') == 193) { # EBCDIC?
28 is(ord($c), 0x8c, "ord under use bytes looks at the 1st byte");
0ef00eb6 29 } else {
1ae0ae17 30 is(ord($c), 0xc4, "ord under use bytes looks at the 1st byte");
0ef00eb6 31 }
1ae0ae17
JH
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");
4e002eb0 34}