Skip to content

Commit

Permalink
Add Array and Set equalTo functions when Element is Equatable.
Browse files Browse the repository at this point in the history
  • Loading branch information
TadeasKriz committed Nov 9, 2017
1 parent 3adcde2 commit eb1992a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 0.10.2
* Double the maximum parameters in `call` and `callThrows` methods. [bug #145](https://github.com/Brightify/Cuckoo/issues/145)
* Make the generator deterministic by sorting input files.
* [bug #157](https://github.com/Brightify/Cuckoo/issues/157)
* [PR #158 - kudos to IanKeen](https://github.com/Brightify/Cuckoo/pull/158)
* Add `equalTo` for `Array` and `Set` where `Element` is `Equatable`.

## 0.10.1
* Fixed some errors with getters [bug #151](https://github.com/Brightify/Cuckoo/issues/151)
Expand Down
2 changes: 1 addition & 1 deletion Source/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.10.1</string>
<string>0.10.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
16 changes: 16 additions & 0 deletions Source/Matching/ParameterMatcherFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,21 @@ public func equal<T: Equatable>(to value: T) -> ParameterMatcher<T> {
}

/// Returns an identity matcher.
@available(*, renamed: "sameInstance(as:)")
public func equal<T: AnyObject>(to value: T) -> ParameterMatcher<T> {
return equal(to: value, equalWhen: ===)
}

/// Returns an equality matcher for Array<Equatable> (ordered)
public func equal<T: Equatable>(to array: [T]) -> ParameterMatcher<[T]> {
return equal(to: array, equalWhen: ==)
}

/// Returns an equality matcher for Set<Equatable>
public func equal<T>(to set: Set<T>) -> ParameterMatcher<Set<T>> {
return equal(to: set, equalWhen: ==)
}

/// Returns a matcher using the supplied function.
public func equal<T>(to value: T, equalWhen equalityFunction: @escaping (T, T) -> Bool) -> ParameterMatcher<T> {
return ParameterMatcher {
Expand Down Expand Up @@ -59,6 +70,11 @@ public func sameInstance<T: AnyObject>(as object: T?) -> ParameterMatcher<T?> {
return equal(to: object, equalWhen: ===)
}

/// Returns an identity matcher.
public func sameInstance<T: AnyObject>(as object: T) -> ParameterMatcher<T?> {
return equal(to: object, equalWhen: ===)
}

/// Returns a matcher using the supplied function.
public func equal<T>(to value: T?, equalWhen equalityFunction: @escaping (T?, T?) -> Bool) -> ParameterMatcher<T?> {
return ParameterMatcher {
Expand Down
14 changes: 12 additions & 2 deletions Tests/Matching/ParameterMatcherFunctionsTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import XCTest
import Cuckoo

class ParameterMatcherFunctionsTest: XCTestCase {

class ParameterMatcherFunctionsTest: XCTestCase {
func testEqualToEquatable() {
XCTAssertTrue(equal(to: 1).matches(1))
XCTAssertFalse(equal(to: 1).matches(2))
Expand All @@ -32,6 +31,17 @@ class ParameterMatcherFunctionsTest: XCTestCase {
XCTAssertTrue(equal(to: tuple, equalWhen: function).matches((1, 1)))
XCTAssertFalse(equal(to: tuple, equalWhen: function).matches((1, 2)))
}

func testEqualToArray() {
XCTAssertTrue(equal(to: [1, 2, 3]).matches([1, 2, 3]))
XCTAssertFalse(equal(to: [1, 2, 3]).matches([1, 3, 2]))
}

func testEqualToSet() {
XCTAssertTrue(equal(to: [1, 2, 3] as Set<Int>).matches([1, 2, 3] as Set<Int>))
XCTAssertTrue(equal(to: [1, 2, 3] as Set<Int>).matches([1, 3, 2] as Set<Int>))
XCTAssertFalse(equal(to: [1, 2, 3] as Set<Int>).matches([1, 2] as Set<Int>))
}

func testAnyInt() {
XCTAssertTrue(anyInt().matches(1))
Expand Down

0 comments on commit eb1992a

Please sign in to comment.