Adjust logic to properly sort erlang versions

Fixes Homebrew/homebrew#21417.
This commit is contained in:
Jack Nagel 2013-07-24 19:44:27 -05:00
parent 4a2817d826
commit 023aff10c7
2 changed files with 22 additions and 7 deletions

View File

@ -46,6 +46,12 @@ class VersionComparisonTests < Test::Unit::TestCase
def test_compare_patchlevel_to_non_patchlevel def test_compare_patchlevel_to_non_patchlevel
assert_operator version('9.9.3-P1'), :>, version('9.9.3') assert_operator version('9.9.3-P1'), :>, version('9.9.3')
end end
def test_erlang_version
versions = %w{R16B R15B03-1 R15B03 R15B02 R15B01 R14B04 R14B03
R14B02 R14B01 R14B R13B04 R13B03 R13B02-1}.reverse
assert_equal versions, versions.sort_by { |v| version(v) }
end
end end
class VersionParsingTests < Test::Unit::TestCase class VersionParsingTests < Test::Unit::TestCase

View File

@ -80,12 +80,12 @@ class Version
class CompositeToken < StringToken class CompositeToken < StringToken
def rev def rev
value[/([0-9]+)/, 1] value[/([0-9]+)/, 1] || "0"
end end
end end
class AlphaToken < CompositeToken class AlphaToken < CompositeToken
PATTERN = /a(?:lpha)?[0-9]+/i PATTERN = /a(?:lpha)?[0-9]*/i
def <=>(other) def <=>(other)
case other case other
@ -98,7 +98,7 @@ class Version
end end
class BetaToken < CompositeToken class BetaToken < CompositeToken
PATTERN = /b(?:eta)?[0-9]+/i PATTERN = /b(?:eta)?[0-9]*/i
def <=>(other) def <=>(other)
case other case other
@ -115,7 +115,7 @@ class Version
end end
class RCToken < CompositeToken class RCToken < CompositeToken
PATTERN = /rc[0-9]+/i PATTERN = /rc[0-9]*/i
def <=>(other) def <=>(other)
case other case other
@ -132,7 +132,7 @@ class Version
end end
class PatchToken < CompositeToken class PatchToken < CompositeToken
PATTERN = /p[0-9]+/i PATTERN = /p[0-9]*/i
def <=>(other) def <=>(other)
case other case other
@ -192,9 +192,18 @@ class Version
protected protected
def begins_with_numeric?
NumericToken === tokens.first
end
def pad_to(length) def pad_to(length)
if begins_with_numeric?
nums, rest = tokens.partition { |t| NumericToken === t } nums, rest = tokens.partition { |t| NumericToken === t }
nums.concat([NULL_TOKEN]*(length - tokens.length)).concat(rest) nums.fill(NULL_TOKEN, nums.length, length - tokens.length)
nums.concat(rest)
else
tokens.dup.fill(NULL_TOKEN, tokens.length, length - tokens.length)
end
end end
def tokens def tokens