mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
Failing test for #561
This commit is contained in:
1 parent
ff2f8bd88e
commit
036e236dc0
1 file changed
+37
-11
@@ -15,24 +15,50 @@ class DatabasePoolCollationTests: GRDBTestCase {
|
||||
}
|
||||
dbPool.add(collation: collation1)
|
||||
|
||||
try dbPool.write { db in
|
||||
try db.execute(sql: "CREATE TABLE items (text TEXT COLLATE collation1)")
|
||||
try db.execute(sql: "INSERT INTO items (text) VALUES ('a')")
|
||||
try db.execute(sql: "INSERT INTO items (text) VALUES ('b')")
|
||||
try db.execute(sql: "INSERT INTO items (text) VALUES ('c')")
|
||||
}
|
||||
try dbPool.read { db in
|
||||
XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text"), ["a", "b", "c"])
|
||||
XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE collation1"), ["a", "b", "c"])
|
||||
}
|
||||
|
||||
let collation2 = DatabaseCollation("collation2") { (string1, string2) in
|
||||
return (string1 == string2) ? .orderedSame : ((string1 < string2) ? .orderedDescending : .orderedAscending)
|
||||
}
|
||||
dbPool.add(collation: collation2)
|
||||
|
||||
try dbPool.write { db in
|
||||
// Both collations are available in writer
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE items (text TEXT COLLATE collation2);
|
||||
INSERT INTO items (text) VALUES ('a');
|
||||
INSERT INTO items (text) VALUES ('b');
|
||||
INSERT INTO items (text) VALUES ('c');
|
||||
""")
|
||||
XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text"), ["c", "b", "a"])
|
||||
XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE collation1"), ["a", "b", "c"])
|
||||
}
|
||||
|
||||
try dbPool.read { db in
|
||||
// Both collations are available in reader
|
||||
XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text"), ["c", "b", "a"])
|
||||
XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE collation1"), ["a", "b", "c"])
|
||||
XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE collation2"), ["c", "b", "a"])
|
||||
}
|
||||
|
||||
dbPool.remove(collation: collation1)
|
||||
|
||||
do {
|
||||
// collation1 is no longer available in writer
|
||||
try dbPool.write { db in
|
||||
_ = try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE collation1")
|
||||
}
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
XCTAssert(error.message!.contains("collation1"))
|
||||
}
|
||||
|
||||
do {
|
||||
// collation1 is no longer available in reader
|
||||
try dbPool.read { db in
|
||||
_ = try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE collation1")
|
||||
}
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
XCTAssert(error.message!.contains("collation1"))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user