xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/bytes.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gateBEGIN {
2*0Sstevel@tonic-gate    chdir 't' if -d 't';
3*0Sstevel@tonic-gate    @INC = '../lib';
4*0Sstevel@tonic-gate    require './test.pl';
5*0Sstevel@tonic-gate}
6*0Sstevel@tonic-gate
7*0Sstevel@tonic-gateplan tests => 19;
8*0Sstevel@tonic-gate
9*0Sstevel@tonic-gatemy $a = chr(0x100);
10*0Sstevel@tonic-gate
11*0Sstevel@tonic-gateis(ord($a), 0x100, "ord sanity check");
12*0Sstevel@tonic-gateis(length($a), 1,  "length sanity check");
13*0Sstevel@tonic-gateis(substr($a, 0, 1), "\x{100}",  "substr sanity check");
14*0Sstevel@tonic-gateis(index($a, "\x{100}"),  0, "index sanity check");
15*0Sstevel@tonic-gateis(rindex($a, "\x{100}"), 0, "rindex sanity check");
16*0Sstevel@tonic-gateis(bytes::length($a), 2,  "bytes::length sanity check");
17*0Sstevel@tonic-gateis(bytes::chr(0x100), chr(0),  "bytes::chr sanity check");
18*0Sstevel@tonic-gate
19*0Sstevel@tonic-gate{
20*0Sstevel@tonic-gate    use bytes;
21*0Sstevel@tonic-gate    my $b = chr(0x100); # affected by 'use bytes'
22*0Sstevel@tonic-gate    is(ord($b), 0, "chr truncates under use bytes");
23*0Sstevel@tonic-gate    is(length($b), 1, "length truncated under use bytes");
24*0Sstevel@tonic-gate    is(bytes::ord($b), 0, "bytes::ord truncated under use bytes");
25*0Sstevel@tonic-gate    is(bytes::length($b), 1, "bytes::length truncated under use bytes");
26*0Sstevel@tonic-gate    is(bytes::substr($b, 0, 1), "\0", "bytes::substr truncated under use bytes");
27*0Sstevel@tonic-gate}
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gatemy $c = chr(0x100);
30*0Sstevel@tonic-gate
31*0Sstevel@tonic-gate{
32*0Sstevel@tonic-gate    use bytes;
33*0Sstevel@tonic-gate    if (ord('A') == 193) { # EBCDIC?
34*0Sstevel@tonic-gate	is(ord($c), 0x8c, "ord under use bytes looks at the 1st byte");
35*0Sstevel@tonic-gate    } else {
36*0Sstevel@tonic-gate	is(ord($c), 0xc4, "ord under use bytes looks at the 1st byte");
37*0Sstevel@tonic-gate    }
38*0Sstevel@tonic-gate    is(length($c), 2, "length under use bytes looks at bytes");
39*0Sstevel@tonic-gate    is(bytes::length($c), 2, "bytes::length under use bytes looks at bytes");
40*0Sstevel@tonic-gate    if (ord('A') == 193) { # EBCDIC?
41*0Sstevel@tonic-gate	is(bytes::ord($c), 0x8c, "bytes::ord under use bytes looks at the 1st byte");
42*0Sstevel@tonic-gate    } else {
43*0Sstevel@tonic-gate	is(bytes::ord($c), 0xc4, "bytes::ord under use bytes looks at the 1st byte");
44*0Sstevel@tonic-gate    }
45*0Sstevel@tonic-gate    is(bytes::substr($c, 0, 1), "\xc4", "bytes::substr under use bytes looks at bytes");
46*0Sstevel@tonic-gate    is(bytes::index($c, "\x80"), 1, "bytes::index under use bytes looks at bytes");
47*0Sstevel@tonic-gate    is(bytes::rindex($c, "\xc4"), 0, "bytes::rindex under use bytes looks at bytes");
48*0Sstevel@tonic-gate}
49