Tests for Cursor.drop(while:)

This commit is contained in:
Gwendal Roué committed 2018-01-28 17:13:49 +01:00
1 parent ce6bbb2885
commit 420ed0764b
1 file changed
+35 -7
+35 -7
View File
@@ -12,13 +12,41 @@ private struct TestError : Error { }
class DropWhileCursorTests: GRDBTestCase {
func testDropWhileCursorFromCursor() throws {
let base = IteratorCursor([1, 2, 3, 1, 5])
let cursor = base.drop(while: { $0 < 3 })
try XCTAssertEqual(cursor.next()!, 3)
try XCTAssertEqual(cursor.next()!, 1)
try XCTAssertEqual(cursor.next()!, 5)
XCTAssertTrue(try cursor.next() == nil) // end
XCTAssertTrue(try cursor.next() == nil) // past the end
do {
let base = IteratorCursor([1, 2, 3, 1, 5])
let cursor = base.drop(while: { $0 < 3 })
try XCTAssertEqual(cursor.next()!, 3)
try XCTAssertEqual(cursor.next()!, 1)
try XCTAssertEqual(cursor.next()!, 5)
XCTAssertTrue(try cursor.next() == nil) // end
XCTAssertTrue(try cursor.next() == nil) // past the end
}
do {
let base = IteratorCursor([1, 2, 3, 1, 5])
let cursor = base.drop(while: { _ in true })
XCTAssertTrue(try cursor.next() == nil) // end
XCTAssertTrue(try cursor.next() == nil) // past the end
}
do {
let base = IteratorCursor([1, 2, 3, 1, 5])
let cursor = base.drop(while: { _ in false })
try XCTAssertEqual(cursor.next()!, 1)
try XCTAssertEqual(cursor.next()!, 2)
try XCTAssertEqual(cursor.next()!, 3)
try XCTAssertEqual(cursor.next()!, 1)
try XCTAssertEqual(cursor.next()!, 5)
XCTAssertTrue(try cursor.next() == nil) // end
XCTAssertTrue(try cursor.next() == nil) // past the end
}
do {
let base = IteratorCursor([1, 2, 3, 1, 5])
let cursor = base.drop(while: { _ in throw TestError() })
_ = try cursor.next()
XCTFail()
} catch is TestError {
} catch {
XCTFail()
}
}
func testDropWhileCursorFromThrowingCursor() throws {