Skip to content

[Test] Add wrappedErrorTask #65

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

Merged
merged 1 commit into from
May 8, 2016
Merged
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
43 changes: 43 additions & 0 deletions SwiftTaskTests/MultipleTasksTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,43 @@ class MultipleTasksTests: _TestCase

self.wait()
}

func testMultipleTasksTests_success1_failure2_success3_wrapped()
{
let expect = self.expectationWithDescription(#function)

var flow = [Int]()

let task1 = { Task<(), Value1, Error1>(value: .Default).on(success: { _ in flow.append(1) }) }
let wrapped1 = wrappedErrorTask(task1, f: WrappedError.ByTask1)

let task2 = { Task<(), Value2, Error2>(error: .Default).on(success: { _ in flow.append(2) }) }
let wrapped2 = wrappedErrorTask(task2, f: WrappedError.ByTask2)

let task3 = { Task<(), Value3, Error3>(value: .Default).on(success: { _ in flow.append(3) }) }
let wrapped3 = wrappedErrorTask(task3, f: WrappedError.ByTask3)

XCTAssertEqual(flow, [])

wrapped1()
.success { _ in
wrapped2()
}
.success { _ in
wrapped3()
}
.on(failure: { error, isCancelled in
guard case let .Some(.ByTask2(error2)) = error else {
XCTFail("Wrong WrappedError.")
return
}
XCTAssertEqual(error2, Error2.Default)
XCTAssertEqual(flow, [1])
expect.fulfill()
})

self.wait()
}
}

extension Task
Expand All @@ -134,3 +171,9 @@ extension Task
}
}
}

private func wrappedErrorTask<P,V,E>(task: () -> Task<P,V,E>, f: E -> WrappedError) -> () -> Task<P,V,WrappedError> {
return {
task()._mapError(f)
}
}