Add unit tests

This commit is contained in:
2025-10-25 18:56:55 +03:00
parent ddc47abdde
commit bbb7f14650
38 changed files with 1051 additions and 526 deletions

View File

@@ -0,0 +1,33 @@
import Testing
import DataLiteCore
struct JournalModeTests {
@Test func rawValue() {
#expect(JournalMode.delete.rawValue == "DELETE")
#expect(JournalMode.truncate.rawValue == "TRUNCATE")
#expect(JournalMode.persist.rawValue == "PERSIST")
#expect(JournalMode.memory.rawValue == "MEMORY")
#expect(JournalMode.wal.rawValue == "WAL")
#expect(JournalMode.off.rawValue == "OFF")
}
@Test func initRawValue() {
#expect(JournalMode(rawValue: "DELETE") == .delete)
#expect(JournalMode(rawValue: "delete") == .delete)
#expect(JournalMode(rawValue: "TRUNCATE") == .truncate)
#expect(JournalMode(rawValue: "truncate") == .truncate)
#expect(JournalMode(rawValue: "PERSIST") == .persist)
#expect(JournalMode(rawValue: "persist") == .persist)
#expect(JournalMode(rawValue: "MEMORY") == .memory)
#expect(JournalMode(rawValue: "memory") == .memory)
#expect(JournalMode(rawValue: "WAL") == .wal)
#expect(JournalMode(rawValue: "wal") == .wal)
#expect(JournalMode(rawValue: "OFF") == .off)
#expect(JournalMode(rawValue: "off") == .off)
}
}

View File

@@ -1,43 +0,0 @@
import XCTest
import DataLiteCore
class SQLiteActionTests: XCTestCase {
func testInsertAction() {
let action = SQLiteAction.insert(db: "testDB", table: "users", rowID: 1)
switch action {
case .insert(let db, let table, let rowID):
XCTAssertEqual(db, "testDB", "Database name should be 'testDB'")
XCTAssertEqual(table, "users", "Table name should be 'users'")
XCTAssertEqual(rowID, 1, "Row ID should be 1")
default:
XCTFail("Expected insert action")
}
}
func testUpdateAction() {
let action = SQLiteAction.update(db: "testDB", table: "users", rowID: 1)
switch action {
case .update(let db, let table, let rowID):
XCTAssertEqual(db, "testDB", "Database name should be 'testDB'")
XCTAssertEqual(table, "users", "Table name should be 'users'")
XCTAssertEqual(rowID, 1, "Row ID should be 1")
default:
XCTFail("Expected update action")
}
}
func testDeleteAction() {
let action = SQLiteAction.delete(db: "testDB", table: "users", rowID: 1)
switch action {
case .delete(let db, let table, let rowID):
XCTAssertEqual(db, "testDB", "Database name should be 'testDB'")
XCTAssertEqual(table, "users", "Table name should be 'users'")
XCTAssertEqual(rowID, 1, "Row ID should be 1")
default:
XCTFail("Expected delete action")
}
}
}

View File

@@ -4,14 +4,14 @@ import DataLiteCore
struct SQLiteValueTests {
@Test(arguments: [1, 42, 1234])
func testSQLiteIntValue(_ value: Int64) {
func intSQLiteValue(_ value: Int64) {
let value = SQLiteValue.int(value)
#expect(value.sqliteLiteral == "\(value)")
#expect(value.description == value.sqliteLiteral)
}
@Test(arguments: [12, 0.5, 123.99])
func testSQLiteRealValue(_ value: Double) {
func realSQLiteValue(_ value: Double) {
let value = SQLiteValue.real(value)
#expect(value.sqliteLiteral == "\(value)")
#expect(value.description == value.sqliteLiteral)
@@ -24,7 +24,7 @@ struct SQLiteValueTests {
("O'Reilly", "'O''Reilly'"),
("It's John's \"book\"", "'It''s John''s \"book\"'")
])
func testSQLiteTextValue(_ value: String, _ expected: String) {
func textSQLiteValue(_ value: String, _ expected: String) {
let value = SQLiteValue.text(value)
#expect(value.sqliteLiteral == expected)
#expect(value.description == value.sqliteLiteral)
@@ -35,13 +35,13 @@ struct SQLiteValueTests {
(Data([0x00]), "X'00'"),
(Data([0x00, 0xAB, 0xCD]), "X'00ABCD'")
])
func testSQLiteBlobValue(_ value: Data, _ expected: String) {
func blobSQLiteValue(_ value: Data, _ expected: String) {
let value = SQLiteValue.blob(value)
#expect(value.sqliteLiteral == expected)
#expect(value.description == value.sqliteLiteral)
}
@Test func testSQLiteNullValue() {
@Test func nullSQLiteValue() {
let value = SQLiteValue.null
#expect(value.sqliteLiteral == "NULL")
#expect(value.description == value.sqliteLiteral)

View File

@@ -0,0 +1,29 @@
import Testing
import DataLiteCore
struct TransactionTypeTests {
@Test func description() {
#expect(TransactionType.deferred.description == "DEFERRED")
#expect(TransactionType.immediate.description == "IMMEDIATE")
#expect(TransactionType.exclusive.description == "EXCLUSIVE")
}
@Test func rawValue() {
#expect(TransactionType.deferred.rawValue == "DEFERRED")
#expect(TransactionType.immediate.rawValue == "IMMEDIATE")
#expect(TransactionType.exclusive.rawValue == "EXCLUSIVE")
}
@Test func initRawValue() {
#expect(TransactionType(rawValue: "DEFERRED") == .deferred)
#expect(TransactionType(rawValue: "deferred") == .deferred)
#expect(TransactionType(rawValue: "IMMEDIATE") == .immediate)
#expect(TransactionType(rawValue: "immediate") == .immediate)
#expect(TransactionType(rawValue: "EXCLUSIVE") == .exclusive)
#expect(TransactionType(rawValue: "exclusive") == .exclusive)
#expect(TransactionType(rawValue: "SOME_STR") == nil)
}
}