Add unit tests
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import Foundation
|
||||
import Testing
|
||||
import DataLiteCore
|
||||
|
||||
struct ArgumentsProtocolTests {
|
||||
@Test func typedSubscript() {
|
||||
let arguments: Arguments = [
|
||||
.text("one"),
|
||||
.text("two"),
|
||||
.int(42)
|
||||
]
|
||||
|
||||
#expect(arguments[0] == TestModel.one)
|
||||
#expect(arguments[1] == TestModel.two)
|
||||
#expect(arguments[2] as TestModel? == nil)
|
||||
}
|
||||
}
|
||||
|
||||
private extension ArgumentsProtocolTests {
|
||||
enum TestModel: String, SQLiteRepresentable {
|
||||
case one, two
|
||||
}
|
||||
|
||||
struct Arguments: ArgumentsProtocol, ExpressibleByArrayLiteral {
|
||||
private let values: [SQLiteValue]
|
||||
|
||||
var startIndex: Int { values.startIndex }
|
||||
var endIndex: Int { values.endIndex }
|
||||
|
||||
init(_ values: [SQLiteValue]) {
|
||||
self.values = values
|
||||
}
|
||||
|
||||
init(arrayLiteral elements: SQLiteValue...) {
|
||||
self.values = elements
|
||||
}
|
||||
|
||||
subscript(index: Int) -> SQLiteValue {
|
||||
values[index]
|
||||
}
|
||||
|
||||
func index(after i: Int) -> Int {
|
||||
values.index(after: i)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,6 @@ import Foundation
|
||||
import Testing
|
||||
import DataLiteCore
|
||||
|
||||
private struct BindableStub: SQLiteBindable {
|
||||
let value: SQLiteValue
|
||||
var sqliteValue: SQLiteValue { value }
|
||||
}
|
||||
|
||||
struct SQLiteBindableTests {
|
||||
@Test(arguments: [
|
||||
SQLiteValue.int(42),
|
||||
@@ -15,8 +10,15 @@ struct SQLiteBindableTests {
|
||||
SQLiteValue.blob(Data([0x00, 0xAB])),
|
||||
SQLiteValue.null
|
||||
])
|
||||
func testDefaultSqliteLiteralPassThrough(_ value: SQLiteValue) {
|
||||
let stub = BindableStub(value: value)
|
||||
func sqliteLiteral(_ value: SQLiteValue) {
|
||||
let stub = Bindable(value: value)
|
||||
#expect(stub.sqliteLiteral == value.sqliteLiteral)
|
||||
}
|
||||
}
|
||||
|
||||
private extension SQLiteBindableTests {
|
||||
struct Bindable: SQLiteBindable {
|
||||
let value: SQLiteValue
|
||||
var sqliteValue: SQLiteValue { value }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user