Change 28404 broke the construct s/foo/<<BAR/e. So, try to be more
[p5sagit/p5-mst-13.2.git] / t / op / sprintf.t
index d7f71e7..3e038d4 100755 (executable)
@@ -11,29 +11,13 @@ BEGIN {
     @INC = '../lib';
 }
 use warnings;
+use version;
 use Config;
+use strict;
 
-# strictness
 my @tests = ();
 my ($i, $template, $data, $result, $comment, $w, $x, $evalData, $n, $p);
 
-while (<DATA>) {
-    s/^\s*>//; s/<\s*$//;
-    push @tests, [split(/<\s*>/, $_, 4)];
-}
-
-print '1..', scalar @tests, "\n";
-
-$SIG{__WARN__} = sub {
-    if ($_[0] =~ /^Invalid conversion/) {
-       $w = ' INVALID';
-    } elsif ($_[0] =~ /^Use of uninitialized value/) {
-       $w = ' UNINIT';
-    } else {
-       warn @_;
-    }
-};
-
 my $Is_VMS_VAX = 0;
 # We use HW_MODEL since ARCH_NAME was not in VMS V5.*
 if ($^O eq 'VMS') {
@@ -45,8 +29,9 @@ if ($^O eq 'VMS') {
 # No %Config.
 my $Is_Ultrix_VAX = $^O eq 'ultrix' && `uname -m` =~ /^VAX$/;
 
-for ($i = 1; @tests; $i++) {
-    ($template, $data, $result, $comment) = @{shift @tests};
+while (<DATA>) {
+    s/^\s*>//; s/<\s*$//;
+    ($template, $data, $result, $comment) = split(/<\s*>/, $_, 4);
     if ($^O eq 'os390' || $^O eq 's390') { # non-IEEE (s390 is UTS)
         $data   =~ s/([eE])96$/${1}63/;      # smaller exponents
         $result =~ s/([eE]\+)102$/${1}69/;   #  "       "
@@ -62,10 +47,28 @@ for ($i = 1; @tests; $i++) {
         $data   =~ s/([eE])\-101$/${1}-24/;  # larger exponents
         $result =~ s/([eE])\-102$/${1}-25/;  #  "       "
     }
+
     $evalData = eval $data;
+    $data = ref $evalData ? $evalData : [$evalData];
+    push @tests, [$template, $data, $result, $comment];
+}
+
+print '1..', scalar @tests, "\n";
+
+$SIG{__WARN__} = sub {
+    if ($_[0] =~ /^Invalid conversion/) {
+       $w = ' INVALID';
+    } elsif ($_[0] =~ /^Use of uninitialized value/) {
+       $w = ' UNINIT';
+    } else {
+       warn @_;
+    }
+};
+
+for ($i = 1; @tests; $i++) {
+    ($template, $data, $result, $comment) = @{shift @tests};
     $w = undef;
-    $x = sprintf(">$template<",
-                 defined @$evalData ? @$evalData : $evalData);
+    $x = sprintf(">$template<", @$data);
     substr($x, -1, 0) = $w if $w;
     # $x may have 3 exponent digits, not 2
     my $y = $x;
@@ -239,10 +242,19 @@ __END__
 >%+vd<      >chr(1)<      >+1<
 >%#vd<      >chr(1)<      >1<
 >%vd<       >"\01\02\03"< >1.2.3<
+>%vd<       >v1.2.3<      >1.2.3<
+>%vd<       >[version::qv("1.2.3")]< >1.2.3<
+>%vd<       >[version->new("1.2")]< >1.200<
+>%vd<       >[version->new("1.02")]< >1.20<
+>%vd<       >[version->new("1.002")]< >1.2<
+>%vd<       >[version->new("1048576.5")]< >1048576.500<
+>%vd<       >[version->new("50")]< >50.0<
 >%v.3d<     >"\01\02\03"< >001.002.003<
 >%0v3d<     >"\01\02\03"< >001.002.003<
+>%v.3d<     >[version::qv("1.2.3")]< >001.002.003<
 >%-v3d<     >"\01\02\03"< >1  .2  .3  <
 >%+-v3d<    >"\01\02\03"< >+1 .2  .3  <
+>%+-v3d<    >[version::qv("1.2.3")]< >+1 .2  .3  <
 >%v4.3d<    >"\01\02\03"< > 001. 002. 003<
 >%0v4.3d<   >"\01\02\03"< >0001.0002.0003<
 >%0*v2d<    >['-', "\0\7\14"]< >00-07-12<
@@ -253,6 +265,7 @@ __END__
 >%v*.*d<    >["\01\02\03", 4, 3]< > 001. 002. 003<
 >%0v*.*d<   >["\01\02\03", 4, 3]< >0001.0002.0003<
 >%0*v*d<    >['-', "\0\7\13", 2]< >00-07-11<
+>%0*v*d<    >['-', version::qv("0.7.11"), 2]< >00-07-11<
 >%e<        >1234.875<    >1.234875e+03<
 >%e<        >0.000012345< >1.234500e-05<
 >%e<        >1234567E96<  >1.234567e+102<
@@ -387,6 +400,8 @@ __END__
 >%-010x<    >2**32-1<     >ffffffff  <
 >%0-10x<    >2**32-1<     >ffffffff  <
 >%0*x<      >[-10, ,2**32-1]< >ffffffff  <
+>%vx<       >[version::qv("1.2.3")]< >1.2.3<
+>%vx<       >[version::qv("1.20.300")]< >1.14.12c<
 >%y<        >''<          >%y INVALID<
 >%z<        >''<          >%z INVALID<
 >%2$d %1$d<    >[12, 34]<      >34 12<
@@ -419,6 +434,18 @@ __END__
 >%v_<  >''<    >%v_ INVALID<
 >%v#x< >''<    >%v#x INVALID<
 >%v02x<        >"foo\012"<     >66.6f.6f.0a<
+>%#v.8b<       >"a\000b"<      >0b01100001.00000000.0b01100010<
+>%#v.4o<       >"a\000b"<      >0141.0000.0142<
+>%#v.3i<       >"a\000b"<      >097.000.098<
+>%#v.2x<       >"a\000b"<      >0x61.00.0x62<
+>%#*v.8b<      >["][", "a\000b"]<      >0b01100001][00000000][0b01100010<
+>%#*v.4o<      >["][", "a\000b"]<      >0141][0000][0142<
+>%#*v.3i<      >["][", "a\000b"]<      >097][000][098<
+>%#*v.2x<      >["][", "a\000b"]<      >0x61][00][0x62<
+>%#v.8b<       >"a\x{1e01}\000b\x{1e03}"<      >0b01100001.0b1111000000001.00000000.0b01100010.0b1111000000011<
+>%#v.4o<       >"a\x{1e01}\000b\x{1e03}"<      >0141.017001.0000.0142.017003<
+>%#v.3i<       >"a\x{1e01}\000b\x{1e03}"<      >097.7681.000.098.7683<
+>%#v.2x<       >"a\x{1e01}\000b\x{1e03}"<      >0x61.0x1e01.00.0x62.0x1e03<
 >%V-%s<                >["Hello"]<     >%V-Hello INVALID<
 >%K %d %d<     >[13, 29]<      >%K 13 29 INVALID<
 >%*.*K %d<     >[13, 29, 76]<  >%*.*K 13 INVALID<
@@ -428,5 +455,5 @@ __END__
 >%#b<          >0<     >0<
 >%#o<          >0<     >0<
 >%#x<          >0<     >0<
->%2918905856$v2d<      >''<    ><
->%*2918905856$v2d<     >''<    > UNINIT<
+>%2147483647$v2d<      >''<    ><
+>%*2147483647$v2d<     >''<    > UNINIT<