DataLireCoder swift package
This commit is contained in:
50
Tests/DLCCommonTests/Extensions/SQLiteRowTests.swift
Normal file
50
Tests/DLCCommonTests/Extensions/SQLiteRowTests.swift
Normal file
@@ -0,0 +1,50 @@
|
||||
import XCTest
|
||||
import DataLiteCore
|
||||
import DLCCommon
|
||||
|
||||
final class SQLiteRowTests: XCTestCase {
|
||||
func testContainsKey() {
|
||||
var row = SQLiteRow()
|
||||
row["key1"] = .text("value1")
|
||||
row["key2"] = .int(42)
|
||||
|
||||
XCTAssertTrue(row.contains(DummyKey(stringValue: "key1")))
|
||||
XCTAssertFalse(row.contains(DummyKey(stringValue: "key3")))
|
||||
|
||||
XCTAssertTrue(row.contains(DummyKey(intValue: 0)))
|
||||
XCTAssertFalse(row.contains(DummyKey(intValue: 2)))
|
||||
}
|
||||
|
||||
func testSubscriptWithKey() {
|
||||
var row = SQLiteRow()
|
||||
row["key1"] = .text("value")
|
||||
|
||||
XCTAssertEqual(row[DummyKey(stringValue: "key1")], .text("value"))
|
||||
XCTAssertNil(row[DummyKey(stringValue: "key2")])
|
||||
|
||||
XCTAssertEqual(row[DummyKey(intValue: 0)], .text("value"))
|
||||
|
||||
row[DummyKey(stringValue: "key1")] = .int(42)
|
||||
XCTAssertEqual(row[DummyKey(stringValue: "key1")], .int(42))
|
||||
|
||||
row[DummyKey(intValue: 0)] = .real(3.14)
|
||||
XCTAssertEqual(row[DummyKey(intValue: 0)], .real(3.14))
|
||||
}
|
||||
}
|
||||
|
||||
private extension SQLiteRowTests {
|
||||
struct DummyKey: CodingKey, Equatable {
|
||||
var stringValue: String
|
||||
var intValue: Int?
|
||||
|
||||
init(stringValue: String) {
|
||||
self.stringValue = stringValue
|
||||
self.intValue = nil
|
||||
}
|
||||
|
||||
init(intValue: Int) {
|
||||
self.stringValue = "\(intValue)"
|
||||
self.intValue = intValue
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Tests/DLCCommonTests/Structures/RowCodingKeyTests.swift
Normal file
18
Tests/DLCCommonTests/Structures/RowCodingKeyTests.swift
Normal file
@@ -0,0 +1,18 @@
|
||||
import XCTest
|
||||
import DLCCommon
|
||||
|
||||
final class RowCodingKeyTests: XCTestCase {
|
||||
func testInitWithStringValue() {
|
||||
let key = RowCodingKey(stringValue: "testKey")
|
||||
|
||||
XCTAssertEqual(key.stringValue, "testKey", "String value does not match the expected value.")
|
||||
XCTAssertNil(key.intValue, "Integer value should be nil when initialized with a string.")
|
||||
}
|
||||
|
||||
func testInitWithIntValue() {
|
||||
let key = RowCodingKey(intValue: 5)
|
||||
|
||||
XCTAssertEqual(key.stringValue, "Index 5", "String value does not match the expected format.")
|
||||
XCTAssertEqual(key.intValue, 5, "Integer value does not match the expected value.")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user