Skip to content

Commit 7715f7d

Browse files
committed
add tests for codable UUID
1 parent 84783d3 commit 7715f7d

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

Tests/SQLiteTests/QueryIntegrationTests.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ class QueryIntegrationTests: SQLiteTestCase {
7575
builder.column(Expression<Double>("float"))
7676
builder.column(Expression<Double>("double"))
7777
builder.column(Expression<Date>("date"))
78+
builder.column(Expression<UUID>("uuid"))
7879
builder.column(Expression<String?>("optional"))
7980
builder.column(Expression<Data>("sub"))
8081
})
8182

8283
let value1 = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4,
83-
date: Date(timeIntervalSince1970: 0), optional: nil, sub: nil)
84+
date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil)
8485
let value = TestCodable(int: 5, string: "6", bool: true, float: 7, double: 8,
85-
date: Date(timeIntervalSince1970: 5000), optional: "optional", sub: value1)
86-
86+
date: Date(timeIntervalSince1970: 5000), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: "optional", sub: value1)
8787
try db.run(table.insert(value))
8888

8989
let rows = try db.prepare(table)
@@ -95,6 +95,7 @@ class QueryIntegrationTests: SQLiteTestCase {
9595
XCTAssertEqual(values[0].float, 7)
9696
XCTAssertEqual(values[0].double, 8)
9797
XCTAssertEqual(values[0].date, Date(timeIntervalSince1970: 5000))
98+
XCTAssertEqual(values[0].uuid, UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!)
9899
XCTAssertEqual(values[0].optional, "optional")
99100
XCTAssertEqual(values[0].sub?.int, 1)
100101
XCTAssertEqual(values[0].sub?.string, "2")

Tests/SQLiteTests/QueryTests.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,12 @@ class QueryTests: XCTestCase {
279279
func test_insert_encodable() throws {
280280
let emails = Table("emails")
281281
let value = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4,
282-
date: Date(timeIntervalSince1970: 0), optional: nil, sub: nil)
282+
date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil)
283283
let insert = try emails.insert(value)
284284
assertSQL(
285285
"""
286-
INSERT INTO \"emails\" (\"int\", \"string\", \"bool\", \"float\", \"double\", \"date\")
287-
VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000')
286+
INSERT INTO \"emails\" (\"int\", \"string\", \"bool\", \"float\", \"double\", \"date\", \"uuid\")
287+
VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000', 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F')
288288
""".replacingOccurrences(of: "\n", with: ""),
289289
insert
290290
)
@@ -294,16 +294,16 @@ class QueryTests: XCTestCase {
294294
func test_insert_encodable_with_nested_encodable() throws {
295295
let emails = Table("emails")
296296
let value1 = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4,
297-
date: Date(timeIntervalSince1970: 0), optional: nil, sub: nil)
297+
date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil)
298298
let value = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4,
299-
date: Date(timeIntervalSince1970: 0), optional: "optional", sub: value1)
299+
date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: "optional", sub: value1)
300300
let insert = try emails.insert(value)
301301
let encodedJSON = try JSONEncoder().encode(value1)
302302
let encodedJSONString = String(data: encodedJSON, encoding: .utf8)!
303303
assertSQL(
304304
"""
305-
INSERT INTO \"emails\" (\"int\", \"string\", \"bool\", \"float\", \"double\", \"date\", \"optional\",
306-
\"sub\") VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000', 'optional', '\(encodedJSONString)')
305+
INSERT INTO \"emails\" (\"int\", \"string\", \"bool\", \"float\", \"double\", \"date\", \"uuid\", \"optional\",
306+
\"sub\") VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000', 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F', 'optional', '\(encodedJSONString)')
307307
""".replacingOccurrences(of: "\n", with: ""),
308308
insert
309309
)
@@ -350,14 +350,14 @@ class QueryTests: XCTestCase {
350350
let emails = Table("emails")
351351
let string = Expression<String>("string")
352352
let value = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4,
353-
date: Date(timeIntervalSince1970: 0), optional: nil, sub: nil)
353+
date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil)
354354
let insert = try emails.upsert(value, onConflictOf: string)
355355
assertSQL(
356356
"""
357-
INSERT INTO \"emails\" (\"int\", \"string\", \"bool\", \"float\", \"double\", \"date\")
358-
VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000') ON CONFLICT (\"string\")
357+
INSERT INTO \"emails\" (\"int\", \"string\", \"bool\", \"float\", \"double\", \"date\", \"uuid\")
358+
VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000', 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F') ON CONFLICT (\"string\")
359359
DO UPDATE SET \"int\" = \"excluded\".\"int\", \"bool\" = \"excluded\".\"bool\",
360-
\"float\" = \"excluded\".\"float\", \"double\" = \"excluded\".\"double\", \"date\" = \"excluded\".\"date\"
360+
\"float\" = \"excluded\".\"float\", \"double\" = \"excluded\".\"double\", \"date\" = \"excluded\".\"date\", \"uuid\" = \"excluded\".\"uuid\"
361361
""".replacingOccurrences(of: "\n", with: ""),
362362
insert
363363
)
@@ -366,17 +366,17 @@ class QueryTests: XCTestCase {
366366
func test_insert_many_encodable() throws {
367367
let emails = Table("emails")
368368
let value1 = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4,
369-
date: Date(timeIntervalSince1970: 0), optional: nil, sub: nil)
369+
date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil)
370370
let value2 = TestCodable(int: 2, string: "3", bool: true, float: 3, double: 5,
371-
date: Date(timeIntervalSince1970: 0), optional: nil, sub: nil)
371+
date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil)
372372
let value3 = TestCodable(int: 3, string: "4", bool: true, float: 3, double: 6,
373-
date: Date(timeIntervalSince1970: 0), optional: nil, sub: nil)
373+
date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil)
374374
let insert = try emails.insertMany([value1, value2, value3])
375375
assertSQL(
376376
"""
377-
INSERT INTO \"emails\" (\"int\", \"string\", \"bool\", \"float\", \"double\", \"date\")
378-
VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000'), (2, '3', 1, 3.0, 5.0, '1970-01-01T00:00:00.000'),
379-
(3, '4', 1, 3.0, 6.0, '1970-01-01T00:00:00.000')
377+
INSERT INTO \"emails\" (\"int\", \"string\", \"bool\", \"float\", \"double\", \"date\", \"uuid\")
378+
VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000', 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F'), (2, '3', 1, 3.0, 5.0, '1970-01-01T00:00:00.000', 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F'),
379+
(3, '4', 1, 3.0, 6.0, '1970-01-01T00:00:00.000', 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F')
380380
""".replacingOccurrences(of: "\n", with: ""),
381381
insert
382382
)
@@ -399,12 +399,12 @@ class QueryTests: XCTestCase {
399399
func test_update_encodable() throws {
400400
let emails = Table("emails")
401401
let value = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4,
402-
date: Date(timeIntervalSince1970: 0), optional: nil, sub: nil)
402+
date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil)
403403
let update = try emails.update(value)
404404
assertSQL(
405405
"""
406406
UPDATE \"emails\" SET \"int\" = 1, \"string\" = '2', \"bool\" = 1, \"float\" = 3.0, \"double\" = 4.0,
407-
\"date\" = '1970-01-01T00:00:00.000'
407+
\"date\" = '1970-01-01T00:00:00.000', \"uuid\" = 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F'
408408
""".replacingOccurrences(of: "\n", with: ""),
409409
update
410410
)
@@ -413,9 +413,9 @@ class QueryTests: XCTestCase {
413413
func test_update_encodable_with_nested_encodable() throws {
414414
let emails = Table("emails")
415415
let value1 = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4,
416-
date: Date(timeIntervalSince1970: 0), optional: nil, sub: nil)
416+
date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: nil)
417417
let value = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4,
418-
date: Date(timeIntervalSince1970: 0), optional: nil, sub: value1)
418+
date: Date(timeIntervalSince1970: 0), uuid: UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!, optional: nil, sub: value1)
419419
let update = try emails.update(value)
420420

421421
// NOTE: As Linux JSON decoding doesn't order keys the same way, we need to check prefix, suffix,
@@ -424,7 +424,7 @@ class QueryTests: XCTestCase {
424424
let expectedPrefix =
425425
"""
426426
UPDATE \"emails\" SET \"int\" = 1, \"string\" = '2', \"bool\" = 1, \"float\" = 3.0, \"double\" = 4.0,
427-
\"date\" = '1970-01-01T00:00:00.000', \"sub\" = '
427+
\"date\" = '1970-01-01T00:00:00.000', \"uuid\" = 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F', \"sub\" = '
428428
""".replacingOccurrences(of: "\n", with: "")
429429
let expectedSuffix = "'"
430430

Tests/SQLiteTests/TestHelpers.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,18 @@ class TestCodable: Codable, Equatable {
115115
let float: Float
116116
let double: Double
117117
let date: Date
118+
let uuid: UUID
118119
let optional: String?
119120
let sub: TestCodable?
120121

121-
init(int: Int, string: String, bool: Bool, float: Float, double: Double, date: Date, optional: String?, sub: TestCodable?) {
122+
init(int: Int, string: String, bool: Bool, float: Float, double: Double, date: Date, uuid: UUID, optional: String?, sub: TestCodable?) {
122123
self.int = int
123124
self.string = string
124125
self.bool = bool
125126
self.float = float
126127
self.double = double
127128
self.date = date
129+
self.uuid = uuid
128130
self.optional = optional
129131
self.sub = sub
130132
}
@@ -136,6 +138,7 @@ class TestCodable: Codable, Equatable {
136138
lhs.float == rhs.float &&
137139
lhs.double == rhs.double &&
138140
lhs.date == rhs.date &&
141+
lhs.uuid == lhs.uuid &&
139142
lhs.optional == rhs.optional &&
140143
lhs.sub == rhs.sub
141144
}

0 commit comments

Comments
 (0)