From 520bdd64e6239f49a1f97bf8d360978d59e7cb5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 28 Jan 2018 14:34:53 +0100 Subject: [PATCH] Tests for Cursor.dropFirst(_:) --- GRDB/Core/Cursor.swift | 2 -- Tests/GRDBTests/DropFirstCursorTests.swift | 11 +++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/GRDB/Core/Cursor.swift b/GRDB/Core/Cursor.swift index b67094c92..edf093ef9 100644 --- a/GRDB/Core/Cursor.swift +++ b/GRDB/Core/Cursor.swift @@ -177,8 +177,6 @@ extension Cursor { /// - Returns: A cursor starting after the specified number of /// elements. public func dropFirst(_ n: Int) -> DropFirstCursor { - // TODO: test that [1,2,3,4].dropFirst(1).dropFirst(1) is equivalent to - // [1,2,3,4].dropFirst(2). return DropFirstCursor(self, limit: n) } diff --git a/Tests/GRDBTests/DropFirstCursorTests.swift b/Tests/GRDBTests/DropFirstCursorTests.swift index ae6110ad7..d118418da 100644 --- a/Tests/GRDBTests/DropFirstCursorTests.swift +++ b/Tests/GRDBTests/DropFirstCursorTests.swift @@ -47,4 +47,15 @@ class DropFirstCursorTests: GRDBTestCase { XCTFail() } } + + func testDropFirstChain() throws { + let base = IteratorCursor([1, 2, 3, 4, 5]) + let cursor = base.dropFirst(1).dropFirst(1) + try XCTAssertEqual(cursor.next()!, 3) + try XCTAssertEqual(cursor.next()!, 4) + try XCTAssertEqual(cursor.next()!, 5) + XCTAssertTrue(try cursor.next() == nil) // end + XCTAssertTrue(try cursor.next() == nil) // past the end + } + }