Skip to content

Commit 8c38626

Browse files
author
Anton Pogonets
committed
Add CustomNSError tests
1 parent b85468d commit 8c38626

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

TestFoundation/TestNSError.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,20 @@
1616
import SwiftXCTest
1717
#endif
1818

19+
struct SwiftCustomNSError: Error, CustomNSError {
20+
}
1921

2022
class TestNSError : XCTestCase {
2123

2224
static var allTests: [(String, (TestNSError) -> () throws -> Void)] {
2325
return [
2426
("test_LocalizedError_errorDescription", test_LocalizedError_errorDescription),
2527
("test_NSErrorAsError_localizedDescription", test_NSErrorAsError_localizedDescription),
28+
("test_CustomNSError_domain", test_CustomNSError_domain),
29+
("test_CustomNSError_userInfo", test_CustomNSError_userInfo),
30+
("test_CustomNSError_errorCode", test_CustomNSError_errorCode),
31+
("test_CustomNSError_errorCodeRawInt", test_CustomNSError_errorCodeRawInt),
32+
("test_CustomNSError_errorCodeRawUInt", test_CustomNSError_errorCodeRawUInt),
2633
]
2734
}
2835

@@ -40,4 +47,45 @@ class TestNSError : XCTestCase {
4047
let error = nsError as Error
4148
XCTAssertEqual(error.localizedDescription, "Localized!")
4249
}
50+
51+
func test_CustomNSError_domain() {
52+
XCTAssertEqual(SwiftCustomNSError.errorDomain, "TestFoundation.SwiftCustomNSError")
53+
}
54+
55+
func test_CustomNSError_userInfo() {
56+
let userInfo = SwiftCustomNSError().errorUserInfo
57+
XCTAssertTrue(userInfo.isEmpty)
58+
}
59+
60+
func test_CustomNSError_errorCode() {
61+
enum SwiftError : Error, CustomNSError {
62+
case zero
63+
case one
64+
case two
65+
}
66+
67+
XCTAssertEqual(SwiftCustomNSError().errorCode, 1)
68+
69+
XCTAssertEqual(SwiftError.zero.errorCode, 0)
70+
XCTAssertEqual(SwiftError.one.errorCode, 1)
71+
XCTAssertEqual(SwiftError.two.errorCode, 2)
72+
}
73+
74+
func test_CustomNSError_errorCodeRawInt() {
75+
enum SwiftError : Int, Error, CustomNSError {
76+
case minusOne = -1
77+
case fourtyTwo = 42
78+
}
79+
80+
XCTAssertEqual(SwiftError.minusOne.errorCode, -1)
81+
XCTAssertEqual(SwiftError.fourtyTwo.errorCode, 42)
82+
}
83+
84+
func test_CustomNSError_errorCodeRawUInt() {
85+
enum SwiftError : UInt, Error, CustomNSError {
86+
case fourtyTwo = 42
87+
}
88+
89+
XCTAssertEqual(SwiftError.fourtyTwo.errorCode, 42)
90+
}
4391
}

0 commit comments

Comments
 (0)