Validate when result of Item is un-sorted
This commit is contained in:
@@ -126,6 +126,8 @@ public class KissDB: NSObject {
|
||||
}
|
||||
}
|
||||
|
||||
/// The result of `Item` is not sorted.
|
||||
///
|
||||
public func select(into: ((Item)->Bool)?) throws {
|
||||
let obj = ItemCallbackObject(itemCallback: into)
|
||||
let userPtr = Unmanaged.passUnretained(obj).toOpaque()
|
||||
|
||||
@@ -62,14 +62,23 @@ final class KissMemeTests: XCTestCase {
|
||||
try db.begin()
|
||||
print("DB count: \(db.count)")
|
||||
|
||||
var index = 0
|
||||
var result = [String: String]()
|
||||
try db.select(into: { item in
|
||||
XCTAssertTrue(item.key == "hello\(index)")
|
||||
XCTAssertTrue(item.value == "world\(index)")
|
||||
index += 1
|
||||
result[item.key] = item.value
|
||||
return true
|
||||
})
|
||||
|
||||
for i in 0 ..< maxItems {
|
||||
guard let value = result["hello\(i)"] else {
|
||||
XCTAssertThrowsError("key not exist for hello\(i)")
|
||||
continue
|
||||
}
|
||||
guard value == "world\(i)" else {
|
||||
XCTAssertThrowsError("value not matched for hello\(i) \(value)")
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
try db.rollback()
|
||||
let endTime = KissDB.appTime
|
||||
print("DB count: \(db.count) selectAll elapsed: \(endTime - startTime)")
|
||||
|
||||
Reference in New Issue
Block a user