Skip to content

Commit e7da7a6

Browse files
Create DatabaseErrorTests
1 parent c13030a commit e7da7a6

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

Sources/SQLyra/DatabaseError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public struct DatabaseError: Error, Equatable, Hashable {
3535
// MARK: - CustomNSError
3636

3737
extension DatabaseError: CustomNSError {
38-
public static let errorDomain = "SQLyra.DatabaseError"
38+
public static let errorDomain = "SQLyra.DatabaseErrorDomain"
3939

4040
public var errorCode: Int { Int(code) }
4141

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Foundation
2+
import SQLyra
3+
import Testing
4+
5+
struct DatabaseErrorTests {
6+
7+
@Test func localizedDescription() async throws {
8+
let error: any Error = DatabaseError(code: 25, message: "A", details: "B")
9+
#expect(error.localizedDescription == "A")
10+
}
11+
12+
@Test func nsError() {
13+
let error = DatabaseError(code: 12, message: "A", details: "B") as NSError
14+
#expect(error.domain == "SQLyra.DatabaseErrorDomain")
15+
#expect(error.code == 12)
16+
17+
for (key, value) in error.userInfo {
18+
switch (key, value) {
19+
case (NSLocalizedDescriptionKey, let string as String):
20+
#expect(string == "A")
21+
case (NSLocalizedFailureReasonErrorKey, let string as String):
22+
#expect(string == "B")
23+
default:
24+
Issue.record("Unexpected \(key)=\(value)")
25+
}
26+
}
27+
}
28+
29+
}

0 commit comments

Comments
 (0)