diff --git a/Tests/GRDBTests/DropWhileCursorTests.swift b/Tests/GRDBTests/DropWhileCursorTests.swift index d47c71f02..63e9b0832 100644 --- a/Tests/GRDBTests/DropWhileCursorTests.swift +++ b/Tests/GRDBTests/DropWhileCursorTests.swift @@ -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 {