|
1 | 1 | #if canImport(CloudKit) |
2 | 2 | import CloudKit |
3 | | - @testable import SQLiteData |
| 3 | + import SQLiteData |
4 | 4 | import Testing |
5 | 5 |
|
6 | 6 | @Suite |
|
13 | 13 | #expect(record.modificationDate == Date(timeIntervalSinceReferenceDate: 1)) |
14 | 14 | } |
15 | 15 |
|
| 16 | + @Test func recordChangeTagOverride() { |
| 17 | + let record = CKRecord(recordType: "record", recordID: CKRecord.ID(recordName: "A")) |
| 18 | + #expect(record.recordChangeTag == nil) |
| 19 | + |
| 20 | + record._recordChangeTag = "ab" |
| 21 | + #expect(record.recordChangeTag == "ab") |
| 22 | + } |
| 23 | + |
| 24 | + @Test func copyPreservesMockSystemFields() { |
| 25 | + let record = CKRecord(recordType: "record", recordID: CKRecord.ID(recordName: "A")) |
| 26 | + record._recordChangeTag = "ab" |
| 27 | + record._modificationDate = Date(timeIntervalSinceReferenceDate: 1) |
| 28 | + |
| 29 | + let copy = record.copy() as! CKRecord |
| 30 | + #expect(copy.recordChangeTag == "ab") |
| 31 | + #expect(copy.modificationDate == Date(timeIntervalSinceReferenceDate: 1)) |
| 32 | + } |
| 33 | + |
16 | 34 | @available(iOS 17, macOS 14, tvOS 17, watchOS 10, *) |
17 | 35 | @Test func systemFieldsRepresentationRoundtrip() throws { |
18 | 36 | let record = CKRecord(recordType: "record", recordID: CKRecord.ID(recordName: "A")) |
19 | | - record._recordChangeTag = 42 |
| 37 | + record._recordChangeTag = "ab" |
20 | 38 | record._modificationDate = Date(timeIntervalSinceReferenceDate: 1) |
21 | 39 |
|
22 | 40 | let representation = CKRecord.SystemFieldsRepresentation(queryOutput: record) |
23 | 41 | let result = try #require(CKRecord.SystemFieldsRepresentation(queryBinding: representation.queryBinding)) |
24 | 42 |
|
25 | | - #expect(result.queryOutput._recordChangeTag == 42) |
| 43 | + #expect(result.queryOutput._recordChangeTag == "ab") |
26 | 44 | #expect(result.queryOutput._modificationDate == Date(timeIntervalSinceReferenceDate: 1)) |
27 | 45 | } |
28 | 46 |
|
29 | 47 | @available(iOS 17, macOS 14, tvOS 17, watchOS 10, *) |
30 | 48 | @Test func allFieldsRepresentationRoundtrip() throws { |
31 | 49 | let record = CKRecord(recordType: "record", recordID: CKRecord.ID(recordName: "A")) |
32 | | - record._recordChangeTag = 42 |
| 50 | + record._recordChangeTag = "ab" |
33 | 51 | record._modificationDate = Date(timeIntervalSinceReferenceDate: 1) |
34 | 52 |
|
35 | 53 | let representation = CKRecord._AllFieldsRepresentation(queryOutput: record) |
36 | 54 | let result = try #require(CKRecord._AllFieldsRepresentation(queryBinding: representation.queryBinding)) |
37 | 55 |
|
38 | | - #expect(result.queryOutput._recordChangeTag == 42) |
| 56 | + #expect(result.queryOutput._recordChangeTag == "ab") |
39 | 57 | #expect(result.queryOutput._modificationDate == Date(timeIntervalSinceReferenceDate: 1)) |
40 | 58 | } |
| 59 | + |
| 60 | + @Test func isNewerChangeTag() { |
| 61 | + #expect("0".isNewerChangeTag(than: nil)) |
| 62 | + |
| 63 | + #expect(!"0".isNewerChangeTag(than: "0")) |
| 64 | + #expect(!"z".isNewerChangeTag(than: "z")) |
| 65 | + |
| 66 | + #expect("1".isNewerChangeTag(than: "0")) |
| 67 | + #expect(!"0".isNewerChangeTag(than: "1")) |
| 68 | + #expect("a".isNewerChangeTag(than: "9")) |
| 69 | + #expect(!"9".isNewerChangeTag(than: "a")) |
| 70 | + #expect("z".isNewerChangeTag(than: "a")) |
| 71 | + |
| 72 | + #expect("10".isNewerChangeTag(than: "z")) |
| 73 | + #expect(!"z".isNewerChangeTag(than: "10")) |
| 74 | + #expect("100".isNewerChangeTag(than: "zz")) |
| 75 | + #expect(!"zz".isNewerChangeTag(than: "100")) |
| 76 | + } |
41 | 77 | } |
42 | 78 | #endif |
0 commit comments