Refactor entire codebase and rewrite documentation
This commit is contained in:
@@ -4,46 +4,46 @@ import DataLiteCore
|
||||
struct BinaryFloatingPointTests {
|
||||
@Test func testFloatToSQLiteRawValue() {
|
||||
let floatValue: Float = 3.14
|
||||
let rawValue = floatValue.sqliteRawValue
|
||||
let rawValue = floatValue.sqliteValue
|
||||
#expect(rawValue == .real(Double(floatValue)))
|
||||
}
|
||||
|
||||
@Test func testDoubleToSQLiteRawValue() {
|
||||
let doubleValue: Double = 3.14
|
||||
let rawValue = doubleValue.sqliteRawValue
|
||||
let rawValue = doubleValue.sqliteValue
|
||||
#expect(rawValue == .real(doubleValue))
|
||||
}
|
||||
|
||||
@Test func testFloatInitializationFromSQLiteRawValue() {
|
||||
let realValue: SQLiteRawValue = .real(3.14)
|
||||
let realValue: SQLiteValue = .real(3.14)
|
||||
let floatValue = Float(realValue)
|
||||
#expect(floatValue != nil)
|
||||
#expect(floatValue == 3.14)
|
||||
|
||||
let intValue: SQLiteRawValue = .int(42)
|
||||
let intValue: SQLiteValue = .int(42)
|
||||
let floatFromInt = Float(intValue)
|
||||
#expect(floatFromInt != nil)
|
||||
#expect(floatFromInt == 42.0)
|
||||
}
|
||||
|
||||
@Test func testDoubleInitializationFromSQLiteRawValue() {
|
||||
let realValue: SQLiteRawValue = .real(3.14)
|
||||
let realValue: SQLiteValue = .real(3.14)
|
||||
let doubleValue = Double(realValue)
|
||||
#expect(doubleValue != nil)
|
||||
#expect(doubleValue == 3.14)
|
||||
|
||||
let intValue: SQLiteRawValue = .int(42)
|
||||
let intValue: SQLiteValue = .int(42)
|
||||
let doubleFromInt = Double(intValue)
|
||||
#expect(doubleFromInt != nil)
|
||||
#expect(doubleFromInt == 42.0)
|
||||
}
|
||||
|
||||
@Test func testInitializationFailureFromInvalidSQLiteRawValue() {
|
||||
let nullValue: SQLiteRawValue = .null
|
||||
let nullValue: SQLiteValue = .null
|
||||
#expect(Float(nullValue) == nil)
|
||||
#expect(Double(nullValue) == nil)
|
||||
|
||||
let textValue: SQLiteRawValue = .text("Invalid")
|
||||
let textValue: SQLiteValue = .text("Invalid")
|
||||
#expect(Float(textValue) == nil)
|
||||
#expect(Double(textValue) == nil)
|
||||
}
|
||||
|
||||
@@ -3,38 +3,38 @@ import Foundation
|
||||
import DataLiteCore
|
||||
|
||||
struct BinaryIntegerTests {
|
||||
@Test func testIntegerToSQLiteRawValue() {
|
||||
#expect(Int(42).sqliteRawValue == .int(42))
|
||||
#expect(Int8(42).sqliteRawValue == .int(42))
|
||||
#expect(Int16(42).sqliteRawValue == .int(42))
|
||||
#expect(Int32(42).sqliteRawValue == .int(42))
|
||||
#expect(Int64(42).sqliteRawValue == .int(42))
|
||||
@Test func testIntegerToSQLiteValue() {
|
||||
#expect(Int(42).sqliteValue == .int(42))
|
||||
#expect(Int8(42).sqliteValue == .int(42))
|
||||
#expect(Int16(42).sqliteValue == .int(42))
|
||||
#expect(Int32(42).sqliteValue == .int(42))
|
||||
#expect(Int64(42).sqliteValue == .int(42))
|
||||
|
||||
#expect(UInt(42).sqliteRawValue == .int(42))
|
||||
#expect(UInt8(42).sqliteRawValue == .int(42))
|
||||
#expect(UInt16(42).sqliteRawValue == .int(42))
|
||||
#expect(UInt32(42).sqliteRawValue == .int(42))
|
||||
#expect(UInt64(42).sqliteRawValue == .int(42))
|
||||
#expect(UInt(42).sqliteValue == .int(42))
|
||||
#expect(UInt8(42).sqliteValue == .int(42))
|
||||
#expect(UInt16(42).sqliteValue == .int(42))
|
||||
#expect(UInt32(42).sqliteValue == .int(42))
|
||||
#expect(UInt64(42).sqliteValue == .int(42))
|
||||
}
|
||||
|
||||
@Test func testIntegerInitializationFromSQLiteRawValue() {
|
||||
#expect(Int(SQLiteRawValue.int(42)) == 42)
|
||||
#expect(Int8(SQLiteRawValue.int(42)) == 42)
|
||||
#expect(Int16(SQLiteRawValue.int(42)) == 42)
|
||||
#expect(Int32(SQLiteRawValue.int(42)) == 42)
|
||||
#expect(Int64(SQLiteRawValue.int(42)) == 42)
|
||||
@Test func testIntegerInitializationFromSQLiteValue() {
|
||||
#expect(Int(SQLiteValue.int(42)) == 42)
|
||||
#expect(Int8(SQLiteValue.int(42)) == 42)
|
||||
#expect(Int16(SQLiteValue.int(42)) == 42)
|
||||
#expect(Int32(SQLiteValue.int(42)) == 42)
|
||||
#expect(Int64(SQLiteValue.int(42)) == 42)
|
||||
|
||||
#expect(UInt(SQLiteRawValue.int(42)) == 42)
|
||||
#expect(UInt8(SQLiteRawValue.int(42)) == 42)
|
||||
#expect(UInt16(SQLiteRawValue.int(42)) == 42)
|
||||
#expect(UInt32(SQLiteRawValue.int(42)) == 42)
|
||||
#expect(UInt64(SQLiteRawValue.int(42)) == 42)
|
||||
#expect(UInt(SQLiteValue.int(42)) == 42)
|
||||
#expect(UInt8(SQLiteValue.int(42)) == 42)
|
||||
#expect(UInt16(SQLiteValue.int(42)) == 42)
|
||||
#expect(UInt32(SQLiteValue.int(42)) == 42)
|
||||
#expect(UInt64(SQLiteValue.int(42)) == 42)
|
||||
}
|
||||
|
||||
@Test func testInvalidIntegerInitialization() {
|
||||
#expect(Int(SQLiteRawValue.real(3.14)) == nil)
|
||||
#expect(Int8(SQLiteRawValue.text("test")) == nil)
|
||||
#expect(UInt32(SQLiteRawValue.blob(Data([0x01, 0x02]))) == nil)
|
||||
#expect(Int(SQLiteValue.real(3.14)) == nil)
|
||||
#expect(Int8(SQLiteValue.text("test")) == nil)
|
||||
#expect(UInt32(SQLiteValue.blob(Data([0x01, 0x02]))) == nil)
|
||||
|
||||
// Out-of-range conversion
|
||||
let largeValue = Int64.max
|
||||
|
||||
@@ -4,8 +4,8 @@ import DataLiteCore
|
||||
|
||||
struct BoolTests {
|
||||
@Test func testBoolToSQLiteRawValue() {
|
||||
#expect(true.sqliteRawValue == .int(1))
|
||||
#expect(false.sqliteRawValue == .int(0))
|
||||
#expect(true.sqliteValue == .int(1))
|
||||
#expect(false.sqliteValue == .int(0))
|
||||
}
|
||||
|
||||
@Test func testSQLiteRawValueToBool() {
|
||||
|
||||
@@ -5,12 +5,12 @@ import DataLiteCore
|
||||
struct DataSQLiteRawRepresentableTests {
|
||||
@Test func testDataToSQLiteRawValue() {
|
||||
let data = Data([0x01, 0x02, 0x03])
|
||||
#expect(data.sqliteRawValue == .blob(data))
|
||||
#expect(data.sqliteValue == .blob(data))
|
||||
}
|
||||
|
||||
@Test func testSQLiteRawValueToData() {
|
||||
let data = Data([0x01, 0x02, 0x03])
|
||||
let rawValue = SQLiteRawValue.blob(data)
|
||||
let rawValue = SQLiteValue.blob(data)
|
||||
|
||||
#expect(Data(rawValue) == data)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ struct DateSQLiteRawRepresentableTests {
|
||||
let formatter = ISO8601DateFormatter()
|
||||
let dateString = formatter.string(from: date)
|
||||
|
||||
#expect(date.sqliteRawValue == .text(dateString))
|
||||
#expect(date.sqliteValue == .text(dateString))
|
||||
}
|
||||
|
||||
@Test func testSQLiteRawValueToDate() {
|
||||
@@ -16,13 +16,13 @@ struct DateSQLiteRawRepresentableTests {
|
||||
let formatter = ISO8601DateFormatter()
|
||||
let dateString = formatter.string(from: date)
|
||||
|
||||
let rawText = SQLiteRawValue.text(dateString)
|
||||
let rawText = SQLiteValue.text(dateString)
|
||||
#expect(Date(rawText) == date)
|
||||
|
||||
let rawInt = SQLiteRawValue.int(1609459200)
|
||||
let rawInt = SQLiteValue.int(1609459200)
|
||||
#expect(Date(rawInt) == date)
|
||||
|
||||
let rawReal = SQLiteRawValue.real(1609459200)
|
||||
let rawReal = SQLiteValue.real(1609459200)
|
||||
#expect(Date(rawReal) == date)
|
||||
|
||||
#expect(Date(.blob(Data([0x01, 0x02, 0x03]))) == nil)
|
||||
|
||||
@@ -5,7 +5,7 @@ import DataLiteCore
|
||||
struct RawRepresentableTests {
|
||||
@Test func testRawRepresentableToSQLiteRawValue() {
|
||||
let color: Color = .green
|
||||
#expect(color.sqliteRawValue == .int(1))
|
||||
#expect(color.sqliteValue == .int(1))
|
||||
}
|
||||
|
||||
@Test func testSQLiteRawValueToRawRepresentable() {
|
||||
@@ -19,7 +19,7 @@ struct RawRepresentableTests {
|
||||
}
|
||||
|
||||
private extension RawRepresentableTests {
|
||||
enum Color: Int, SQLiteRawRepresentable {
|
||||
enum Color: Int, SQLiteRepresentable {
|
||||
case red
|
||||
case green
|
||||
case blue
|
||||
|
||||
@@ -4,14 +4,14 @@ import DataLiteCore
|
||||
|
||||
struct StringTests {
|
||||
@Test func testStringToSQLiteRawValue() {
|
||||
#expect("Hello, SQLite!".sqliteRawValue == .text("Hello, SQLite!"))
|
||||
#expect("Hello, SQLite!".sqliteValue == .text("Hello, SQLite!"))
|
||||
}
|
||||
|
||||
@Test func testSQLiteRawValueToString() {
|
||||
#expect(String(SQLiteRawValue.text("Hello, SQLite!")) == "Hello, SQLite!")
|
||||
#expect(String(SQLiteValue.text("Hello, SQLite!")) == "Hello, SQLite!")
|
||||
|
||||
#expect(String(SQLiteRawValue.int(42)) == nil)
|
||||
#expect(String(SQLiteRawValue.blob(Data([0x01, 0x02]))) == nil)
|
||||
#expect(String(SQLiteRawValue.null) == nil)
|
||||
#expect(String(SQLiteValue.int(42)) == nil)
|
||||
#expect(String(SQLiteValue.blob(Data([0x01, 0x02]))) == nil)
|
||||
#expect(String(SQLiteValue.null) == nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@ import DataLiteCore
|
||||
struct UUIDTests {
|
||||
@Test func testUUIDToSQLiteRawValue() {
|
||||
let uuid = UUID(uuidString: "123e4567-e89b-12d3-a456-426614174000")!
|
||||
#expect(uuid.sqliteRawValue == .text("123E4567-E89B-12D3-A456-426614174000"))
|
||||
#expect(uuid.sqliteValue == .text("123E4567-E89B-12D3-A456-426614174000"))
|
||||
}
|
||||
|
||||
@Test func testSQLiteRawValueToUUID() {
|
||||
let raw = SQLiteRawValue.text("123e4567-e89b-12d3-a456-426614174000")
|
||||
let raw = SQLiteValue.text("123e4567-e89b-12d3-a456-426614174000")
|
||||
#expect(UUID(raw) == UUID(uuidString: "123e4567-e89b-12d3-a456-426614174000"))
|
||||
|
||||
#expect(UUID(.text("invalid-uuid-string")) == nil)
|
||||
|
||||
Reference in New Issue
Block a user