Author: petergibbs
Date: Sat Jul 26 00:22:51 2008
New Revision: 29750
Modified:
trunk/src/spf_render.c
trunk/t/op/sprintf.t
trunk/t/op/sprintf2.t
Log:
Re-wrote sprintf2.t to simplify adding more tests.
Added more tests including %*.*f
Fixed spf_render to make %*.*f test pass.
Changed sprintf.t to skip test 300 which now fails differently.
Modified: trunk/src/spf_render.c
==============================================================================
--- trunk/src/spf_render.c (original)
+++ trunk/src/spf_render.c Sat Jul 26 00:22:51 2008
@@ -501,7 +501,7 @@
else {
info.width = num;
}
- /* fall through */
+ continue;
case '.':
info.phase = PHASE_PREC;
Modified: trunk/t/op/sprintf.t
==============================================================================
--- trunk/t/op/sprintf.t (original)
+++ trunk/t/op/sprintf.t Sat Jul 26 00:22:51 2008
@@ -351,6 +351,7 @@
skip_info[233] = 'harness needs support for * modifier'
skip_info[234] = 'perl5-specific extension (%v...)'
skip_info[235] = 'perl5-specific extension (%v...)'
+ skip_info[300] = 'harness needs support for * modifier'
$S0 = 'perl5-specific test'
$I0 = 238
Modified: trunk/t/op/sprintf2.t
==============================================================================
--- trunk/t/op/sprintf2.t (original)
+++ trunk/t/op/sprintf2.t Sat Jul 26 00:22:51 2008
@@ -7,7 +7,7 @@
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 4;
+use Parrot::Test;
=head1 NAME
@@ -23,62 +23,33 @@
=cut
-pir_output_is( <<'CODE', <<'OUTPUT', 'positive length' );
-.sub main
- $P0 = new 'ResizableIntegerArray'
- push $P0, 4
- push $P0, 12
- $S0 = sprintf "<%*d>", $P0
- say $S0
-.end
-CODE
-< 12>
-OUTPUT
-
-pir_output_is( <<'CODE', <<'OUTPUT', 'negative length' );
-.sub main
- $P0 = new 'ResizableIntegerArray'
- push $P0, -4
- push $P0, 12
- $S0 = sprintf "<%*d>", $P0
- say $S0
-.end
-CODE
-<12 >
-OUTPUT
-
-pir_output_is( <<'CODE', <<'OUTPUT', 'minus option, positive length' );
-.sub main
- $P0 = new 'ResizableIntegerArray'
- push $P0, 4
- push $P0, 12
- $S0 = sprintf "<%-*d>", $P0
- say $S0
-.end
-CODE
-<12 >
-OUTPUT
-
-pir_output_is( <<'CODE', <<'OUTPUT', 'misc w/ minus option' );
-.sub main
- $P0 = new 'ResizableIntegerArray'
- push $P0, 65
- push $P0, 65
- push $P0, 65
- push $P0, 65
- push $P0, 65
- push $P0, 65
- push $P0, 3
- push $P0, 65
- push $P0, -4
- push $P0, 65
-
- $S0 = sprintf "|%c|%0c|%-1c|%1c|%-6c|%6c|%*c|%*c|", $P0
- say $S0
-.end
-CODE
-|A|A|A|A|A | A| A|A |
-OUTPUT
+# [ 'format', [arguments], "expected output", 'description' ]
+my @tests = (
+ [ '<%*d>', [4,12], "< 12>\n", 'positive length' ],
+ [ '<%*d>', [-4,12], "<12 >\n", 'negative length' ],
+ [ '<%-*d>', [4,12], "<12 >\n", 'minus option, positive length' ],
+ [ '|%c|%0c|%-1c|%1c|%-6c|%6c|%*c|%*c|', [65,65,65,65,65,65,3,65,-4,65],
+ "|A|A|A|A|A | A| A|A |\n", 'misc w/ minus option' ],
+ [ '<%*s>', [4,'"hi"'], "< hi>\n", 'string, positive length' ],
+ [ '<%*s>', [-4,'"hi"'], "<hi >\n", 'string, negative length' ],
+ [ '<%-*s>', [4,'"hi"'], "<hi >\n", 'string, minus flag' ],
+ [ '<%*.*f>', [7,2,123.456], "< 123.46>\n", 'float length&prec' ],
+ [ '<%*.*f>', [-7,2,123.456], "<123.46 >\n", 'float -length&prec' ],
+);
+
+plan tests => scalar @tests;
+
+foreach my $test (@tests) {
+ my $code = ".sub main\n"
+ . " \$P0 = new 'ResizablePMCArray'\n";
+ foreach my $arg (@{$$test[1]}) {
+ $code .= " push \$P0,$arg\n";
+ }
+ $code .= " \$S0 = sprintf '$$test[0]', \$P0\n"
+ . " say \$S0\n"
+ . ".end\n";
+ pir_output_is( $code, $$test[2], $$test[3] );
+}
# Local Variables:
# mode: cperl