aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorJack Nagel2013-12-09 19:43:07 -0600
committerJack Nagel2013-12-09 19:43:07 -0600
commitf6df3e46eaf2e6cb0288026427f918ee6ccc5f4c (patch)
treea83bd671f35766c46566c6405f3493b5e2704088 /Library
parent1bde550346903c07680974264616f098f7b0c7f8 (diff)
downloadhomebrew-f6df3e46eaf2e6cb0288026427f918ee6ccc5f4c.tar.bz2
Implement hash equality for Version
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