Make TagReference Hashable

This commit is contained in:
Matt Diephouse 2015-02-14 11:16:08 -05:00
parent fc641cbb94
commit a0f76f6c26
2 changed files with 35 additions and 0 deletions

View File

@ -169,4 +169,14 @@ public enum TagReference: ReferenceType {
} }
} }
extension TagReference: Hashable {
public var hashValue: Int {
return longName.hashValue ^ oid.hashValue
}
}
public func == (lhs: TagReference, rhs: TagReference) -> Bool {
return lhs.longName == rhs.longName
&& lhs.oid == rhs.oid
}

View File

@ -130,5 +130,30 @@ class TagReferenceSpec: QuickSpec {
expect(tag).to(beNil()) expect(tag).to(beNil())
} }
} }
describe("==") {
it("should be true with equal tag references") {
let repo = Fixtures.simpleRepository
let tag1 = from_git_reference(repo, "refs/tags/tag-2") { TagReference($0)! }
let tag2 = from_git_reference(repo, "refs/tags/tag-2") { TagReference($0)! }
expect(tag1).to(equal(tag2))
}
it("should be false with unequal tag references") {
let repo = Fixtures.simpleRepository
let tag1 = from_git_reference(repo, "refs/tags/tag-1") { TagReference($0)! }
let tag2 = from_git_reference(repo, "refs/tags/tag-2") { TagReference($0)! }
expect(tag1).notTo(equal(tag2))
}
}
describe("hashValue") {
it("should be equal with equal references") {
let repo = Fixtures.simpleRepository
let tag1 = from_git_reference(repo, "refs/tags/tag-2") { TagReference($0)! }
let tag2 = from_git_reference(repo, "refs/tags/tag-2") { TagReference($0)! }
expect(tag1.hashValue).to(equal(tag2.hashValue))
}
}
} }
} }