forked from pointfreeco/sqlite-data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomFunctionTests.swift
More file actions
32 lines (29 loc) · 839 Bytes
/
CustomFunctionTests.swift
File metadata and controls
32 lines (29 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import Foundation
import SQLiteData
import Testing
@Suite struct CustomFunctionsTests {
@DatabaseFunction func customDate() -> Date {
Date(timeIntervalSinceReferenceDate: 0)
}
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func basics() throws {
var configuration = Configuration()
configuration.prepareDatabase { db in
db.add(function: $customDate)
}
let database = try DatabaseQueue(configuration: configuration)
let date = try database.read { db in
try Values($customDate())
.fetchOne(db)
}
#expect(date?.timeIntervalSinceReferenceDate == 0)
try database.write { db in
db.remove(function: $customDate)
}
#expect(throws: (any Error).self) {
try database.read { db in
_ = try Values($customDate()).fetchOne(db)
}
}
}
}