@@ -6,38 +6,38 @@ class DatabaseCollationTests: GRDBTestCase {
66 func testDefaultCollations( ) throws {
77 let dbQueue = try makeDatabaseQueue ( )
88 try dbQueue. inDatabase { db in
9- try db. execute ( sql: " CREATE TABLE strings (id INTEGER PRIMARY KEY, name TEXT) " )
10- try db. execute ( sql: " INSERT INTO strings VALUES (1, '1') " )
11- try db. execute ( sql: " INSERT INTO strings VALUES (2, '2') " )
12- try db. execute ( sql: " INSERT INTO strings VALUES (3, '10') " )
13- try db. execute ( sql: " INSERT INTO strings VALUES (4, 'a') " )
14- try db. execute ( sql: " INSERT INTO strings VALUES (5, 'à') " )
15- try db. execute ( sql: " INSERT INTO strings VALUES (6, 'A') " )
16- try db. execute ( sql: " INSERT INTO strings VALUES (7, 'Z') " )
17- try db. execute ( sql: " INSERT INTO strings VALUES (8, 'z') " )
9+ try db. execute ( sql: """
10+ CREATE TABLE strings (id INTEGER PRIMARY KEY, name TEXT);
11+ INSERT INTO strings VALUES (1, '1');
12+ INSERT INTO strings VALUES (2, '2');
13+ INSERT INTO strings VALUES (3, '10');
14+ INSERT INTO strings VALUES (4, 'a');
15+ INSERT INTO strings VALUES (5, 'à');
16+ INSERT INTO strings VALUES (6, 'A');
17+ INSERT INTO strings VALUES (7, 'Z');
18+ INSERT INTO strings VALUES (8, 'z');
19+ INSERT INTO strings VALUES (9, '');
20+ INSERT INTO strings VALUES (10, NULL);
21+ INSERT INTO strings VALUES (11, x'42FF'); -- Invalid UTF8 " B� "
22+ """ )
1823
19- // Swift 4.2 and Swift 4.1 don't sort strings in the same way
20- if " z " < " à " {
21- XCTAssertEqual (
22- try Int . fetchAll ( db, sql: " SELECT id FROM strings ORDER BY name COLLATE \( DatabaseCollation . unicodeCompare. name) , id " ) ,
23- [ 1 , 3 , 2 , 6 , 7 , 4 , 8 , 5 ] )
24- } else {
25- XCTAssertEqual (
26- try Int . fetchAll ( db, sql: " SELECT id FROM strings ORDER BY name COLLATE \( DatabaseCollation . unicodeCompare. name) , id " ) ,
27- [ 1 , 3 , 2 , 6 , 7 , 4 , 5 , 8 ] )
28- }
24+ // Note that "B�" is always last. We can observe that SQLite
25+ // does not invoke the collation for invalid UTF8 strings.
26+ XCTAssertEqual (
27+ try Int . fetchAll ( db, sql: " SELECT id FROM strings ORDER BY name COLLATE \( DatabaseCollation . unicodeCompare. name) , id " ) ,
28+ [ 10 , 9 , 1 , 3 , 2 , 6 , 7 , 4 , 8 , 5 , 11 ] )
2929 XCTAssertEqual (
3030 try Int . fetchAll ( db, sql: " SELECT id FROM strings ORDER BY name COLLATE \( DatabaseCollation . caseInsensitiveCompare. name) , id " ) ,
31- [ 1 , 3 , 2 , 4 , 6 , 5 , 7 , 8 ] )
31+ [ 10 , 9 , 1 , 3 , 2 , 4 , 6 , 5 , 7 , 8 , 11 ] )
3232 XCTAssertEqual (
3333 try Int . fetchAll ( db, sql: " SELECT id FROM strings ORDER BY name COLLATE \( DatabaseCollation . localizedCaseInsensitiveCompare. name) , id " ) ,
34- [ 1 , 3 , 2 , 4 , 6 , 5 , 7 , 8 ] )
34+ [ 10 , 9 , 1 , 3 , 2 , 4 , 6 , 5 , 7 , 8 , 11 ] )
3535 XCTAssertEqual (
3636 try Int . fetchAll ( db, sql: " SELECT id FROM strings ORDER BY name COLLATE \( DatabaseCollation . localizedCompare. name) , id " ) ,
37- [ 1 , 3 , 2 , 4 , 6 , 5 , 8 , 7 ] )
37+ [ 10 , 9 , 1 , 3 , 2 , 4 , 6 , 5 , 8 , 7 , 11 ] )
3838 XCTAssertEqual (
3939 try Int . fetchAll ( db, sql: " SELECT id FROM strings ORDER BY name COLLATE \( DatabaseCollation . localizedStandardCompare. name) , id " ) ,
40- [ 1 , 2 , 3 , 4 , 6 , 5 , 8 , 7 ] )
40+ [ 10 , 9 , 1 , 2 , 3 , 4 , 6 , 5 , 8 , 7 , 11 ] )
4141 }
4242 }
4343
0 commit comments