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

@@ -3,23 +3,30 @@ import Foundation
import DataLiteCore
struct RawRepresentableTests {
@Test func testRawRepresentableToSQLiteRawValue() {
let color: Color = .green
#expect(color.sqliteValue == .int(1))
@Test func rawRepresentableToSQLiteValue() {
#expect(Color.red.sqliteValue == .int(Color.red.rawValue))
#expect(Color.green.sqliteValue == .int(Color.green.rawValue))
#expect(Color.blue.sqliteValue == .int(Color.blue.rawValue))
}
@Test func testSQLiteRawValueToRawRepresentable() {
#expect(Color(.int(2)) == .blue)
@Test func rawRepresentableFromSQLiteValue() {
#expect(Color(SQLiteValue.int(0)) == .red)
#expect(Color(SQLiteValue.int(1)) == .green)
#expect(Color(SQLiteValue.int(2)) == .blue)
#expect(Color(.int(42)) == nil)
#expect(Color(.text("red")) == nil)
#expect(Color(.blob(Data([0x01, 0x02]))) == nil)
#expect(Color(.null) == nil)
#expect(Color(SQLiteValue.int(42)) == nil)
#expect(Color(SQLiteValue.real(0)) == nil)
#expect(Color(SQLiteValue.real(1)) == nil)
#expect(Color(SQLiteValue.real(2)) == nil)
#expect(Color(SQLiteValue.real(42)) == nil)
#expect(Color(SQLiteValue.text("red")) == nil)
#expect(Color(SQLiteValue.blob(Data([0x01, 0x02]))) == nil)
#expect(Color(SQLiteValue.null) == nil)
}
}
private extension RawRepresentableTests {
enum Color: Int, SQLiteRepresentable {
enum Color: Int64, SQLiteRepresentable {
case red
case green
case blue