-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from AirHelp/feature/result-refactor
Added more advanced info about comparison result
- Loading branch information
Showing
9 changed files
with
198 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
language: Swift | ||
xcode_project: Mimus.xcodeproj | ||
xcode_scheme: MimusTests | ||
xcode_sdk: [iphonesimulator10.2] | ||
osx_image: xcode8.2 | ||
xcode_sdk: [iphonesimulator11.0] | ||
osx_image: xcode9.0 | ||
|
||
script: | ||
- ./run_tests.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,69 @@ | ||
internal struct MatchResult { | ||
|
||
struct MismatchedComparison { | ||
|
||
let expected: MockEquatable? | ||
|
||
let actual: MockEquatable? | ||
} | ||
|
||
let matching: Bool | ||
|
||
let mismatchedComparisons: [MismatchedComparison] | ||
|
||
init(matching: Bool) { | ||
self.matching = matching | ||
self.mismatchedComparisons = [] | ||
} | ||
|
||
init(matching: Bool, mismatchedComparisons: [MismatchedComparison]) { | ||
self.matching = matching | ||
self.mismatchedComparisons = mismatchedComparisons | ||
} | ||
} | ||
|
||
internal class Matcher { | ||
|
||
func match(expected: [MockEquatable?]?, actual: [MockEquatable?]?) -> Bool { | ||
func match(expected: [MockEquatable?]?, actual: [MockEquatable?]?) -> MatchResult { | ||
if expected == nil && actual == nil { | ||
return true | ||
return MatchResult(matching: true) | ||
} | ||
|
||
guard let expectedArguments = expected, let actualArguments = actual else { | ||
return false | ||
return MatchResult(matching: false) | ||
} | ||
|
||
if expectedArguments.count != actualArguments.count { | ||
return false | ||
return MatchResult(matching: false) | ||
} | ||
|
||
return match(expectedArguments: expectedArguments, actualArguments: actualArguments) | ||
} | ||
|
||
func match(expectedArguments: [MockEquatable?], actualArguments: [MockEquatable?]) -> Bool { | ||
func match(expectedArguments: [MockEquatable?], actualArguments: [MockEquatable?]) -> MatchResult { | ||
// At this point we're sure both arrays have the same count | ||
|
||
var equal = true | ||
|
||
var mismatchedComparisons: [MatchResult.MismatchedComparison] = [] | ||
|
||
for (index, item) in expectedArguments.enumerated() { | ||
let internalEqual: Bool | ||
|
||
let other = actualArguments[index] | ||
if let unwrappedItem = item { | ||
equal = (unwrappedItem.equalTo(other: other)) && equal | ||
internalEqual = (unwrappedItem.equalTo(other: other)) | ||
} else { | ||
equal = other == nil | ||
internalEqual = other == nil | ||
} | ||
|
||
if !internalEqual { | ||
mismatchedComparisons.append(MatchResult.MismatchedComparison(expected: item, actual: other)) | ||
} | ||
|
||
equal = internalEqual && equal | ||
} | ||
|
||
return equal | ||
return MatchResult(matching: equal, mismatchedComparisons: mismatchedComparisons) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.