mirror of
https://github.com/gosticks/SwiftGit2.git
synced 2025-10-16 11:55:34 +00:00
Make Reference Hashable
This commit is contained in:
parent
d1928ca06c
commit
2a4c231230
@ -38,6 +38,17 @@ public struct Reference: ReferenceType {
|
||||
}
|
||||
}
|
||||
|
||||
extension Reference: Hashable {
|
||||
public var hashValue: Int {
|
||||
return longName.hashValue ^ oid.hashValue
|
||||
}
|
||||
}
|
||||
|
||||
public func == (lhs: Reference, rhs: Reference) -> Bool {
|
||||
return lhs.longName == rhs.longName
|
||||
&& lhs.oid == rhs.oid
|
||||
}
|
||||
|
||||
/// A git branch.
|
||||
public struct Branch: ReferenceType {
|
||||
/// The full name of the reference (e.g., `refs/heads/master`).
|
||||
|
||||
@ -34,5 +34,30 @@ class ReferenceSpec: QuickSpec {
|
||||
expect(ref.oid).to(equal(OID(string: "c4ed03a6b7d7ce837d31d83757febbe84dd465fd")!))
|
||||
}
|
||||
}
|
||||
|
||||
describe("==") {
|
||||
it("should be true with equal references") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let ref1 = from_git_reference(repo, "refs/heads/master") { Reference($0) }
|
||||
let ref2 = from_git_reference(repo, "refs/heads/master") { Reference($0) }
|
||||
expect(ref1).to(equal(ref2))
|
||||
}
|
||||
|
||||
it("should be false with unequal references") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let ref1 = from_git_reference(repo, "refs/heads/master") { Reference($0) }
|
||||
let ref2 = from_git_reference(repo, "refs/heads/another-branch") { Reference($0) }
|
||||
expect(ref1).notTo(equal(ref2))
|
||||
}
|
||||
}
|
||||
|
||||
describe("hashValue") {
|
||||
it("should be equal with equal references") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let ref1 = from_git_reference(repo, "refs/heads/master") { Reference($0) }
|
||||
let ref2 = from_git_reference(repo, "refs/heads/master") { Reference($0) }
|
||||
expect(ref1.hashValue).to(equal(ref2.hashValue))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user