Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Quick and Nimble from tests #258

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Partial/Partial.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Foundation
public struct Partial<Wrapped>: PartialProtocol, CustomStringConvertible {

/// An error that can be thrown by the `value(for:)` function.
public enum Error<Value>: Swift.Error {
public enum Error<Value>: Swift.Error, Equatable {
/// The key path has not been set.
case keyPathNotSet(KeyPath<Wrapped, Value>)
}
Expand Down
55 changes: 55 additions & 0 deletions Sources/Partial/PartialConvertible.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,58 @@ public protocol PartialConvertible {
init<PartialType: PartialProtocol>(partial: PartialType) throws where PartialType.Wrapped == Self

}

//extension Optional: PartialConvertible where Wrapped: PartialConvertible {
// public init<PartialType: PartialProtocol>(partial: PartialType) throws where PartialType.Wrapped == Self {
// do {
// let optionalWrapper = OptionalPartialWrapper(partial: partial)
// let unwrappedValue = try Wrapped(partial: optionalWrapper)
// self = .some(unwrappedValue)
// } catch let error as OptionalPartialWrapper<Wrapped>.Error {
// switch error {
// case .valueIsNil:
// self = .none
// case .valueNotSet:
// throw error
// }
// } catch {
// throw error
// }
// }
//}

//private struct OptionalPartialWrapper<Wrapped>: PartialProtocol {
// mutating func setValue<Value>(_ value: Value, for keyPath: KeyPath<Wrapped, Value>) {
// fatalError()
// }
//
// init() {
// getValue = { _ in
// throw Error.valueNotSet
// }
// }
//
// fileprivate enum Error: Swift.Error {
// case valueIsNil
// case valueNotSet
// }
//
// fileprivate var knownKeys: [PartialKeyPath<Wrapped>: Any] = [:]
//
// fileprivate var requestedKeys: [PartialKeyPath<Wrapped>] = []
//
// init<PartialType: PartialProtocol>(
// partial: PartialType,
// requestedKeys: [PartialKeyPath<Wrapped>]
// ) where PartialType.Wrapped == Wrapped? {
// knownKeys
// }
//
// func value<Value>(for keyPath: KeyPath<Wrapped, Value>) throws -> Value {
// knownKeys[keyPath] as! Value
// }
//
// mutating func removeValue<Value>(for keyPath: KeyPath<Wrapped, Value>) {
// knownKeys.removeValue(forKey: keyPath)
// }
//}
102 changes: 0 additions & 102 deletions Tests/PartialTests/Tests/Partial+PartialConvertibleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,108 +14,6 @@ final class Partial_PartialConvertibleTests: QuickSpec {
partial = Partial()
}

context("a non-optional key path") {
let keyPath = \StringWrapperWrapper.stringWrapper
var initialValue: StringWrapper!

beforeEach {
initialValue = "initial value"
partial.setValue(initialValue, for: keyPath)
}

context("set no an incomplete Partial") {
var thrownError: Error?

beforeEach {
do {
try partial.setValue(Partial<StringWrapper>(), for: keyPath)
} catch {
thrownError = error
}
}

afterEach {
thrownError = nil
}

it("should throw a `keyPathNotSet` error") {
let expectedError = Partial<StringWrapper>.Error.keyPathNotSet(\.string)
expect(thrownError).to(matchError(expectedError))
}

it("should not overwrite the value") {
expect(partial[keyPath]) == initialValue
}
}

context("set to a complete partial") {
var unwrapped: StringWrapper!
var thrownError: Error?

beforeEach {
unwrapped = "unwrapped value"

do {
var partialStringWrapper = Partial<StringWrapper>()
partialStringWrapper[\.string] = unwrapped.string
try partial.setValue(partialStringWrapper, for: keyPath)
} catch {
thrownError = error
}
}

it("should not throw an error") {
expect(thrownError).to(beNil())
}

it("should set the key path to the unwrapped value") {
expect(partial[keyPath]) == unwrapped
}
}

context("set with a custom unwrapper") {
context("that throws an error") {
enum TestError: Error {
case testError
}

var thrownError: Error!

beforeEach {
do {
try partial.setValue(Partial<StringWrapper>(), for: keyPath) { _ in
throw TestError.testError
}
} catch {
thrownError = error
}
}

afterEach {
thrownError = nil
}

it("should throw errors thrown by the unwrapper") {
expect(thrownError).to(matchError(TestError.testError))
}
}

context("that returns a value") {
var returnedValue: StringWrapper!

beforeEach {
returnedValue = "returned value"
partial.setValue(Partial<StringWrapper>(), for: keyPath) { _ in
return returnedValue
}
}
it("should set the key path to the value returned by the unwrapper") {
expect(partial[keyPath]) == returnedValue
}
}
}
}

context("an optional key path") {
let keyPath = \StringWrapperWrapper.optionalStringWrapper
var initialValue: StringWrapper!
Expand Down
Loading