Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
white49
Alamofire
提交
e489c5fe
A
Alamofire
项目概览
white49
/
Alamofire
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
Alamofire
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e489c5fe
编写于
8月 23, 2015
作者:
C
Christian Noon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Issue #703] Updated Result Failure to store an ErrorType instead of NSError.
上级
eabd1734
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
38 addition
and
38 deletion
+38
-38
Source/Result.swift
Source/Result.swift
+2
-2
Tests/DownloadTests.swift
Tests/DownloadTests.swift
+1
-1
Tests/ResponseSerializationTests.swift
Tests/ResponseSerializationTests.swift
+27
-27
Tests/ResponseTests.swift
Tests/ResponseTests.swift
+6
-6
Tests/ResultTests.swift
Tests/ResultTests.swift
+2
-2
未找到文件。
Source/Result.swift
浏览文件 @
e489c5fe
...
...
@@ -32,7 +32,7 @@ import Foundation
*/
public
enum
Result
<
Value
>
{
case
Success
(
Value
)
case
Failure
(
NSData
?,
NSError
)
case
Failure
(
NSData
?,
ErrorType
)
/// Returns `true` if the result is a success, `false` otherwise.
public
var
isSuccess
:
Bool
{
...
...
@@ -70,7 +70,7 @@ public enum Result<Value> {
}
/// Returns the associated error value if the result is a failure, `nil` otherwise.
public
var
error
:
NSError
?
{
public
var
error
:
ErrorType
?
{
switch
self
{
case
.
Success
:
return
nil
...
...
Tests/DownloadTests.swift
浏览文件 @
e489c5fe
...
...
@@ -360,7 +360,7 @@ class DownloadResumeDataTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isFailure
,
"result should be a failure"
)
XCTAssertNotNil
(
result
.
data
,
"data should not be nil"
)
XCTAssert
NotNil
(
result
.
error
,
"error should not be nil"
)
XCTAssert
True
(
result
.
error
!=
nil
,
"error should not be nil"
)
XCTAssertNotNil
(
download
.
resumeData
,
"resume data should not be nil"
)
}
...
...
Tests/ResponseSerializationTests.swift
浏览文件 @
e489c5fe
...
...
@@ -40,7 +40,7 @@ class ResponseSerializationTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isSuccess
,
"result is success should be true"
)
XCTAssertNotNil
(
result
.
value
,
"result value should not be nil"
)
XCTAssertNil
(
result
.
data
,
"result data should be nil"
)
XCTAssert
Nil
(
result
.
error
,
"result error should be nil"
)
XCTAssert
True
(
result
.
error
==
nil
,
"result error should be nil"
)
}
func
testThatDataResponseSerializerFailsWhenDataIsNil
()
{
...
...
@@ -54,9 +54,9 @@ class ResponseSerializationTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isFailure
,
"result is failure should be true"
)
XCTAssertNil
(
result
.
value
,
"result value should be nil"
)
XCTAssertNil
(
result
.
data
,
"result data should be nil"
)
XCTAssert
NotNil
(
result
.
error
,
"result error should not be nil"
)
XCTAssert
True
(
result
.
error
!=
nil
,
"result error should not be nil"
)
if
let
error
=
result
.
error
{
if
let
error
=
result
.
error
as?
NSError
{
XCTAssertEqual
(
error
.
domain
,
Error
.
Domain
,
"error domain should match expected value"
)
XCTAssertEqual
(
error
.
code
,
Error
.
Code
.
DataSerializationFailed
.
rawValue
,
"error code should match expected value"
)
}
else
{
...
...
@@ -77,9 +77,9 @@ class ResponseSerializationTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isFailure
,
"result is failure should be true"
)
XCTAssertNil
(
result
.
value
,
"result value should be nil"
)
XCTAssertNil
(
result
.
data
,
"result data should be nil"
)
XCTAssert
NotNil
(
result
.
error
,
"result error should not be nil"
)
XCTAssert
True
(
result
.
error
!=
nil
,
"result error should not be nil"
)
if
let
error
=
result
.
error
{
if
let
error
=
result
.
error
as?
NSError
{
XCTAssertEqual
(
error
.
domain
,
Error
.
Domain
,
"error domain should match expected value"
)
XCTAssertEqual
(
error
.
code
,
Error
.
Code
.
StringSerializationFailed
.
rawValue
,
"error code should match expected value"
)
}
else
{
...
...
@@ -98,7 +98,7 @@ class ResponseSerializationTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isSuccess
,
"result is success should be true"
)
XCTAssertNotNil
(
result
.
value
,
"result value should not be nil"
)
XCTAssertNil
(
result
.
data
,
"result data should be nil"
)
XCTAssert
Nil
(
result
.
error
,
"result error should be nil"
)
XCTAssert
True
(
result
.
error
==
nil
,
"result error should be nil"
)
}
func
testThatStringResponseSerializerSucceedsWithUTF8DataAndNoProvidedEncoding
()
{
...
...
@@ -112,7 +112,7 @@ class ResponseSerializationTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isSuccess
,
"result is success should be true"
)
XCTAssertNotNil
(
result
.
value
,
"result value should not be nil"
)
XCTAssertNil
(
result
.
data
,
"result data should be nil"
)
XCTAssert
Nil
(
result
.
error
,
"result error should be nil"
)
XCTAssert
True
(
result
.
error
==
nil
,
"result error should be nil"
)
}
func
testThatStringResponseSerializerSucceedsWithUTF8DataAndUTF8ProvidedEncoding
()
{
...
...
@@ -126,7 +126,7 @@ class ResponseSerializationTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isSuccess
,
"result is success should be true"
)
XCTAssertNotNil
(
result
.
value
,
"result value should not be nil"
)
XCTAssertNil
(
result
.
data
,
"result data should be nil"
)
XCTAssert
Nil
(
result
.
error
,
"result error should be nil"
)
XCTAssert
True
(
result
.
error
==
nil
,
"result error should be nil"
)
}
func
testThatStringResponseSerializerSucceedsWithUTF8DataUsingResponseTextEncodingName
()
{
...
...
@@ -146,7 +146,7 @@ class ResponseSerializationTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isSuccess
,
"result is success should be true"
)
XCTAssertNotNil
(
result
.
value
,
"result value should not be nil"
)
XCTAssertNil
(
result
.
data
,
"result data should be nil"
)
XCTAssert
Nil
(
result
.
error
,
"result error should be nil"
)
XCTAssert
True
(
result
.
error
==
nil
,
"result error should be nil"
)
}
func
testThatStringResponseSerializerFailsWithUTF32DataAndUTF8ProvidedEncoding
()
{
...
...
@@ -161,9 +161,9 @@ class ResponseSerializationTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isFailure
,
"result is failure should be true"
)
XCTAssertNil
(
result
.
value
,
"result value should be nil"
)
XCTAssertNotNil
(
result
.
data
,
"result data should not be nil"
)
XCTAssert
NotNil
(
result
.
error
,
"result error should not be nil"
)
XCTAssert
True
(
result
.
error
!=
nil
,
"result error should not be nil"
)
if
let
error
=
result
.
error
{
if
let
error
=
result
.
error
as?
NSError
{
XCTAssertEqual
(
error
.
domain
,
Error
.
Domain
,
"error domain should match expected value"
)
XCTAssertEqual
(
error
.
code
,
Error
.
Code
.
StringSerializationFailed
.
rawValue
,
"error code should match expected value"
)
}
else
{
...
...
@@ -189,9 +189,9 @@ class ResponseSerializationTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isFailure
,
"result is failure should be true"
)
XCTAssertNil
(
result
.
value
,
"result value should be nil"
)
XCTAssertNotNil
(
result
.
data
,
"result data should not be nil"
)
XCTAssert
NotNil
(
result
.
error
,
"result error should not be nil"
)
XCTAssert
True
(
result
.
error
!=
nil
,
"result error should not be nil"
)
if
let
error
=
result
.
error
{
if
let
error
=
result
.
error
as?
NSError
{
XCTAssertEqual
(
error
.
domain
,
Error
.
Domain
,
"error domain should match expected value"
)
XCTAssertEqual
(
error
.
code
,
Error
.
Code
.
StringSerializationFailed
.
rawValue
,
"error code should match expected value"
)
}
else
{
...
...
@@ -212,9 +212,9 @@ class ResponseSerializationTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isFailure
,
"result is failure should be true"
)
XCTAssertNil
(
result
.
value
,
"result value should be nil"
)
XCTAssertNil
(
result
.
data
,
"result data should be nil"
)
XCTAssert
NotNil
(
result
.
error
,
"result error should not be nil"
)
XCTAssert
True
(
result
.
error
!=
nil
,
"result error should not be nil"
)
if
let
error
=
result
.
error
{
if
let
error
=
result
.
error
as?
NSError
{
XCTAssertEqual
(
error
.
domain
,
Error
.
Domain
,
"error domain should match expected value"
)
XCTAssertEqual
(
error
.
code
,
Error
.
Code
.
JSONSerializationFailed
.
rawValue
,
"error code should match expected value"
)
}
else
{
...
...
@@ -233,9 +233,9 @@ class ResponseSerializationTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isFailure
,
"result is failure should be true"
)
XCTAssertNil
(
result
.
value
,
"result value should be nil"
)
XCTAssertNotNil
(
result
.
data
,
"result data should not be nil"
)
XCTAssert
NotNil
(
result
.
error
,
"result error should not be nil"
)
XCTAssert
True
(
result
.
error
!=
nil
,
"result error should not be nil"
)
if
let
error
=
result
.
error
{
if
let
error
=
result
.
error
as?
NSError
{
XCTAssertEqual
(
error
.
domain
,
NSCocoaErrorDomain
,
"error domain should match expected value"
)
XCTAssertEqual
(
error
.
code
,
3840
,
"error code should match expected value"
)
}
else
{
...
...
@@ -255,7 +255,7 @@ class ResponseSerializationTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isSuccess
,
"result is success should be true"
)
XCTAssertNotNil
(
result
.
value
,
"result value should not be nil"
)
XCTAssertNil
(
result
.
data
,
"result data should be nil"
)
XCTAssert
Nil
(
result
.
error
,
"result error should be nil"
)
XCTAssert
True
(
result
.
error
==
nil
,
"result error should be nil"
)
}
func
testThatJSONResponseSerializerFailsWhenDataIsInvalidJSON
()
{
...
...
@@ -270,9 +270,9 @@ class ResponseSerializationTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isFailure
,
"result is failure should be true"
)
XCTAssertNil
(
result
.
value
,
"result value should be nil"
)
XCTAssertNotNil
(
result
.
data
,
"result data should not be nil"
)
XCTAssert
NotNil
(
result
.
error
,
"result error should not be nil"
)
XCTAssert
True
(
result
.
error
!=
nil
,
"result error should not be nil"
)
if
let
error
=
result
.
error
{
if
let
error
=
result
.
error
as?
NSError
{
XCTAssertEqual
(
error
.
domain
,
NSCocoaErrorDomain
,
"error domain should match expected value"
)
XCTAssertEqual
(
error
.
code
,
3840
,
"error code should match expected value"
)
}
else
{
...
...
@@ -293,9 +293,9 @@ class ResponseSerializationTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isFailure
,
"result is failure should be true"
)
XCTAssertNil
(
result
.
value
,
"result value should be nil"
)
XCTAssertNil
(
result
.
data
,
"result data should be nil"
)
XCTAssert
NotNil
(
result
.
error
,
"result error should not be nil"
)
XCTAssert
True
(
result
.
error
!=
nil
,
"result error should not be nil"
)
if
let
error
=
result
.
error
{
if
let
error
=
result
.
error
as?
NSError
{
XCTAssertEqual
(
error
.
domain
,
Error
.
Domain
,
"error domain should match expected value"
)
XCTAssertEqual
(
error
.
code
,
Error
.
Code
.
PropertyListSerializationFailed
.
rawValue
,
"error code should match expected value"
)
}
else
{
...
...
@@ -314,9 +314,9 @@ class ResponseSerializationTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isFailure
,
"result is failure should be true"
)
XCTAssertNil
(
result
.
value
,
"result value should be nil"
)
XCTAssertNotNil
(
result
.
data
,
"result data should not be nil"
)
XCTAssert
NotNil
(
result
.
error
,
"result error should not be nil"
)
XCTAssert
True
(
result
.
error
!=
nil
,
"result error should not be nil"
)
if
let
error
=
result
.
error
{
if
let
error
=
result
.
error
as?
NSError
{
XCTAssertEqual
(
error
.
domain
,
NSCocoaErrorDomain
,
"error domain should match expected value"
)
XCTAssertEqual
(
error
.
code
,
3840
,
"error code should match expected value"
)
}
else
{
...
...
@@ -336,7 +336,7 @@ class ResponseSerializationTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isSuccess
,
"result is success should be true"
)
XCTAssertNotNil
(
result
.
value
,
"result value should not be nil"
)
XCTAssertNil
(
result
.
data
,
"result data should be nil"
)
XCTAssert
Nil
(
result
.
error
,
"result error should be nil"
)
XCTAssert
True
(
result
.
error
==
nil
,
"result error should be nil"
)
}
func
testThatPropertyListResponseSerializerFailsWhenDataIsInvalidPropertyListData
()
{
...
...
@@ -351,9 +351,9 @@ class ResponseSerializationTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isFailure
,
"result is failure should be true"
)
XCTAssertNil
(
result
.
value
,
"result value should be nil"
)
XCTAssertNotNil
(
result
.
data
,
"result data should not be nil"
)
XCTAssert
NotNil
(
result
.
error
,
"result error should not be nil"
)
XCTAssert
True
(
result
.
error
!=
nil
,
"result error should not be nil"
)
if
let
error
=
result
.
error
{
if
let
error
=
result
.
error
as?
NSError
{
XCTAssertEqual
(
error
.
domain
,
NSCocoaErrorDomain
,
"error domain should match expected value"
)
XCTAssertEqual
(
error
.
code
,
3840
,
"error code should match expected value"
)
}
else
{
...
...
Tests/ResponseTests.swift
浏览文件 @
e489c5fe
...
...
@@ -52,7 +52,7 @@ class ResponseDataTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isSuccess
,
"result should be success"
)
XCTAssertNotNil
(
result
.
value
,
"result value should not be nil"
)
XCTAssertNil
(
result
.
data
,
"result data should be nil"
)
XCTAssert
Nil
(
result
.
error
,
"result error should be nil"
)
XCTAssert
True
(
result
.
error
==
nil
,
"result error should be nil"
)
}
func
testThatResponseDataReturnsFailureResultWithOptionalDataAndError
()
{
...
...
@@ -82,7 +82,7 @@ class ResponseDataTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isFailure
,
"result should be a failure"
)
XCTAssertNil
(
result
.
value
,
"result value should not be nil"
)
XCTAssertNotNil
(
result
.
data
,
"result data should be nil"
)
XCTAssert
NotNil
(
result
.
error
,
"result error should
be nil"
)
XCTAssert
True
(
result
.
error
!=
nil
,
"result error should not
be nil"
)
}
}
...
...
@@ -116,7 +116,7 @@ class ResponseStringTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isSuccess
,
"result should be success"
)
XCTAssertNotNil
(
result
.
value
,
"result value should not be nil"
)
XCTAssertNil
(
result
.
data
,
"result data should be nil"
)
XCTAssert
Nil
(
result
.
error
,
"result error should be nil"
)
XCTAssert
True
(
result
.
error
==
nil
,
"result error should be nil"
)
}
func
testThatResponseStringReturnsFailureResultWithOptionalDataAndError
()
{
...
...
@@ -146,7 +146,7 @@ class ResponseStringTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isFailure
,
"result should be a failure"
)
XCTAssertNil
(
result
.
value
,
"result value should not be nil"
)
XCTAssertNotNil
(
result
.
data
,
"result data should be nil"
)
XCTAssert
NotNil
(
result
.
error
,
"result error should
be nil"
)
XCTAssert
True
(
result
.
error
!=
nil
,
"result error should not
be nil"
)
}
}
...
...
@@ -180,7 +180,7 @@ class ResponseJSONTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isSuccess
,
"result should be success"
)
XCTAssertNotNil
(
result
.
value
,
"result value should not be nil"
)
XCTAssertNil
(
result
.
data
,
"result data should be nil"
)
XCTAssert
Nil
(
result
.
error
,
"result error should be nil"
)
XCTAssert
True
(
result
.
error
==
nil
,
"result error should be nil"
)
}
func
testThatResponseStringReturnsFailureResultWithOptionalDataAndError
()
{
...
...
@@ -210,7 +210,7 @@ class ResponseJSONTestCase: BaseTestCase {
XCTAssertTrue
(
result
.
isFailure
,
"result should be a failure"
)
XCTAssertNil
(
result
.
value
,
"result value should not be nil"
)
XCTAssertNotNil
(
result
.
data
,
"result data should be nil"
)
XCTAssert
NotNil
(
result
.
error
,
"result error should
be nil"
)
XCTAssert
True
(
result
.
error
!=
nil
,
"result error should not
be nil"
)
}
func
testThatResponseJSONReturnsSuccessResultForGETRequest
()
{
...
...
Tests/ResultTests.swift
浏览文件 @
e489c5fe
...
...
@@ -117,7 +117,7 @@ class ResultTestCase: BaseTestCase {
let
result
=
Result
.
Success
(
"success"
)
// Then
XCTAssert
Nil
(
result
.
error
,
"result error should be nil for success case"
)
XCTAssert
True
(
result
.
error
==
nil
,
"result error should be nil for success case"
)
}
func
testThatErrorPropertyReturnsErrorForFailureCase
()
{
...
...
@@ -126,7 +126,7 @@ class ResultTestCase: BaseTestCase {
let
result
=
Result
<
String
>.
Failure
(
nil
,
error
)
// Then
XCTAssert
NotNil
(
result
.
error
,
"result error should not be nil for failure case"
)
XCTAssert
True
(
result
.
error
!=
nil
,
"result error should not be nil for failure case"
)
}
// MARK: - Description Tests
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录