From: Nicholas Clark Date: Tue, 11 Dec 2001 23:41:23 +0000 (+0000) Subject: slightly more pack tests X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=72b034c3d570488f2819babae91d2f75fe711c95;p=p5sagit%2Fp5-mst-13.2.git slightly more pack tests Message-ID: <20011211234123.Y21702@plum.flirble.org> p4raw-id: //depot/perl@13635 --- diff --git a/t/op/pack.t b/t/op/pack.t index 6ee51e0..f6f9448 100755 --- a/t/op/pack.t +++ b/t/op/pack.t @@ -6,7 +6,7 @@ BEGIN { require './test.pl'; } -plan tests => 1470; +plan tests => 1476; use strict; use warnings; @@ -442,25 +442,40 @@ is(pack("V", 0xdeadbeef), "\xef\xbe\xad\xde"); my ($x, $y, $z); eval { ($x) = unpack '/a*','hello' }; like($@, qr!/ must follow a numeric type!); + undef $x; + eval { $x = unpack '/a*','hello' }; + like($@, qr!/ must follow a numeric type!); + undef $x; eval { ($z,$x,$y) = unpack 'a3/A C/a* C/Z', "003ok \003yes\004z\000abc" }; is($@, ''); is($z, 'ok'); is($x, 'yes'); is($y, 'z'); + undef $z; + eval { $z = unpack 'a3/A C/a* C/Z', "003ok \003yes\004z\000abc" }; + is($@, ''); + is($z, 'ok'); + + undef $x; eval { ($x) = pack '/a*','hello' }; like($@, qr!Invalid type in pack: '/'!); + undef $x; + eval { $x = pack '/a*','hello' }; + like($@, qr!Invalid type in pack: '/'!); $z = pack 'n/a* N/Z* w/A*','string','hi there ','etc'; my $expect = "\000\006string\0\0\0\012hi there \000\003etc"; is($z, $expect); + undef $x; $expect = 'hello world'; eval { ($x) = unpack ("w/a", chr (11) . "hello world!")}; is($x, $expect); is($@, ''); + undef $x; # Doing this in scalar context used to fail. eval { $x = unpack ("w/a", chr (11) . "hello world!")}; is($@, ''); @@ -473,12 +488,14 @@ is(pack("V", 0xdeadbeef), "\xef\xbe\xad\xde"); ) { my ($pat, $in, $expect) = @$_; + undef $x; eval { ($x) = unpack $pat, $in }; is($@, ''); is($x, $expect) || printf "# list unpack ('$pat', '$in') gave %s, expected '$expect'\n", encode_list ($x); + undef $x; eval { $x = unpack $pat, $in }; is($@, ''); is($x, $expect) || @@ -488,23 +505,29 @@ is(pack("V", 0xdeadbeef), "\xef\xbe\xad\xde"); # / with # - eval { ($z,$x,$y) = unpack <