Skip to content

Commit

Permalink
Be smart about string ranges as well
Browse files Browse the repository at this point in the history
  • Loading branch information
gisle committed Jun 11, 2010
1 parent 05d04b8 commit 7c0615f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
13 changes: 11 additions & 2 deletions lib/Data/Dump.pm
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,17 @@ sub format_list
my $v = $_[$i];
while ($j < @_) {
# XXX allow string increment too?
last unless $v eq "0" || $v =~ /^-?[1-9]\d{0,9}\z/;
$v++;
if ($v eq "0" || $v =~ /^-?[1-9]\d{0,9}\z/) {
$v++;
}
elsif ($v =~ /^"([A-Za-z]{1,3}\d*)"\z/) {
$v = $1;
$v++;
$v = qq("$v");
}
else {
last;
}
last if $_[$j] ne $v;
$j++;
}
Expand Down
4 changes: 3 additions & 1 deletion t/dump.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use strict;
use Test qw(plan ok);
plan tests => 28;
plan tests => 30;

use Data::Dump qw(dump);

Expand All @@ -23,6 +23,8 @@ ok(dump(1..4), "(1 .. 4)");
ok(dump(1..5,6,8,9), "(1 .. 6, 8, 9)");
ok(dump(1..5,4..8), "(1 .. 5, 4 .. 8)");
ok(dump([-2..2]), "[-2 .. 2]");
ok(dump(["a0" .. "z9"]), qq(["a0" .. "z9"]));
ok(dump(["x", 0, 1, 2, 3, "a", "b", "c", "d"]), qq(["x", 0 .. 3, "a" .. "d"]));
ok(dump({ a => 1, b => 2 }), "{ a => 1, b => 2 }");
ok(dump({ 1 => 1, 2 => 1, 10 => 1 }), "{ 1 => 1, 2 => 1, 10 => 1 }");
ok(dump({ 0.14 => 1, 1.8 => 1, -0.5 => 1 }), qq({ "-0.5" => 1, "0.14" => 1, "1.8" => 1 }));
Expand Down
5 changes: 1 addition & 4 deletions t/tied.t
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ EOT
ok(nl(dump(\@array)), <<EOT);
[
# tied MyTie
"v0",
"v1",
"v2",
"v3",
"v0" .. "v3",
]
EOT

Expand Down

0 comments on commit 7c0615f

Please sign in to comment.