DataLiteCore swift package
This commit is contained in:
43
Tests/DataLiteCoreTests/Enums/SQLiteActionTests.swift
Normal file
43
Tests/DataLiteCoreTests/Enums/SQLiteActionTests.swift
Normal file
@@ -0,0 +1,43 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
27
Tests/DataLiteCoreTests/Enums/SQLiteRawTypeTests.swift
Normal file
27
Tests/DataLiteCoreTests/Enums/SQLiteRawTypeTests.swift
Normal file
@@ -0,0 +1,27 @@
|
||||
import Testing
|
||||
import DataLiteC
|
||||
import DataLiteCore
|
||||
|
||||
struct SQLiteRawTypeTests {
|
||||
@Test func testInitializationFromRawValue() {
|
||||
#expect(SQLiteRawType(rawValue: SQLITE_INTEGER) == .int)
|
||||
#expect(SQLiteRawType(rawValue: SQLITE_FLOAT) == .real)
|
||||
#expect(SQLiteRawType(rawValue: SQLITE_TEXT) == .text)
|
||||
#expect(SQLiteRawType(rawValue: SQLITE_BLOB) == .blob)
|
||||
#expect(SQLiteRawType(rawValue: SQLITE_NULL) == .null)
|
||||
#expect(SQLiteRawType(rawValue: -1) == nil)
|
||||
}
|
||||
|
||||
@Test func testRawValue() {
|
||||
#expect(SQLiteRawType.int.rawValue == SQLITE_INTEGER)
|
||||
#expect(SQLiteRawType.real.rawValue == SQLITE_FLOAT)
|
||||
#expect(SQLiteRawType.text.rawValue == SQLITE_TEXT)
|
||||
#expect(SQLiteRawType.blob.rawValue == SQLITE_BLOB)
|
||||
#expect(SQLiteRawType.null.rawValue == SQLITE_NULL)
|
||||
}
|
||||
|
||||
@Test func testInvalidRawValue() {
|
||||
let invalidRawValue: Int32 = 9999
|
||||
#expect(SQLiteRawType(rawValue: invalidRawValue) == nil)
|
||||
}
|
||||
}
|
||||
36
Tests/DataLiteCoreTests/Enums/SQLiteRawValueTests.swift
Normal file
36
Tests/DataLiteCoreTests/Enums/SQLiteRawValueTests.swift
Normal file
@@ -0,0 +1,36 @@
|
||||
import Testing
|
||||
import Foundation
|
||||
import DataLiteCore
|
||||
|
||||
struct SQLiteRawValueTests {
|
||||
@Test func testIntValue() {
|
||||
let value = SQLiteRawValue.int(42)
|
||||
#expect(value.description == "42")
|
||||
}
|
||||
|
||||
@Test func testRealValue() {
|
||||
let value = SQLiteRawValue.real(3.14)
|
||||
#expect(value.description == "3.14")
|
||||
}
|
||||
|
||||
@Test func testTextValue() {
|
||||
let value = SQLiteRawValue.text("Hello, World!")
|
||||
#expect(value.description == "'Hello, World!'")
|
||||
}
|
||||
|
||||
@Test func testTextValueWithSingleQuote() {
|
||||
let value = SQLiteRawValue.text("O'Reilly")
|
||||
#expect(value.description == "'O''Reilly'") // Escaped single quote
|
||||
}
|
||||
|
||||
@Test func testBlobValue() {
|
||||
let data = Data([0xDE, 0xAD, 0xBE, 0xEF])
|
||||
let value = SQLiteRawValue.blob(data)
|
||||
#expect(value.description == "X'DEADBEEF'")
|
||||
}
|
||||
|
||||
@Test func testNullValue() {
|
||||
let value = SQLiteRawValue.null
|
||||
#expect(value.description == "NULL")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user