Version: allow comparing against nil
This commit is contained in:
parent
fbcf500a48
commit
b6acb9cb47
@ -145,6 +145,10 @@ class VersionComparisonTests < Homebrew::TestCase
|
|||||||
assert_operator version("2-p194"), :<, version("2.1-p195")
|
assert_operator version("2-p194"), :<, version("2.1-p195")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_comparing_against_nil
|
||||||
|
assert_operator version("2.1.0-p194"), :>, nil
|
||||||
|
end
|
||||||
|
|
||||||
def test_comparison_returns_nil_for_non_version
|
def test_comparison_returns_nil_for_non_version
|
||||||
v = version("1.0")
|
v = version("1.0")
|
||||||
assert_nil v <=> Object.new
|
assert_nil v <=> Object.new
|
||||||
|
|||||||
@ -213,6 +213,8 @@ class Version
|
|||||||
end
|
end
|
||||||
|
|
||||||
def <=>(other)
|
def <=>(other)
|
||||||
|
return 1 if other.nil?
|
||||||
|
|
||||||
return unless other.is_a?(Version)
|
return unless other.is_a?(Version)
|
||||||
return 0 if version == other.version
|
return 0 if version == other.version
|
||||||
return 1 if head? && !other.head?
|
return 1 if head? && !other.head?
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user