Skip to content

Commit a743288

Browse files
committed
Fix iOS build issue and add new test case
1 parent 45315ca commit a743288

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

Tests/OpenAttributeGraphCompatibilityTests/CompareValuesCompatibilityTests.swift

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,27 +106,57 @@ struct CompareValuesCompatibilityTests {
106106
struct NonPODEquatable: Equatable {
107107
init(id: Int, v1: Int) {
108108
self.id = id
109-
self.m = M(v: v1)
109+
self.wrapper = Wrapper(v: v1)
110110
}
111111

112112
var id: Int
113-
var v1: Int { m.v }
113+
var v1: Int { wrapper.v }
114114

115-
class M: Equatable {
115+
class Wrapper: Equatable {
116116
var v: Int
117117
init(v: Int) { self.v = v }
118118

119-
static func == (lhs: M, rhs: M) -> Bool {
119+
static func == (lhs: Wrapper, rhs: Wrapper) -> Bool {
120120
lhs.v == rhs.v
121121
}
122122
}
123-
var m: M
123+
private var wrapper: Wrapper
124124

125125
static func == (lhs: NonPODEquatable, rhs: NonPODEquatable) -> Bool {
126126
lhs.id == rhs.id && (lhs.v1 - rhs.v1) % 2 == 0
127127
}
128128
}
129129

130+
struct NonPODEquatableTrue: Equatable {
131+
init() {
132+
self.wrapper = Wrapper()
133+
}
134+
135+
private var wrapper: Wrapper
136+
137+
class Wrapper {}
138+
139+
static func == (lhs: NonPODEquatableTrue, rhs: NonPODEquatableTrue) -> Bool {
140+
true
141+
}
142+
}
143+
144+
struct NonPODEquatableFalse: Equatable {
145+
init() {
146+
self.wrapper = Wrapper.shared
147+
}
148+
149+
private var wrapper: Wrapper
150+
151+
class Wrapper {
152+
static let shared = Wrapper()
153+
}
154+
155+
static func == (lhs: NonPODEquatableFalse, rhs: NonPODEquatableFalse) -> Bool {
156+
false
157+
}
158+
}
159+
130160
@Test
131161
func bitwizeMode() async throws {
132162
let mode = ComparisonMode.bitwise
@@ -160,8 +190,10 @@ struct CompareValuesCompatibilityTests {
160190
#expect(compareValues(NonPODEquatable(id: 1, v1: 2), NonPODEquatable(id: 1, v1: 2), mode: mode) == false)
161191
#expect(compareValues(NonPODEquatable(id: 1, v1: 2), NonPODEquatable(id: 1, v1: 3), mode: mode) == false)
162192
#expect(compareValues(NonPODEquatable(id: 1, v1: 2), NonPODEquatable(id: 1, v1: 4), mode: mode) == false)
193+
#expect(compareValues(NonPODEquatableTrue(), NonPODEquatableTrue(), mode: mode) == false)
194+
#expect(compareValues(NonPODEquatableFalse(), NonPODEquatableFalse(), mode: mode) == true)
163195

164-
try await Task.sleep(for: .seconds(1))
196+
try await Task.sleep(nanoseconds: 1_000_000_000)
165197

166198
// layout is ready, use Equatable copmare only for non POD type when avaiable
167199
#expect(compareValues(POD(id: 1), POD(id: 1), mode: mode) == true)
@@ -180,6 +212,9 @@ struct CompareValuesCompatibilityTests {
180212
#expect(compareValues(NonPODEquatable(id: 1, v1: 2), NonPODEquatable(id: 1, v1: 2), mode: mode) == true, "Non POD type, use Equatable compare")
181213
#expect(compareValues(NonPODEquatable(id: 1, v1: 2), NonPODEquatable(id: 1, v1: 3), mode: mode) == false)
182214
#expect(compareValues(NonPODEquatable(id: 1, v1: 2), NonPODEquatable(id: 1, v1: 4), mode: mode) == true, "Non POD type, use Equatable compare")
215+
216+
#expect(compareValues(NonPODEquatableTrue(), NonPODEquatableTrue(), mode: mode) == true)
217+
#expect(compareValues(NonPODEquatableFalse(), NonPODEquatableFalse(), mode: mode) == false)
183218
}
184219

185220
@Test
@@ -200,7 +235,7 @@ struct CompareValuesCompatibilityTests {
200235
#expect(compareValues(NonPODEquatable(id: 1, v1: 2), NonPODEquatable(id: 1, v1: 3), mode: mode) == false)
201236
#expect(compareValues(NonPODEquatable(id: 1, v1: 2), NonPODEquatable(id: 1, v1: 4), mode: mode) == false)
202237

203-
try await Task.sleep(for: .seconds(1))
238+
try await Task.sleep(nanoseconds: 1_000_000_000)
204239

205240
// layout is ready, Equatable is used when avaiable
206241
#expect(compareValues(POD(id: 1), POD(id: 1), mode: mode) == true)

0 commit comments

Comments
 (0)