SwiftGit2/SwiftGit2Tests/ReferencesSpec.swift
Markos Charatzas 5c8a6000c4 updated to Swift 2.0
updated to Xcode 7.2 recommended settings
integrated with Nimble (v3.0.0), Quick (v0.8.0), Result (1.0.1)
integrated with Guanaco (5031bf67297afbe61ac0f2fbf3e3e8400b3f8888) that supports Swift 2.0
2016-01-16 14:57:32 +00:00

173 lines
6.3 KiB
Swift

//
// ReferencesSpec.swift
// SwiftGit2
//
// Created by Matt Diephouse on 1/2/15.
// Copyright (c) 2015 GitHub, Inc. All rights reserved.
//
import Result
import SwiftGit2
import Nimble
import Quick
func from_git_reference<T>(repository: Repository, name: String, f: COpaquePointer -> T) -> T {
let repository = repository.pointer
var pointer: COpaquePointer = nil
git_reference_lookup(&pointer, repository, name)
let result = f(pointer)
git_object_free(pointer)
return result
}
class ReferenceSpec: QuickSpec {
override func spec() {
describe("Reference(pointer)") {
it("should initialize its properties") {
let repo = Fixtures.simpleRepository
let ref = from_git_reference(repo, name: "refs/heads/master") { Reference($0) }
expect(ref.longName).to(equal("refs/heads/master"))
expect(ref.shortName).to(equal("master"))
expect(ref.oid).to(equal(OID(string: "c4ed03a6b7d7ce837d31d83757febbe84dd465fd")!))
}
}
describe("==(Reference, Reference)") {
it("should be true with equal references") {
let repo = Fixtures.simpleRepository
let ref1 = from_git_reference(repo, name: "refs/heads/master") { Reference($0) }
let ref2 = from_git_reference(repo, name: "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, name: "refs/heads/master") { Reference($0) }
let ref2 = from_git_reference(repo, name: "refs/heads/another-branch") { Reference($0) }
expect(ref1).notTo(equal(ref2))
}
}
describe("Reference.hashValue") {
it("should be equal with equal references") {
let repo = Fixtures.simpleRepository
let ref1 = from_git_reference(repo, name: "refs/heads/master") { Reference($0) }
let ref2 = from_git_reference(repo, name: "refs/heads/master") { Reference($0) }
expect(ref1.hashValue).to(equal(ref2.hashValue))
}
}
}
}
class BranchSpec: QuickSpec {
override func spec() {
describe("Branch(pointer)") {
it("should initialize its properties") {
let repo = Fixtures.mantleRepository
let branch = from_git_reference(repo, name: "refs/heads/master") { Branch($0)! }
expect(branch.longName).to(equal("refs/heads/master"))
expect(branch.name).to(equal("master"))
expect(branch.shortName).to(equal(branch.name))
expect(branch.commit.oid).to(equal(OID(string: "f797bd4837b61d37847a4833024aab268599a681")!))
expect(branch.oid).to(equal(branch.commit.oid))
expect(branch.isLocal).to(beTrue())
expect(branch.isRemote).to(beFalse())
}
it("should work with symoblic refs") {
let repo = Fixtures.mantleRepository
let branch = from_git_reference(repo, name: "refs/remotes/origin/HEAD") { Branch($0)! }
expect(branch.longName).to(equal("refs/remotes/origin/HEAD"))
expect(branch.name).to(equal("origin/HEAD"))
expect(branch.shortName).to(equal(branch.name))
expect(branch.commit.oid).to(equal(OID(string: "f797bd4837b61d37847a4833024aab268599a681")!))
expect(branch.oid).to(equal(branch.commit.oid))
expect(branch.isLocal).to(beFalse())
expect(branch.isRemote).to(beTrue())
}
}
describe("==(Branch, Branch)") {
it("should be true with equal branches") {
let repo = Fixtures.simpleRepository
let branch1 = from_git_reference(repo, name: "refs/heads/master") { Branch($0)! }
let branch2 = from_git_reference(repo, name: "refs/heads/master") { Branch($0)! }
expect(branch1).to(equal(branch2))
}
it("should be false with unequal branches") {
let repo = Fixtures.simpleRepository
let branch1 = from_git_reference(repo, name: "refs/heads/master") { Branch($0)! }
let branch2 = from_git_reference(repo, name: "refs/heads/another-branch") { Branch($0)! }
expect(branch1).notTo(equal(branch2))
}
}
describe("Branch.hashValue") {
it("should be equal with equal references") {
let repo = Fixtures.simpleRepository
let branch1 = from_git_reference(repo, name: "refs/heads/master") { Branch($0)! }
let branch2 = from_git_reference(repo, name: "refs/heads/master") { Branch($0)! }
expect(branch1.hashValue).to(equal(branch2.hashValue))
}
}
}
}
class TagReferenceSpec: QuickSpec {
override func spec() {
describe("TagReference(pointer)") {
it("should work with an annotated tag") {
let repo = Fixtures.simpleRepository
let tag = from_git_reference(repo, name: "refs/tags/tag-2") { TagReference($0)! }
expect(tag.longName).to(equal("refs/tags/tag-2"))
expect(tag.name).to(equal("tag-2"))
expect(tag.shortName).to(equal(tag.name))
expect(tag.oid).to(equal(OID(string: "24e1e40ee77525d9e279f079f9906ad6d98c8940")!))
}
it("should work with a lightweight tag") {
let repo = Fixtures.mantleRepository
let tag = from_git_reference(repo, name: "refs/tags/1.5.4") { TagReference($0)! }
expect(tag.longName).to(equal("refs/tags/1.5.4"))
expect(tag.name).to(equal("1.5.4"))
expect(tag.shortName).to(equal(tag.name))
expect(tag.oid).to(equal(OID(string: "d9dc95002cfbf3929d2b70d2c8a77e6bf5b1b88a")!))
}
it("should return nil if not a tag") {
let repo = Fixtures.simpleRepository
let tag = from_git_reference(repo, name: "refs/heads/master") { TagReference($0) }
expect(tag).to(beNil())
}
}
describe("==(TagReference, TagReference)") {
it("should be true with equal tag references") {
let repo = Fixtures.simpleRepository
let tag1 = from_git_reference(repo, name: "refs/tags/tag-2") { TagReference($0)! }
let tag2 = from_git_reference(repo, name: "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, name: "refs/tags/tag-1") { TagReference($0)! }
let tag2 = from_git_reference(repo, name: "refs/tags/tag-2") { TagReference($0)! }
expect(tag1).notTo(equal(tag2))
}
}
describe("TagReference.hashValue") {
it("should be equal with equal references") {
let repo = Fixtures.simpleRepository
let tag1 = from_git_reference(repo, name: "refs/tags/tag-2") { TagReference($0)! }
let tag2 = from_git_reference(repo, name: "refs/tags/tag-2") { TagReference($0)! }
expect(tag1.hashValue).to(equal(tag2.hashValue))
}
}
}
}