|
1 | 1 | import XCTest
|
2 |
| -import SQLite |
| 2 | +@testable import SQLite |
| 3 | + |
3 | 4 | #if SQLITE_SWIFT_STANDALONE
|
4 | 5 | import sqlite3
|
5 | 6 | #elseif SQLITE_SWIFT_SQLCIPHER
|
@@ -341,3 +342,43 @@ class ConnectionTests : SQLiteTestCase {
|
341 | 342 | }
|
342 | 343 |
|
343 | 344 | }
|
| 345 | + |
| 346 | + |
| 347 | +class ResultTests : XCTestCase { |
| 348 | + let connection = try! Connection(.inMemory) |
| 349 | + |
| 350 | + func test_init_with_ok_code_returns_nil() { |
| 351 | + XCTAssertNil(Result(errorCode: SQLITE_OK, connection: connection, statement: nil) as Result?) |
| 352 | + } |
| 353 | + |
| 354 | + func test_init_with_row_code_returns_nil() { |
| 355 | + XCTAssertNil(Result(errorCode: SQLITE_ROW, connection: connection, statement: nil) as Result?) |
| 356 | + } |
| 357 | + |
| 358 | + func test_init_with_done_code_returns_nil() { |
| 359 | + XCTAssertNil(Result(errorCode: SQLITE_DONE, connection: connection, statement: nil) as Result?) |
| 360 | + } |
| 361 | + |
| 362 | + func test_init_with_other_code_returns_error() { |
| 363 | + if case .some(.error(let message, let code, let statement)) = |
| 364 | + Result(errorCode: SQLITE_MISUSE, connection: connection, statement: nil) { |
| 365 | + XCTAssertEqual("not an error", message) |
| 366 | + XCTAssertEqual(SQLITE_MISUSE, code) |
| 367 | + XCTAssertNil(statement) |
| 368 | + XCTAssert(self.connection === connection) |
| 369 | + } else { |
| 370 | + XCTFail() |
| 371 | + } |
| 372 | + } |
| 373 | + |
| 374 | + func test_description_contains_error_code() { |
| 375 | + XCTAssertEqual("not an error (code: 21)", |
| 376 | + Result(errorCode: SQLITE_MISUSE, connection: connection, statement: nil)?.description) |
| 377 | + } |
| 378 | + |
| 379 | + func test_description_contains_statement_and_error_code() { |
| 380 | + let statement = try! Statement(connection, "SELECT 1") |
| 381 | + XCTAssertEqual("not an error (SELECT 1) (code: 21)", |
| 382 | + Result(errorCode: SQLITE_MISUSE, connection: connection, statement: statement)?.description) |
| 383 | + } |
| 384 | +} |
0 commit comments