my $Is_EBCDIC = (defined $Config{ebcdic} && $Config{ebcdic} eq 'define');
my $Perl = which_perl();
-sub encode {
- my @result = @_;
- foreach (@result) {
- s/([[:cntrl:]\177 ])/sprintf "\\%03o", ord $1/ge if defined;
- }
- @result;
-}
-
sub encode_list {
- my @result = @_;
- foreach (@result) {
- if (defined) {
- s/([[:cntrl:]\177])/sprintf "\\%03o", ord $1/ge;
- $_ = qq("$_");
- } else {
- $_ = 'undef';
- }
- }
+ my @result = map {_qq($_)} @_;
if (@result == 1) {
return @result;
}
is( $@, '' );
is(scalar @t, 2);
- if( $t =~ /[nv]/i ) {
+
+ SKIP: {
+ skip "$t not expected to work for some reason", 2 if $t =~ /[nv]/i;
+
is($t[0], 12);
is($t[1], 34);
}
- else {
- pass() for 1..2;
- }
}
}
my ($what, $template, $in, $out) = @$_;
my $got = $what eq 'u' ? (unpack $template, $in) : (pack $template, $in);
unless (is($got, $out)) {
- ($in, $out, $got) = encode ($in, $out, $got);
my $un = $what eq 'u' ? 'un' : '';
- print "# ${un}pack ('$template', \"$in\") gave $out not $got\n";
+ print "# ${un}pack ('$template', "._qq($in).') gave '._qq($out).
+ ' not '._qq($got)."\n";
}
}
$calc_sum = 0;
}
- if (is( $calc_sum, $sum)) {
- print "# unpack '%$_$format' gave $sum\n";
+ if ($calc_sum == $sum) { # HAS to be ==, not eq (so no is()).
+ ok ("unpack '%$_$format' gave $sum");
} else {
my $delta = 1.000001;
if ($format =~ tr /dDfF//
&& ($calc_sum <= $sum * $delta && $calc_sum >= $sum / $delta)) {
- pass;
- print "# unpack '%$_$format' gave $sum, expected $calc_sum\n";
+ pass ("unpack '%$_$format' gave $sum, expected $calc_sum");
} else {
my $text = ref $total ? &$total($len) : $total;
fail;
EOP
$expect = "\000\006string\003etc";
- is($z, $expect) ||
- printf "# got '%s', expected '$expect'\n", encode $z;
+ is($z, $expect);
}
is("1.20.300.4000", sprintf "%vd", pack("U*",1,20,300,4000));
my @got = eval {unpack $template, $in};
is($@, '');
list_eq (\@got, \@out) ||
- printf "# list unpack ('$template', \"%s\") gave %s expected %s\n",
- encode ($in), encode_list (@got), encode_list (@out);
+ printf "# list unpack ('$template', %s) gave %s expected %s\n",
+ _qq($in), encode_list (@got), encode_list (@out);
my $got = eval {unpack $template, $in};
is($@, '');
@out ? is( $got, $out[0] ) # 1 or more items; should get first
: ok( !defined $got ) # 0 items; should get undef
- or printf "# scalar unpack ('$template', \"%s\") gave %s expected %s\n",
- encode ($in), encode_list ($got), encode_list ($out[0]);
+ or printf "# scalar unpack ('$template', %s) gave %s expected %s\n",
+ _qq($in), encode_list ($got), encode_list ($out[0]);
}
{