15 my $Is_EBCDIC = (defined $Config{ebcdic} && $Config{ebcdic} eq 'define');
16 my $Perl = which_perl();
19 my @result = map {_qq($_)} @_;
23 return '(' . join (', ', @result) . ')';
29 return unless @$l == @$r;
31 if (defined $l->[$i]) {
32 return unless defined ($r->[$i]) && $l->[$i] eq $r->[$i];
34 return if defined $r->[$i]
40 ##############################################################################
42 # Here starteth the tests
46 my $format = "c2 x5 C C x s d i l a6";
47 # Need the expression in here to force ary[5] to be numeric. This avoids
48 # test2 failing because ary2 goes str->numeric->str and ary doesn't.
49 my @ary = (1,-100,127,128,32767,987.654321098 / 100.0,12345,123456,
51 my $foo = pack($format,@ary);
52 my @ary2 = unpack($format,$foo);
56 my $out1=join(':',@ary);
57 my $out2=join(':',@ary2);
58 # Using long double NVs may introduce greater accuracy than wanted.
59 $out1 =~ s/:9\.87654321097999\d*:/:9.87654321098:/;
60 $out2 =~ s/:9\.87654321097999\d*:/:9.87654321098:/;
65 # How about counting bits?
69 is( ($x = unpack("%32B*", "\001\002\004\010\020\040\100\200\377")), 16 );
71 is( ($x = unpack("%32b69", "\001\002\004\010\020\040\100\200\017")), 12 );
73 is( ($x = unpack("%32B69", "\001\002\004\010\020\040\100\200\017")), 9 );
77 my $sum = 129; # ASCII
78 $sum = 103 if $Is_EBCDIC;
81 is( ($x = unpack("%32B*", "Now is the time for all good blurfl")), $sum );
84 open(BIN, $Perl) || die "Can't open $Perl: $!\n";
85 sysread BIN, $foo, 8192;
88 $sum = unpack("%32b*", $foo);
89 my $longway = unpack("b*", $foo);
90 is( $sum, $longway =~ tr/1/1/ );
95 is( ($x = unpack("I",pack("I", 0xFFFFFFFF))), 0xFFFFFFFF );
100 my @x = (5,130,256,560,32000,3097152,268435455,1073741844, 2**33,
101 '4503599627365785','23728385234614992549757750638446');
102 my $x = pack('w*', @x);
103 my $y = pack 'H*', '0581028200843081fa0081bd8440ffffff7f8480808014A0808'.
104 '0800087ffffffffffdb19caefe8e1eeeea0c2e1e3e8ede1ee6e';
108 my @y = unpack('w*', $y);
110 while ($a = pop @x) {
115 @y = unpack('w2', $x);
119 $x = pack('w*', 5000000000); $y = '';
122 $y = pack('w*', Math::BigInt::->new(5000000000));
131 eval { $x = unpack 'w', pack 'C*', 0xff, 0xff};
132 like($@, qr/^Unterminated compressed integer/);
134 eval { $x = unpack 'w', pack 'C*', 0xff, 0xff, 0xff, 0xff};
135 like($@, qr/^Unterminated compressed integer/);
137 eval { $x = unpack 'w', pack 'C*', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
138 like($@, qr/^Unterminated compressed integer/);
142 # test the "p" template
145 is(unpack("p",pack("p","foo")), "foo");
148 is(unpack("p",pack("p",239)), 239);
151 sub foo { my $a = "a"; return $a . $a++ . $a++ }
155 local $SIG{__WARN__} = sub {
158 my $junk = pack("p", &foo);
160 like($warning, qr/temporary val/);
163 # undef should give null pointer
164 like(pack("p", undef), qr/^\0+/);
166 # Check for optimizer bug (e.g. Digital Unix GEM cc with -O4 on DU V4.0B gives
167 # 4294967295 instead of -1)
168 # see #ifdef __osf__ in pp.c pp_unpack
169 is((unpack("i",pack("i",-1))), -1);
171 # test the pack lengths of s S i I l L
172 # test the pack lengths of n N v V
173 my @lengths = qw(s 2 S 2 i -4 I -4 l 4 L 4 n 2 N 4 v 2 V 4);
174 while (my ($format, $expect) = splice @lengths, 0, 2) {
175 my $len = length(pack($format, 0));
177 is($expect, $len, "format '$format'");
180 ok ($len >= $expect, "format '$format'") ||
181 print "# format '$format' has length $len, expected >= $expect\n";
186 # test unpack-pack lengths
187 my @templates = qw(c C i I s S l L n N v V f d q Q);
189 foreach my $t (@templates) {
191 my @t = eval { unpack("$t*", pack("$t*", 12, 34)) };
193 # quads not supported everywhere
194 skip "Quads not supported", 4 if $@ =~ /Invalid type in pack/;
200 skip "$t not expected to work for some reason", 2 if $t =~ /[nv]/i;
211 # Note that first uuencoding known 'text' data and then checking the
212 # binary values of the uuencoded version would not be portable between
213 # character sets. Uuencoding is meant for encoding binary data, not
216 my $in = pack 'C*', 0 .. 255;
218 # just to be anal, we do some random tr/`/ /
220 M` $"`P0%!@<("0H+# T.#Q`1$A,4%187&!D:&QP='A\@(2(C)"4F)R@I*BLL
221 M+2XO,#$R,S0U-C<X.3H[/#T^/T!!0D-$149'2$E*2TQ-3D]045)35%565UA9
222 M6EM<75Y?8&%B8V1E9F=H:6IK;&UN;W!Q<G-T=79W>'EZ>WQ]?G^`@8*#A(6&
223 MAXB)BHN,C8Z/D)&2DY25EI>8F9J;G)V>GZ"AHJ.DI::GJ*FJJZRMKJ^PL;*S
224 MM+6VM[BYNKN\O;Z_P,'"P\3%QL?(R<K+S,W.S]#1TM/4U=;7V-G:V]S=WM_@
225 ?X>+CY.7FY^CIZNOL[>[O\/'R\_3U]O?X^?K[_/W^_P `
231 is(pack('u', $in), $_);
233 is(unpack('u', $uu), $in);
235 $in = "\x1f\x8b\x08\x08\x58\xdc\xc4\x35\x02\x03\x4a\x41\x50\x55\x00\xf3\x2a\x2d\x2e\x51\x48\xcc\xcb\x2f\xc9\x48\x2d\x52\x08\x48\x2d\xca\x51\x28\x2d\x4d\xce\x4f\x49\x2d\xe2\x02\x00\x64\x66\x60\x5c\x1a\x00\x00\x00";
237 M'XL("%C<Q#4"`TI!4%4`\RHM+E%(S,LOR4@M4@A(+<I1*"U-SD])+>("`&1F
241 is(unpack('u', $uu), $in);
243 # This is identical to the above except that backquotes have been
247 M'XL("%C<Q#4" TI!4%4 \RHM+E%(S,LOR4@M4@A(+<I1*"U-SD])+>(" &1F
252 is(unpack('u', $uu), $in);
256 # test the ascii template types (A, a, Z)
259 ['p', 'A*', "foo\0bar\0 ", "foo\0bar\0 "],
260 ['p', 'A11', "foo\0bar\0 ", "foo\0bar\0 "],
261 ['u', 'A*', "foo\0bar \0", "foo\0bar"],
262 ['u', 'A8', "foo\0bar \0", "foo\0bar"],
263 ['p', 'a*', "foo\0bar\0 ", "foo\0bar\0 "],
264 ['p', 'a11', "foo\0bar\0 ", "foo\0bar\0 \0\0"],
265 ['u', 'a*', "foo\0bar \0", "foo\0bar \0"],
266 ['u', 'a8', "foo\0bar \0", "foo\0bar "],
267 ['p', 'Z*', "foo\0bar\0 ", "foo\0bar\0 \0"],
268 ['p', 'Z11', "foo\0bar\0 ", "foo\0bar\0 \0\0"],
269 ['p', 'Z3', "foo", "fo\0"],
270 ['u', 'Z*', "foo\0bar \0", "foo"],
271 ['u', 'Z8', "foo\0bar \0", "foo"],
274 my ($what, $template, $in, $out) = @$_;
275 my $got = $what eq 'u' ? (unpack $template, $in) : (pack $template, $in);
276 unless (is($got, $out)) {
277 my $un = $what eq 'u' ? 'un' : '';
278 print "# ${un}pack ('$template', "._qq($in).') gave '._qq($out).
279 ' not '._qq($got)."\n";
283 # packing native shorts/ints/longs
285 is(length(pack("s!", 0)), $Config{shortsize});
286 is(length(pack("i!", 0)), $Config{intsize});
287 is(length(pack("l!", 0)), $Config{longsize});
288 ok(length(pack("s!", 0)) <= length(pack("i!", 0)));
289 ok(length(pack("i!", 0)) <= length(pack("l!", 0)));
290 is(length(pack("i!", 0)), length(pack("i", 0)));
294 return numbers_with_total ($format, undef, @_);
297 sub numbers_with_total {
300 if (!defined $total) {
307 my $out = eval {unpack($format, pack($format, $_))};
308 skip "cannot pack '$format' on this perl", 2 if
309 $@ =~ /Invalid type in pack: '$format'/;
316 my $skip_if_longer_than = ~0; # "Infinity"
318 # If we're running with -DNO_PERLPRESERVE_IVUV and NVs don't preserve all
319 # UVs (in which case ~0 is NV, ~0-1 will be the same NV) then we can't
320 # correctly in perl calculate UV totals for long checksums, as pp_unpack
321 # is using UV maths, and we've only got NVs.
322 $skip_if_longer_than = $Config{d_nv_preserves_uv_bits};
325 foreach ('', 1, 2, 3, 15, 16, 17, 31, 32, 33, 53, 54, 63, 64, 65) {
327 my $sum = eval {unpack "%$_$format*", pack "$format*", @_};
328 skip "cannot pack '$format' on this perl", 3
329 if $@ =~ /Invalid type in pack: '$format'/;
334 my $len = $_; # Copy, so that we can reassign ''
335 $len = 16 unless length $len;
338 skip "cannot test checksums over $skip_if_longer_than bits", 1
339 if $len > $skip_if_longer_than;
341 # Our problem with testing this portably is that the checksum code in
342 # pp_unpack is able to cast signed to unsigned, and do modulo 2**n
343 # arithmetic in unsigned ints, which perl has no operators to do.
344 # (use integer; does signed ints, which won't wrap on UTS, which is just
345 # fine with ANSI, but not with most people's assumptions.
346 # This is why we need to supply the totals for 'Q' as there's no way in
347 # perl to calculate them, short of unpack '%0Q' (is that documented?)
348 # ** returns NVs; make sure it's IV.
349 my $max = 1 + 2 * (int (2 ** ($len-1))-1); # The max possible checksum
350 my $max_p1 = $max + 1;
351 my ($max_is_integer, $max_p1_is_integer);
352 $max_p1_is_integer = 1 unless $max_p1 + 1 == $max_p1;
353 $max_is_integer = 1 if $max - 1 < ~0;
357 $calc_sum = &$total($len);
360 # Shift into range by some multiple of the total
361 my $mult = int ($total / $max_p1);
362 # Need this to make sure that -1 + (~0+1) is ~0 (ie still integer)
363 $calc_sum = $total - $mult;
364 $calc_sum -= $mult * $max;
370 if ($calc_sum == $calc_sum - 1 && $calc_sum == $max_p1) {
371 # we're into floating point (either by getting out of the range of
372 # UV arithmetic, or because we're doing a floating point checksum)
373 # and our calculation of the checksum has become rounded up to
378 if ($calc_sum == $sum) { # HAS to be ==, not eq (so no is()).
379 ok ("unpack '%$_$format' gave $sum");
381 my $delta = 1.000001;
382 if ($format =~ tr /dDfF//
383 && ($calc_sum <= $sum * $delta && $calc_sum >= $sum / $delta)) {
384 pass ("unpack '%$_$format' gave $sum, expected $calc_sum");
386 my $text = ref $total ? &$total($len) : $total;
388 print "# For list (" . join (", ", @_) . ") (total $text)"
389 . " packed with $format unpack '%$_$format' gave $sum,"
390 . " expected $calc_sum\n";
398 numbers ('c', -128, -1, 0, 1, 127);
399 numbers ('C', 0, 1, 127, 128, 255);
400 numbers ('s', -32768, -1, 0, 1, 32767);
401 numbers ('S', 0, 1, 32767, 32768, 65535);
402 numbers ('i', -2147483648, -1, 0, 1, 2147483647);
403 numbers ('I', 0, 1, 2147483647, 2147483648, 4294967295);
404 numbers ('l', -2147483648, -1, 0, 1, 2147483647);
405 numbers ('L', 0, 1, 2147483647, 2147483648, 4294967295);
406 numbers ('s!', -32768, -1, 0, 1, 32767);
407 numbers ('S!', 0, 1, 32767, 32768, 65535);
408 numbers ('i!', -2147483648, -1, 0, 1, 2147483647);
409 numbers ('I!', 0, 1, 2147483647, 2147483648, 4294967295);
410 numbers ('l!', -2147483648, -1, 0, 1, 2147483647);
411 numbers ('L!', 0, 1, 2147483647, 2147483648, 4294967295);
412 numbers ('n', 0, 1, 32767, 32768, 65535);
413 numbers ('v', 0, 1, 32767, 32768, 65535);
414 numbers ('N', 0, 1, 2147483647, 2147483648, 4294967295);
415 numbers ('V', 0, 1, 2147483647, 2147483648, 4294967295);
416 # All these should have exact binary representations:
417 numbers ('f', -1, 0, 0.5, 42, 2**34);
418 numbers ('d', -(2**34), -1, 0, 1, 2**34);
419 ## These don't, but 'd' is NV. XXX wrong, it's double
420 #numbers ('d', -1, 0, 1, 1-exp(-1), -exp(1));
422 numbers_with_total ('q', -1,
423 -9223372036854775808, -1, 0, 1,9223372036854775807);
424 # This total is icky, but the true total is 2**65-1, and need a way to generate
425 # the epxected checksum on any system including those where NVs can preserve
426 # 65 bits. (long double is 128 bits on sparc, so they certainly can)
427 # or where rounding is down not up on binary conversion (crays)
428 numbers_with_total ('Q', sub {
430 $len = 65 if $len > 65; # unmasked total is 2**65-1 here
431 my $total = 1 + 2 * (int (2**($len - 1)) - 1);
432 return 0 if $total == $total - 1; # Overflowed integers
433 return $total; # NVs still accurate to nearest integer
435 0, 1,9223372036854775807, 9223372036854775808,
436 18446744073709551615);
438 # pack nvNV byteorders
440 is(pack("n", 0xdead), "\xde\xad");
441 is(pack("v", 0xdead), "\xad\xde");
442 is(pack("N", 0xdeadbeef), "\xde\xad\xbe\xef");
443 is(pack("V", 0xdeadbeef), "\xef\xbe\xad\xde");
449 eval { ($x) = unpack '/a*','hello' };
450 like($@, qr!/ must follow a numeric type!);
452 eval { $x = unpack '/a*','hello' };
453 like($@, qr!/ must follow a numeric type!);
456 eval { ($z,$x,$y) = unpack 'a3/A C/a* C/Z', "003ok \003yes\004z\000abc" };
462 eval { $z = unpack 'a3/A C/a* C/Z', "003ok \003yes\004z\000abc" };
468 eval { ($x) = pack '/a*','hello' };
469 like($@, qr!Invalid type in pack: '/'!);
471 eval { $x = pack '/a*','hello' };
472 like($@, qr!Invalid type in pack: '/'!);
474 $z = pack 'n/a* N/Z* w/A*','string','hi there ','etc';
475 my $expect = "\000\006string\0\0\0\012hi there \000\003etc";
479 $expect = 'hello world';
480 eval { ($x) = unpack ("w/a", chr (11) . "hello world!")};
485 # Doing this in scalar context used to fail.
486 eval { $x = unpack ("w/a", chr (11) . "hello world!")};
491 ['a/a*/a*', '212ab345678901234567','ab3456789012'],
492 ['a/a*/a*', '3012ab345678901234567', 'ab3456789012'],
493 ['a/a*/b*', '212ab', $Is_EBCDIC ? '100000010100' : '100001100100'],
496 my ($pat, $in, $expect) = @$_;
498 eval { ($x) = unpack $pat, $in };
501 printf "# list unpack ('$pat', '$in') gave %s, expected '$expect'\n",
505 eval { $x = unpack $pat, $in };
508 printf "# scalar unpack ('$pat', '$in') gave %s, expected '$expect'\n",
514 my $pattern = <<'EOU';
515 a3/A # Count in ASCII
516 C/a* # Count in a C char
517 C/Z # Count in a C char but skip after \0
521 eval { ($z,$x,$y) = unpack $pattern, "003ok \003yes\004z\000abc" };
527 eval { $z = unpack $pattern, "003ok \003yes\004z\000abc" };
532 n/a* # Count as network short
533 w/A* # Count a BER integer
535 $expect = "\000\006string\003etc";
536 $z = pack $pattern,'string','etc';
542 skip("(EBCDIC and) version strings are bad idea", 2) if $Is_EBCDIC;
544 is("1.20.300.4000", sprintf "%vd", pack("U*",1,20,300,4000));
545 is("1.20.300.4000", sprintf "%vd", pack(" U*",1,20,300,4000));
547 isnt(v1.20.300.4000, sprintf "%vd", pack("C0U*",1,20,300,4000));
549 my $rslt = $Is_EBCDIC ? "156 67" : "199 162";
550 is(join(" ", unpack("C*", chr(0x1e2))), $rslt);
552 # does pack U create Unicode?
553 is(ord(pack('U', 300)), 300);
555 # does unpack U deref Unicode?
556 is((unpack('U', chr(300)))[0], 300);
558 # is unpack U the reverse of pack U for Unicode string?
559 is("@{[unpack('U*', pack('U*', 100, 200, 300))]}", "100 200 300");
561 # is unpack U the reverse of pack U for byte string?
562 is("@{[unpack('U*', pack('U*', 100, 200))]}", "100 200");
566 skip "Not for EBCDIC", 4 if $Is_EBCDIC;
568 # does unpack C unravel pack U?
569 is("@{[unpack('C*', pack('U*', 100, 200))]}", "100 195 136");
571 # does pack U0C create Unicode?
572 is("@{[pack('U0C*', 100, 195, 136)]}", v100.v200);
574 # does pack C0U create characters?
575 is("@{[pack('C0U*', 100, 200)]}", pack("C*", 100, 195, 136));
577 # does unpack U0U on byte data warn?
579 local $SIG{__WARN__} = sub { $@ = "@_" };
580 my @null = unpack('U0U', chr(255));
581 like($@, /^Malformed UTF-8 character /);
586 my $p = pack 'i*', -2147483648, ~0, 0, 1, 2147483647;
588 # bug - % had to be at the start of the pattern, no leading whitespace or
589 # comments. %i! didn't work at all.
590 foreach my $pat ('%32i*', ' %32i*', "# Muhahahaha\n%32i*", '%32i* ',
591 '%32i!*', ' %32i!*', "\n#\n#\n\r \t\f%32i!*", '%32i!*#') {
592 @a = unpack $pat, $p;
593 is($a[0], 0xFFFFFFFF) || print "# $pat\n";
594 @a = scalar unpack $pat, $p;
595 is($a[0], 0xFFFFFFFF) || print "# $pat\n";
599 $p = pack 'I*', 42, 12;
600 # Multiline patterns in scalar context failed.
601 foreach my $pat ('I', <<EOPOEMSNIPPET, 'I#I', 'I # I', 'I # !!!') {
602 # On the Ning Nang Nong
603 # Where the Cows go Bong!
604 # And the Monkeys all say Boo!
607 @a = unpack $pat, $p;
610 @a = scalar unpack $pat, $p;
615 # shorts (of all flavours) didn't calculate checksums > 32 bits with floating
616 # point, so a pathologically long pattern would wrap at 32 bits.
617 my $pat = "\xff\xff"x65538; # Start with it long, to save any copying.
618 foreach (4,3,2,1,0) {
619 my $len = 65534 + $_;
620 is(unpack ("%33n$len", $pat), 65535 * $len);
630 ['xXa*', "Nick", "Nick"],
631 ['a5Xa5', "cameL", "llama", "camellama"],
633 ['a*@8a*', 'Camel', 'Dromedary', "Camel\0\0\0Dromedary"],
634 ['a*@4a', 'Perl rules', '!', 'Perl!'],
637 my ($template, @in) = @$_;
639 my $got = eval {pack $template, @in};
642 printf "# pack ('$template', %s) gave %s expected %s\n",
643 encode_list (@in), encode_list ($got), encode_list ($out);
650 ['xXa*', "Nick", "Nick"],
651 ['a5Xa5', "camellama", "camel", "llama"],
653 ['@2a2', "water", "te"],
654 ['a*@1a3', "steam", "steam", "tea"],
657 my ($template, $in, @out) = @$_;
658 my @got = eval {unpack $template, $in};
660 list_eq (\@got, \@out) ||
661 printf "# list unpack ('$template', %s) gave %s expected %s\n",
662 _qq($in), encode_list (@got), encode_list (@out);
664 my $got = eval {unpack $template, $in};
666 @out ? is( $got, $out[0] ) # 1 or more items; should get first
667 : ok( !defined $got ) # 0 items; should get undef
668 or printf "# scalar unpack ('$template', %s) gave %s expected %s\n",
669 _qq($in), encode_list ($got), encode_list ($out[0]);
674 my ($u, $v) = qw(foo xyzzy);
675 my $p = pack($t, $u, $v);
676 my @u = unpack($t, $p);
683 is((unpack("w/a*", "\x02abc"))[0], "ab");
685 # "w/a*" should be seen as one unit
687 is(scalar unpack("w/a*", "\x02abc"), "ab");
691 # from Wolfgang Laun: fix in change #13163
696 my $buf = pack( 'Z*/A* C', $s, $x );
700 $h =~ s/[^[:print:]]/./g;
701 ( $s, $y ) = unpack( "Z*/A* C", $buf );
702 is($h, "30.ABCABCABCABCABCABCABCABCABCABC$t");
704 is($s, "ABCABCABCABCABCABCABCABCABCABC");
709 # from Wolfgang Laun: fix in change #13288
711 eval { my $t=unpack("P*", "abc") };
712 like($@, qr/P must have an explicit size/);
715 { # Grouping constructs
717 @a = unpack '(SL)', pack 'SLSLSL', 67..90;
719 @a = unpack '(SL)3', pack 'SLSLSL', 67..90;
722 @a = unpack '(SL)3', pack 'SLSLSLSL', 67..90;
724 @a = unpack '(SL)[3]', pack 'SLSLSLSL', 67..90;
726 @a = unpack '(SL)[2] SL', pack 'SLSLSLSL', 67..90;
728 @a = unpack 'A/(SL)', pack 'ASLSLSLSL', 3, 67..90;
730 @a = unpack 'A/(SL)SL', pack 'ASLSLSLSL', 2, 67..90;
732 @a = unpack '(SL)*', pack 'SLSLSLSL', 67..90;
735 @a = unpack '(SL)*SL', pack 'SLSLSLSL', 67..90;
737 eval { @a = unpack '(*SL)', '' };
738 like($@, qr/\(\)-group starts with a count/);
739 eval { @a = unpack '(3SL)', '' };
740 like($@, qr/\(\)-group starts with a count/);
741 eval { @a = unpack '([3]SL)', '' };
742 like($@, qr/\(\)-group starts with a count/);
743 eval { @a = pack '(*SL)' };
744 like($@, qr/\(\)-group starts with a count/);
745 @a = unpack '(SL)3 SL', pack '(SL)4', 67..74;
747 @a = unpack '(SL)3 SL', pack '(SL)[4]', 67..74;
749 @a = unpack '(SL)3 SL', pack '(SL)*', 67..74;
753 { # Repeat count [SUBEXPR]
754 my @codes = qw( x A Z a c C B b H h s v n S i I l V N L p P f F d
755 s! S! i! I! l! L! j J);
757 if (eval { pack 'q', 1 } ) {
758 push @codes, qw(q Q);
760 push @codes, qw(c C); # Keep the count the same
762 if (eval { pack 'D', 1 } ) {
765 push @codes, 'd'; # Keep the count the same
769 @val{@codes} = map { / [Xx] (?{ undef })
770 | [AZa] (?{ 'something' })
775 | [svnSiIlVNLqQjJ] (?{ 10111 })
776 | [FfDd] (?{ 1.36514538e67 })
777 | [pP] (?{ "try this buffer" })
779 my @end = (0x12345678, 0x23456781, 0x35465768, 0x15263748);
782 for my $type (@codes) {
783 my @list = $val{$type};
784 @list = () unless defined $list[0];
785 for my $count ('', '3', '[11]') {
787 $c = $1 if $count =~ /(\d+)/;
789 @list1 = (@list1) x $c unless $type =~ /[XxAaZBbHhP]/;
790 for my $groupend ('', ')2', ')[8]') {
791 my $groupbegin = ($groupend ? '(' : '');
793 $c = $1 if $groupend =~ /(\d+)/;
794 my @list2 = (@list1) x $c;
796 my $junk1 = "$groupbegin $type$count $groupend";
797 # print "# junk1=$junk1\n";
798 my $p = pack $junk1, @list2;
799 my $half = int( (length $p)/2 );
800 for my $move ('', "X$half", "X!$half", 'x1', 'x!8', "x$half") {
801 my $junk = "$junk1 $move";
802 # print "# junk='$junk', list=(@list2)\n";
803 $p = pack "$junk $end", @list2, @end;
804 my @l = unpack "x[$junk] $end", $p;
805 is(scalar @l, scalar @end);
806 is("@l", "@end", "skipping x[$junk]");
813 # / is recognized after spaces in scalar context
814 # XXXX no spaces are allowed in pack... In pack only before the slash...
815 is(scalar unpack('A /A Z20', pack 'A/A* Z20', 'bcde', 'xxxxx'), 'bcde');
816 is(scalar unpack('A /A /A Z20', '3004bcde'), 'bcde');
819 my $t = 'C[3] x!8 C[2]';
820 my @a = (0x73..0x77);
821 my $p = pack($t, @a);
822 is($p, "\x73\x74\x75\0\0\0\0\0\x76\x77");
823 my @b = unpack $t, $p;
824 is(scalar @b, scalar @a);
825 is("@b", "@a", 'x!8');
826 $t = 'x[5] C[6] X!8 C[2]';
829 is($p, "\0\0\0\0\0\x73\x74\x75\x79\x7a");
831 @a = (0x73..0x75, 0x79, 0x7a, 0x79, 0x7a);
832 is(scalar @b, scalar @a);
836 { # struct {char c1; double d; char cc[2];}
837 my $t = 'C x![d] d C[2]';
838 my @a = (173, 1.283476517e-45, 42, 215);
841 my @b = unpack "$t X[$t] $t", $p; # Extract, step back, extract again
842 is(scalar @b, 2 * scalar @a);
846 local $SIG{__WARN__} = sub {
849 @b = unpack "x[C] x[$t] X[$t] X[C] $t", "$p\0";
852 is(scalar @b, scalar @a);
856 is(length(pack("j", 0)), $Config{ivsize});
857 is(length(pack("J", 0)), $Config{uvsize});
858 is(length(pack("F", 0)), $Config{nvsize});
860 numbers ('j', -2147483648, -1, 0, 1, 2147483647);
861 numbers ('J', 0, 1, 2147483647, 2147483648, 4294967295);
862 numbers ('F', -(2**34), -1, 0, 1, 2**34);
864 my $t = eval { unpack("D*", pack("D", 12.34)) };
866 skip "Long doubles not in use", 56 if $@ =~ /Invalid type in pack/;
868 is(length(pack("D", 0)), $Config{longdblsize});
869 numbers ('D', -(2**34), -1, 0, 1, 2**34);