From: Vincent Pit Date: Sat, 5 Feb 2011 20:48:50 +0000 (+0100) Subject: Allow zero as a suffix or revision index X-Git-Tag: v0.12~12 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=6c4e16d17f4bee5aa01c2048f0a1e12d348eee67;p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git Allow zero as a suffix or revision index --- diff --git a/lib/CPANPLUS/Dist/Gentoo/Version.pm b/lib/CPANPLUS/Dist/Gentoo/Version.pm index d76bcb4..9b32f79 100644 --- a/lib/CPANPLUS/Dist/Gentoo/Version.pm +++ b/lib/CPANPLUS/Dist/Gentoo/Version.pm @@ -28,10 +28,9 @@ use overload ( '""' => \&_stringify, ); -my $int_rx = qr/[0-9]+/; -my $positive_int_rx = qr/0*[1-9][0-9]*/; -my $letter_rx = qr/[a-zA-Z]/; -my $dotted_num_rx = qr/$int_rx(?:\.$int_rx)*/o; +my $int_rx = qr/[0-9]+/; +my $letter_rx = qr/[a-zA-Z]/; +my $dotted_num_rx = qr/$int_rx(?:\.$int_rx)*/o; my @suffixes = qw; my $suffix_rx = join '|', grep !/^normal$/, @suffixes; @@ -39,14 +38,14 @@ $suffix_rx = qr/(?:$suffix_rx)/o; our $version_rx = qr{ $dotted_num_rx $letter_rx? - (?:_$suffix_rx$positive_int_rx?)* - (?:-r$positive_int_rx)? + (?:_$suffix_rx$int_rx?)* + (?:-r$int_rx)? }xo; my $capturing_version_rx = qr{ ($dotted_num_rx) ($letter_rx)? - ((?:_$suffix_rx$positive_int_rx?)*) - (?:-r($positive_int_rx))? + ((?:_$suffix_rx$int_rx?)*) + (?:-r($int_rx))? }xo; =head1 METHODS @@ -71,7 +70,7 @@ sub new { string => $vstring, version => [ split /\.+/, $1 ], letter => $2, - suffixes => [ map /_($suffix_rx)($positive_int_rx)?/go, $3 ], + suffixes => [ map /_($suffix_rx)($int_rx)?/go, $3 ], revision => $4, }, $class; } diff --git a/t/20-version.t b/t/20-version.t index bd48d75..24a8fad 100644 --- a/t/20-version.t +++ b/t/20-version.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 3 + (2 + 2 * 3) * (66 + 4 * 7); +use Test::More tests => 3 + (2 + 2 * 3) * (69 + 4 * 7); use CPANPLUS::Dist::Gentoo::Version; @@ -67,7 +67,9 @@ my @tests = ( [ "1.1_${_}1", "1.0_${_}2" => 1 ], } qw(alpha beta pre rc)), - [ '1.0', '1.0_p' => -1 ], + [ '1.0', '1.0_p0' => -1 ], + [ '1.0', '1.0_p1' => -1 ], + [ '1.0_p', '1.0_p0' => 0 ], [ '1.0a', '1.0_p' => 1 ], [ '1.0', '1.0_p1' => -1 ], [ '1.0_p1', '1.0_p1' => 0 ], @@ -79,7 +81,6 @@ my @tests = ( [ '1.0_beta1', '1.0_pre1' => -1 ], [ '1.0_pre1', '1.0_rc1' => -1 ], [ '1.0_rc1', '1.0' => -1 ], - [ '1.0', '1.0_p1' => -1 ], [ '1.0_alpha', '1.0_alpha_alpha' => 1 ], [ '1.0_beta', '1.0_beta_beta' => 1 ], @@ -93,11 +94,13 @@ my @tests = ( [ '1.0_pre1_rc2', '1.0_pre1_rc2' => 0 ], [ '1.0_pre1_rc2', '1.0_pre1_rc3' => -1 ], + [ '1.0', '1.0-r0' => 0 ], [ '1.0', '1.0-r1' => -1 ], [ '1.0-r1', '1.0-r1' => 0 ], [ '1.0-r1', '1.0-r2' => -1 ], [ '1.1-r1', '1.0-r2' => 1 ], + [ '1.2_p0-r0', '1.2_p', 0 ], [ '1.2_p1-r1', '1.2_p1', 1 ], [ '1.2_p1-r1', '1.2_p1_p1', -1 ], [ '1.2_p1_pre2-r1', '1.2_p1-r1', -1 ],