summaryrefslogtreecommitdiff
path: root/lib/bytes.t
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2003-09-03 08:22:48 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2003-09-03 08:22:48 +0000
commit579f6b362c1dba5aba4049a91c9b6ef08e1b2c6d (patch)
tree6cdd8413b00066268f4f1bc998afc8bb016e0a6f /lib/bytes.t
parent02f28d4422c060b571af1683cfd1890a475f4e8f (diff)
downloadperl-579f6b362c1dba5aba4049a91c9b6ef08e1b2c6d.tar.gz
Add, document, and test bytes::substr, index, rindex, chr,
document bytes::ord. p4raw-id: //depot/perl@21016
Diffstat (limited to 'lib/bytes.t')
-rw-r--r--lib/bytes.t16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/bytes.t b/lib/bytes.t
index 28043caa1d..6b66a554b2 100644
--- a/lib/bytes.t
+++ b/lib/bytes.t
@@ -4,20 +4,26 @@ BEGIN {
require './test.pl';
}
-plan tests => 9;
+plan tests => 19;
my $a = chr(0x100);
is(ord($a), 0x100, "ord sanity check");
is(length($a), 1, "length sanity check");
+is(substr($a, 0, 1), "\x{100}", "substr sanity check");
+is(index($a, "\x{100}"), 0, "index sanity check");
+is(rindex($a, "\x{100}"), 0, "rindex sanity check");
is(bytes::length($a), 2, "bytes::length sanity check");
+is(bytes::chr(0x100), chr(0), "bytes::chr sanity check");
{
use bytes;
my $b = chr(0x100); # affected by 'use bytes'
is(ord($b), 0, "chr truncates under use bytes");
is(length($b), 1, "length truncated under use bytes");
+ is(bytes::ord($b), 0, "bytes::ord truncated under use bytes");
is(bytes::length($b), 1, "bytes::length truncated under use bytes");
+ is(bytes::substr($b, 0, 1), "\0", "bytes::substr truncated under use bytes");
}
my $c = chr(0x100);
@@ -31,4 +37,12 @@ my $c = chr(0x100);
}
is(length($c), 2, "length under use bytes looks at bytes");
is(bytes::length($c), 2, "bytes::length under use bytes looks at bytes");
+ if (ord('A') == 193) { # EBCDIC?
+ is(bytes::ord($c), 0x8c, "bytes::ord under use bytes looks at the 1st byte");
+ } else {
+ is(bytes::ord($c), 0xc4, "bytes::ord under use bytes looks at the 1st byte");
+ }
+ is(bytes::substr($c, 0, 1), "\xc4", "bytes::substr under use bytes looks at bytes");
+ is(bytes::index($c, "\x80"), 1, "bytes::index under use bytes looks at bytes");
+ is(bytes::rindex($c, "\xc4"), 0, "bytes::rindex under use bytes looks at bytes");
}