Skip to content

Commit 13e8a5c

Browse files
committed
Update unit tests
1 parent 0983485 commit 13e8a5c

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

Tests/CoreModelTests/CoreDataTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ struct CoreDataTests {
9494

9595
let rentalUnitFetchRequest = FetchRequest(
9696
entity: Campground.Unit.entityName,
97-
predicate: Campground.Unit.CodingKeys.campground.stringValue.compare(.equalTo, .relationship(.toOne(ObjectID(campground.id))))
97+
predicate: Campground.Unit.CodingKeys.campground.compare(.equalTo, .relationship(.toOne(ObjectID(campground.id))))
9898
)
9999
let rentalUnitIDs = try store.viewContext.fetchID(rentalUnitFetchRequest)
100100
#expect(rentalUnitIDs == campground.units.map { ObjectID($0) })

Tests/CoreModelTests/PredicateTests.swift

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ struct PredicateTests {
2222

2323
@Test func predicate1() {
2424

25-
let predicate: FetchRequest.Predicate = "id" > Int64(0)
25+
let predicate: FetchRequest.Predicate = Person.CodingKeys.id > Int64(0)
2626
&& "id" != Int64(99)
27-
&& "name".compare(.beginsWith, .attribute(.string("C")))
28-
&& "name".compare(.contains, [.diacriticInsensitive, .caseInsensitive], .attribute(.string("COLE")))
27+
&& Person.CodingKeys.name.compare(.beginsWith, .attribute(.string("C")))
28+
&& Person.CodingKeys.name.compare(.contains, [.diacriticInsensitive, .caseInsensitive], .attribute(.string("COLE")))
2929

3030
#expect(predicate.description == #"((id > 0 AND id != 99) AND name BEGINSWITH "C") AND name CONTAINS[cd] "COLE""#)
3131
}
@@ -71,7 +71,7 @@ struct PredicateTests {
7171

7272
let future = Date.distantFuture
7373

74-
let predicate: FetchRequest.Predicate = ("name").compare(.matches, [.caseInsensitive], .attribute(.string(#"event \d"#))) && [
74+
let predicate: FetchRequest.Predicate = Person.CodingKeys.name.compare(.matches, [.caseInsensitive], .attribute(.string(#"event \d"#))) && [
7575
("start") < future,
7676
("speakers.@count") > 0
7777
]
@@ -104,6 +104,11 @@ internal extension PredicateTests {
104104
self.id = id
105105
self.name = name
106106
}
107+
108+
enum CodingKeys: String, CodingKey {
109+
case id
110+
case name
111+
}
107112
}
108113

109114
struct Event: Equatable, Hashable, Codable {
@@ -119,6 +124,13 @@ internal extension PredicateTests {
119124
self.start = start
120125
self.speakers = speakers
121126
}
127+
128+
enum CodingKeys: String, CodingKey {
129+
case id
130+
case name
131+
case start
132+
case speakers
133+
}
122134
}
123135
}
124136

0 commit comments

Comments
 (0)