-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Combine.Future * swift test --generate-linuxmain * Fix for iOS < 13.0 * Swift >= 4.1 * Better handler for Swift < 4.1 * Fix tests * Fix for Linux * Additional fix for Linux * More #if * receiveCompletion * Linux again * Delete contents.xcworkspacedata
- Loading branch information
1 parent
5b90042
commit 87b5d53
Showing
7 changed files
with
168 additions
and
8 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 |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
DerivedData | ||
/Extensions/Carthage | ||
/Tests/JS-A+/build | ||
.swiftpm/ |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#if swift(>=4.1) | ||
#if canImport(Combine) | ||
import Combine | ||
|
||
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) | ||
public extension Guarantee { | ||
func future() -> Future<T, Never> { | ||
.init { [weak self] promise in | ||
self?.done { value in | ||
promise(.success(value)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) | ||
public extension Promise { | ||
func future() -> Future<T, Error> { | ||
.init { [weak self] promise in | ||
self?.done { value in | ||
promise(.success(value)) | ||
}.catch { error in | ||
promise(.failure(error)) | ||
} | ||
} | ||
} | ||
} | ||
#endif | ||
#endif |
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,5 +1,4 @@ | ||
import PromiseKit | ||
import Dispatch | ||
import XCTest | ||
|
||
private enum Error: Swift.Error { case dummy } | ||
|
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 |
---|---|---|
@@ -0,0 +1,118 @@ | ||
#if swift(>=4.1) | ||
#if canImport(Combine) | ||
import Combine | ||
#endif | ||
#endif | ||
import PromiseKit | ||
import XCTest | ||
|
||
private enum Error: Swift.Error { case dummy } | ||
|
||
class CombineTests: XCTestCase { | ||
private var cancellable: Any? | ||
|
||
override func tearDown() { | ||
#if swift(>=4.1) | ||
#if canImport(Combine) | ||
if #available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) { | ||
(cancellable as? AnyCancellable)?.cancel() | ||
} | ||
#endif | ||
#endif | ||
} | ||
|
||
func testCombinePromiseValue() { | ||
let ex = expectation(description: "") | ||
#if swift(>=4.1) | ||
#if canImport(Combine) | ||
if #available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) { | ||
let promise = after(.milliseconds(100)).then(on: nil){ Promise.value(1) } | ||
cancellable = promise.future().sink(receiveCompletion: { result in | ||
switch result { | ||
case .failure: | ||
XCTAssert(false) | ||
default: | ||
XCTAssert(true) | ||
} | ||
}, receiveValue: { | ||
XCTAssertEqual($0, 1) | ||
ex.fulfill() | ||
}) | ||
} else { | ||
ex.fulfill() | ||
} | ||
#else | ||
ex.fulfill() | ||
#endif | ||
#else | ||
ex.fulfill() | ||
#endif | ||
|
||
wait(for: [ex], timeout: 1) | ||
} | ||
|
||
func testCombineGuaranteeValue() { | ||
let ex = expectation(description: "") | ||
#if swift(>=4.1) | ||
#if canImport(Combine) | ||
if #available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) { | ||
let promise = after(.milliseconds(100)).then(on: nil){ Guarantee.value(1) } | ||
cancellable = promise.future().sink(receiveCompletion: { result in | ||
switch result { | ||
case .failure: | ||
XCTAssert(false) | ||
default: | ||
XCTAssert(true) | ||
} | ||
}, receiveValue: { | ||
XCTAssertEqual($0, 1) | ||
ex.fulfill() | ||
}) | ||
} else { | ||
ex.fulfill() | ||
} | ||
#else | ||
ex.fulfill() | ||
#endif | ||
#else | ||
ex.fulfill() | ||
#endif | ||
|
||
wait(for: [ex], timeout: 1) | ||
} | ||
|
||
func testCombinePromiseThrow() { | ||
let ex = expectation(description: "") | ||
#if swift(>=4.1) | ||
#if canImport(Combine) | ||
if #available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) { | ||
let promise = after(.milliseconds(100)).then(on: nil){ Promise(error: Error.dummy) }.then(on: nil){ Promise.value(1) } | ||
cancellable = promise.future().sink(receiveCompletion: { result in | ||
switch result { | ||
case .failure(let error): | ||
switch error as? Error { | ||
case .dummy: | ||
XCTAssert(true) | ||
default: | ||
XCTAssert(false) | ||
} | ||
default: | ||
XCTAssert(false) | ||
} | ||
ex.fulfill() | ||
}, receiveValue: { _ in | ||
XCTAssert(false) | ||
}) | ||
} else { | ||
ex.fulfill() | ||
} | ||
#else | ||
ex.fulfill() | ||
#endif | ||
#else | ||
ex.fulfill() | ||
#endif | ||
|
||
wait(for: [ex], timeout: 1) | ||
} | ||
} |
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