More typed cursor tests

This commit is contained in:
Gwendal Roué committed 2017-09-06 08:58:27 +02:00
1 parent e84060e01c
commit aa064029ec
4 files changed
+17 -16

No files matched your search

+3 -2
View File
@@ -42,12 +42,13 @@ class AnyCursorTests: GRDBTestCase {
}
func testAnyCursorFromCursor() {
var i = 0
let base = IteratorCursor([0, 1])
// This helper function makes sure AnyCursor initializer accepts any cursor,
// and not only IteratorCursor:
func makeAnyCursor<C: Cursor>(_ cursor: C) -> AnyCursor<Int> where C.Element == Int {
return AnyCursor(cursor)
}
let cursor = makeAnyCursor(base)
let cursor = AnyCursor(base)
XCTAssertEqual(try cursor.next()!, 0)
XCTAssertEqual(try cursor.next()!, 1)
XCTAssertTrue(try cursor.next() == nil) // end
@@ -31,7 +31,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
func testFetchCursor() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
func test<C: Cursor>(_ cursor: C) throws where C.Element == Fetched {
func test(_ cursor: DatabaseValueCursor<Fetched>) throws {
XCTAssertEqual(try cursor.next()!.int, 1)
XCTAssertEqual(try cursor.next()!.int, 2)
XCTAssertTrue(try cursor.next() == nil) // end
@@ -61,7 +61,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
let customError = NSError(domain: "Custom", code: 0xDEAD)
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
try dbQueue.inDatabase { db in
func test<C: Cursor>(_ cursor: C, sql: String) throws where C.Element == Fetched {
func test(_ cursor: DatabaseValueCursor<Fetched>, sql: String) throws {
do {
_ = try cursor.next()
XCTFail()
@@ -102,7 +102,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
func testFetchCursorCompilationFailure() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
func test<C: Cursor>(_ cursor: @autoclosure () throws -> C, sql: String) throws where C.Element == Fetched {
func test(_ cursor: @autoclosure () throws -> DatabaseValueCursor<Fetched>, sql: String) throws {
do {
_ = try cursor()
XCTFail()
@@ -366,7 +366,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
func testOptionalFetchCursor() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
func test<C: Cursor>(_ cursor: C) throws where C.Element == Fetched? {
func test(_ cursor: NullableDatabaseValueCursor<Fetched>) throws {
XCTAssertEqual(try cursor.next()!!.int, 1)
XCTAssertTrue(try cursor.next()! == nil)
XCTAssertTrue(try cursor.next() == nil) // end
@@ -396,7 +396,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
let customError = NSError(domain: "Custom", code: 0xDEAD)
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
try dbQueue.inDatabase { db in
func test<C: Cursor>(_ cursor: C, sql: String) throws where C.Element == Fetched? {
func test(_ cursor: NullableDatabaseValueCursor<Fetched>, sql: String) throws {
do {
_ = try cursor.next()
XCTFail()
@@ -437,7 +437,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
func testOptionalFetchCursorCompilationFailure() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
func test<C: Cursor>(_ cursor: @autoclosure () throws -> C, sql: String) throws where C.Element == Fetched? {
func test(_ cursor: @autoclosure () throws -> NullableDatabaseValueCursor<Fetched>, sql: String) throws {
do {
_ = try cursor()
XCTFail()
+3 -3
View File
@@ -31,7 +31,7 @@ class RowConvertibleTests: GRDBTestCase {
func testFetchCursor() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
func test<C: Cursor>(_ cursor: C) throws where C.Element == Fetched {
func test(_ cursor: RecordCursor<Fetched>) throws {
var record = try cursor.next()!
XCTAssertEqual(record.firstName, "Arthur")
XCTAssertEqual(record.lastName, "Martin")
@@ -65,7 +65,7 @@ class RowConvertibleTests: GRDBTestCase {
let customError = NSError(domain: "Custom", code: 0xDEAD)
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
try dbQueue.inDatabase { db in
func test<C: Cursor>(_ cursor: C, sql: String) throws where C.Element == Fetched {
func test(_ cursor: RecordCursor<Fetched>, sql: String) throws {
do {
_ = try cursor.next()
XCTFail()
@@ -106,7 +106,7 @@ class RowConvertibleTests: GRDBTestCase {
func testFetchCursorCompilationFailure() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
func test<C: Cursor>(_ cursor: @autoclosure () throws -> C, sql: String) throws where C.Element == Fetched {
func test(_ cursor: @autoclosure () throws -> RecordCursor<Fetched>, sql: String) throws {
do {
_ = try cursor()
XCTFail()
@@ -86,7 +86,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
func testFetchCursor() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
func test<C: Cursor>(_ cursor: C) throws where C.Element == Fetched {
func test(_ cursor: ColumnCursor<Fetched>) throws {
var i = try cursor.next()!
XCTAssertEqual(i.int, 1)
XCTAssertTrue(i.fast)
@@ -120,7 +120,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
let customError = NSError(domain: "Custom", code: 0xDEAD)
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
try dbQueue.inDatabase { db in
func test<C: Cursor>(_ cursor: C, sql: String) throws where C.Element == Fetched {
func test(_ cursor: ColumnCursor<Fetched>, sql: String) throws {
do {
_ = try cursor.next()
XCTFail()
@@ -161,7 +161,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
func testFetchCursorCompilationFailure() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
func test<C: Cursor>(_ cursor: @autoclosure () throws -> C, sql: String) throws where C.Element == Fetched {
func test(_ cursor: @autoclosure () throws -> ColumnCursor<Fetched>, sql: String) throws {
do {
_ = try cursor()
XCTFail()
@@ -426,7 +426,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
func testOptionalFetchCursor() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
func test<C: Cursor>(_ cursor: C) throws where C.Element == Fetched? {
func test(_ cursor: NullableColumnCursor<Fetched>) throws {
let i = try cursor.next()!
XCTAssertEqual(i!.int, 1)
XCTAssertTrue(i!.fast)
@@ -456,7 +456,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
func testOptionalFetchCursorCompilationFailure() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
func test<C: Cursor>(_ cursor: @autoclosure () throws -> C, sql: String) throws where C.Element == Fetched? {
func test(_ cursor: @autoclosure () throws -> NullableColumnCursor<Fetched>, sql: String) throws {
do {
_ = try cursor()
XCTFail()