Version: allow coercing non-versions in comparisons
These are needed due to the raw string and fixnum comparisons which exist for legacy reasons, for instance compiler version and build comparisons.
This commit is contained in:
parent
b6acb9cb47
commit
16529a4de5
@ -149,6 +149,11 @@ class VersionComparisonTests < Homebrew::TestCase
|
||||
assert_operator version("2.1.0-p194"), :>, nil
|
||||
end
|
||||
|
||||
def test_comparing_against_strings
|
||||
assert_operator version("2.1.0-p194"), :==, "2.1.0-p194"
|
||||
assert_operator version("1"), :==, 1
|
||||
end
|
||||
|
||||
def test_comparison_returns_nil_for_non_version
|
||||
v = version("1.0")
|
||||
assert_nil v <=> Object.new
|
||||
|
||||
@ -213,6 +213,11 @@ class Version
|
||||
end
|
||||
|
||||
def <=>(other)
|
||||
# Needed to retain API compatibility with older string comparisons
|
||||
# for compiler versions, etc.
|
||||
other = Version.new(other) if other.is_a? String
|
||||
# Used by the *_build_version comparisons, which formerly returned Fixnum
|
||||
other = Version.new(other.to_s) if other.is_a? Integer
|
||||
return 1 if other.nil?
|
||||
|
||||
return unless other.is_a?(Version)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user