Skip to content

Commit

Permalink
removed fatal error for wrong types being compared, fatal error preve…
Browse files Browse the repository at this point in the history
…nted some testing using overloaded functions
  • Loading branch information
Rivukis committed Dec 24, 2017
1 parent c26e3a5 commit 1c753f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
9 changes: 0 additions & 9 deletions Example/Source/Constant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ private func routeString(filePath: String, line: String) -> String {

internal enum Constant {
enum FatalError {
static func wrongTypesBeingCompared(self me: SpryEquatable, actual: SpryEquatable) -> Never {
let title = "Wrong types being equated"
let entries = [
"<\(actual)> could NOT be cast as <\(type(of: me))>"
]

fatalError(title: title, entries: entries)
}

static func wrongNumberOfArgsBeingCompared(specifiedArguments: [SpryEquatable?], actualArguments: [Any?]) -> Never {
let title = "Wrong number of arguments to compare"
let entries = [
Expand Down
12 changes: 6 additions & 6 deletions Example/Source/SpryEquatable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public extension SpryEquatable {
public extension SpryEquatable where Self: Equatable {
func _isEqual(to actual: SpryEquatable?) -> Bool {
guard let castedActual = actual as? Self else {
Constant.FatalError.wrongTypesBeingCompared(self: self, actual: actual)
return false
}

return self == castedActual
Expand All @@ -41,7 +41,7 @@ public extension SpryEquatable where Self: Equatable {
public extension SpryEquatable where Self: AnyObject {
func _isEqual(to actual: SpryEquatable?) -> Bool {
guard let castedActual = actual as? Self else {
Constant.FatalError.wrongTypesBeingCompared(self: self, actual: actual)
return false
}

return self === castedActual
Expand All @@ -53,7 +53,7 @@ public extension SpryEquatable where Self: AnyObject {
public extension SpryEquatable where Self: AnyObject & Equatable {
func _isEqual(to actual: SpryEquatable?) -> Bool {
guard let castedActual = actual as? Self else {
Constant.FatalError.wrongTypesBeingCompared(self: self, actual: actual)
return false
}

return self === castedActual
Expand All @@ -65,7 +65,7 @@ public extension SpryEquatable where Self: AnyObject & Equatable {
public extension Array {
func _isEqual(to actual: SpryEquatable?) -> Bool {
guard let castedActual = actual as? Array<Element> else {
Constant.FatalError.wrongTypesBeingCompared(self: self, actual: actual)
return false
}

if self.count != castedActual.count {
Expand All @@ -91,7 +91,7 @@ public extension Array {
public extension Dictionary {
func _isEqual(to actual: SpryEquatable?) -> Bool {
guard let castedActual = actual as? Dictionary<Key, Value> else {
Constant.FatalError.wrongTypesBeingCompared(self: self, actual: actual)
return false
}

if self.count != castedActual.count {
Expand Down Expand Up @@ -135,7 +135,7 @@ public extension SpryEquatable where Self: OptionalType {
}

guard type(of: self) == type(of: actual) else {
Constant.FatalError.wrongTypesBeingCompared(self: self, actual: actual)
return false
}

let selfsWrappedValue = selfMirror.children.first?.value
Expand Down

0 comments on commit 1c753f0

Please sign in to comment.