diff options
author | Ton Hospel <perl5-porters@ton.iguana.be> | 2005-03-19 22:00:45 +0000 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2005-03-21 10:27:44 +0000 |
commit | 246f24af48839a0c276d6836d932a864d54afe73 (patch) | |
tree | 720117a6bd27a8543d8bf6424de90c20f7f758fb /t | |
parent | f1aa04aa98e25c473fc39871251cb722556cefa9 (diff) | |
download | perl-246f24af48839a0c276d6836d932a864d54afe73.tar.gz |
pack / for general types
Message-Id: <d1i7ed$62c$1@post.home.lunix>
Allow "len/format" to work for any format type, not just strings.
p4raw-id: //depot/perl@24052
Diffstat (limited to 't')
-rwxr-xr-x | t/op/pack.t | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/t/op/pack.t b/t/op/pack.t index 06c3a9a475..3009510a13 100755 --- a/t/op/pack.t +++ b/t/op/pack.t @@ -12,7 +12,7 @@ my $no_endianness = $] > 5.009 ? '' : my $no_signedness = $] > 5.009 ? '' : "Signed/unsigned pack modifiers not available on this perl"; -plan tests => 14606; +plan tests => 14621; use strict; use warnings; @@ -1782,3 +1782,28 @@ is(unpack('c'), 65, "one-arg unpack (change #18751)"); # defaulting to $_ is(pack("U0A*", $high), "\xfeb"); is(pack("U0Z*", $high), "\xfeb\x00"); } +{ + # pack / + my @array = 1..14; + my @out = unpack("N/S", pack("N/S", @array) . "abcd"); + is("@out", "@array", "pack N/S works"); + @out = unpack("N/S*", pack("N/S*", @array) . "abcd"); + is("@out", "@array", "pack N/S* works"); + @out = unpack("N/S*", pack("N/S14", @array) . "abcd"); + is("@out", "@array", "pack N/S14 works"); + @out = unpack("N/S*", pack("N/S15", @array) . "abcd"); + is("@out", "@array", "pack N/S15 works"); + @out = unpack("N/S*", pack("N/S13", @array) . "abcd"); + is("@out", "@array[0..12]", "pack N/S13 works"); + @out = unpack("N/S*", pack("N/S0", @array) . "abcd"); + is("@out", "", "pack N/S0 works"); + is(pack("Z*/a0", "abc"), "0\0", "pack Z*/a0 makes a short string"); + is(pack("Z*/Z0", "abc"), "0\0", "pack Z*/Z0 makes a short string"); + is(pack("Z*/a3", "abc"), "3\0abc", "pack Z*/a3 makes a full string"); + is(pack("Z*/Z3", "abc"), "3\0ab\0", "pack Z*/Z3 makes a short string"); + is(pack("Z*/a5", "abc"), "5\0abc\0\0", "pack Z*/a5 makes a long string"); + is(pack("Z*/Z5", "abc"), "5\0abc\0\0", "pack Z*/Z5 makes a long string"); + is(pack("Z*/Z"), "1\0\0", "pack Z*/Z makes an extended string"); + is(pack("Z*/Z", ""), "1\0\0", "pack Z*/Z makes an extended string"); + is(pack("Z*/a", ""), "0\0", "pack Z*/a makes an extended string"); +} |