Skip to content

Commit b1d3a40

Browse files
committed
Add extra test for custom aggregation.
1 parent 1e6bfbf commit b1d3a40

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Tests/SQLiteTests/CustomAggregationTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,21 @@ class CustomAggregationTests : SQLiteTestCase {
9797
XCTAssertTrue(values.elementsEqual([3028, 3055]))
9898
}
9999

100+
func testCustomStringAgg() {
101+
let initial = String(repeating: " ", count: 64)
102+
let reduce : (String, [Binding?]) -> String = { (last, bindings) in
103+
let v = (bindings[0] as? String) ?? ""
104+
return last + v
105+
}
106+
let _ = db.createAggregation("myReduceSUM3", initialValue: initial, reduce: reduce, result: { $0 })
107+
let result = try! db.prepare("SELECT myReduceSUM3(email) AS s FROM users")
108+
let i = result.columnNames.index(of: "s")!
109+
for row in result {
110+
let value = row[i] as? String
111+
XCTAssertEqual("\(initial)Alice@example.comBob@example.comEve@example.com", value)
112+
}
113+
}
114+
100115
func testCustomObjectSum() {
101116
{
102117
let initial = TestObject(value: 1000)

0 commit comments

Comments
 (0)