add swiftUI code

This commit is contained in:
zeus
2025-01-22 14:09:10 +08:00
parent 68e7b7347c
commit 8a99853829
2531 changed files with 486215 additions and 0 deletions
@@ -0,0 +1,81 @@
import XCTest
@testable import GRDB
class UtilsTests: XCTestCase {
func testThrowingFirstError() {
struct ExecuteError: Error { }
struct FinallyError: Error { }
var actions: [String]
do {
actions = []
let result = try throwingFirstError(
execute: { () -> String in
actions.append("execute")
return "foo"
},
finally: {
actions.append("finally")
})
XCTAssertEqual(result, "foo")
XCTAssertEqual(actions, ["execute", "finally"])
} catch {
XCTFail("Unexpected error: \(error)")
}
do {
actions = []
_ = try throwingFirstError(
execute: { () -> String in
actions.append("execute")
throw ExecuteError()
},
finally: {
actions.append("finally")
})
XCTFail("Expected error")
} catch is ExecuteError {
XCTAssertEqual(actions, ["execute", "finally"])
} catch {
XCTFail("Unexpected error: \(error)")
}
do {
actions = []
_ = try throwingFirstError(
execute: { () -> String in
actions.append("execute")
return "foo"
},
finally: {
actions.append("finally")
throw FinallyError()
})
XCTFail("Expected error")
} catch is FinallyError {
XCTAssertEqual(actions, ["execute", "finally"])
} catch {
XCTFail("Unexpected error: \(error)")
}
do {
actions = []
_ = try throwingFirstError(
execute: { () -> String in
actions.append("execute")
throw ExecuteError()
},
finally: {
actions.append("finally")
throw FinallyError()
})
XCTFail("Expected error")
} catch is ExecuteError {
XCTAssertEqual(actions, ["execute", "finally"])
} catch {
XCTFail("Unexpected error: \(error)")
}
}
}