aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/test/test_versions.rb14
-rw-r--r--Library/Homebrew/version.rb5
2 files changed, 19 insertions, 0 deletions
diff --git a/Library/Homebrew/test/test_versions.rb b/Library/Homebrew/test/test_versions.rb
index c4fbb86f3..86092e2d4 100644
--- a/Library/Homebrew/test/test_versions.rb
+++ b/Library/Homebrew/test/test_versions.rb
@@ -65,6 +65,20 @@ class VersionComparisonTests < Test::Unit::TestCase
R14B02 R14B01 R14B R13B04 R13B03 R13B02-1}.reverse
assert_equal versions, versions.sort_by { |v| version(v) }
end
+
+ def test_hash_equality
+ v1 = version('0.1.0')
+ v2 = version('0.1.0')
+ v3 = version('0.1.1')
+
+ assert v1.eql?(v2)
+ assert v2.eql?(v1)
+ assert !v1.eql?(v3)
+ assert_equal v1.hash, v2.hash
+
+ h = { v1 => :foo }
+ assert_equal :foo, h[v2]
+ end
end
class VersionParsingTests < Test::Unit::TestCase
diff --git a/Library/Homebrew/version.rb b/Library/Homebrew/version.rb
index 0c67fa9da..a6e4fb807 100644
--- a/Library/Homebrew/version.rb
+++ b/Library/Homebrew/version.rb
@@ -189,6 +189,11 @@ class Version
max = [tokens.length, other.tokens.length].max
pad_to(max) <=> other.pad_to(max)
end
+ alias_method :eql?, :==
+
+ def hash
+ @version.hash
+ end
def to_s
@version.dup