-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCodedErrorTest.swift
More file actions
49 lines (42 loc) · 1.33 KB
/
Copy pathCodedErrorTest.swift
File metadata and controls
49 lines (42 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// CodedErrorTest.swift
// NativeAppTemplate
//
import Foundation
@testable import NativeAppTemplate
import Testing
@Suite
struct CodedErrorTest {
struct TestCodedError: CodedError {
var errorCode: String { "NATIVEAPPTEMPLATE-9999" }
var errorDescription: String? { "Test error description" }
}
@Test
func formattedDescription() {
let error = TestCodedError()
#expect(error.formattedDescription == "[NATIVEAPPTEMPLATE-9999] Test error description")
}
@Test
func codedDescriptionWithCodedError() {
let error: Error = TestCodedError()
#expect(error.codedDescription == "[NATIVEAPPTEMPLATE-9999] Test error description")
}
@Test
func codedDescriptionWithNonCodedError() {
let error: Error = NSError(
domain: "TestDomain",
code: 1,
userInfo: [NSLocalizedDescriptionKey: "Plain error"]
)
#expect(error.codedDescription == "Plain error")
}
struct NilDescriptionError: CodedError {
var errorCode: String { "NATIVEAPPTEMPLATE-0000" }
var errorDescription: String? { nil }
}
@Test
func formattedDescriptionWithNilErrorDescription() {
let error = NilDescriptionError()
#expect(error.formattedDescription == "[NATIVEAPPTEMPLATE-0000] Unknown error")
}
}