Skip to content

Commit 1dec91e

Browse files
pitt500mluisbrown
authored andcommitted
Remove closure and pass UUID.incrementing as parameter on AppEnvironment (#1322)
* Remove closure and pass UUID.incrementing as parameter on AppEnvironment * Fix swift 5.6 Co-authored-by: Brandon Williams <[email protected]> (cherry picked from commit 83780f67449d7c6981d73d4fc75d17efa3435cbb) # Conflicts: # Examples/Todos/TodosTests/TodosTests.swift
1 parent f832f4d commit 1dec91e

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

Examples/Todos/TodosTests/TodosTests.swift

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class TodosTests: XCTestCase {
1414
reducer: appReducer,
1515
environment: AppEnvironment(
1616
mainQueue: self.mainQueue,
17-
uuid: { UUID.incrementing() }
17+
uuid: UUID.incrementing
1818
)
1919
)
2020

@@ -28,6 +28,21 @@ final class TodosTests: XCTestCase {
2828
at: 0
2929
)
3030
}
31+
32+
await store.send(.addTodoButtonTapped) {
33+
$0.todos = [
34+
TodoState(
35+
description: "",
36+
id: UUID(uuidString: "00000000-0000-0000-0000-000000000001")!,
37+
isComplete: false
38+
),
39+
TodoState(
40+
description: "",
41+
id: UUID(uuidString: "00000000-0000-0000-0000-000000000000")!,
42+
isComplete: false
43+
)
44+
]
45+
}
3146
}
3247

3348
func testEditTodo() async {
@@ -45,7 +60,7 @@ final class TodosTests: XCTestCase {
4560
reducer: appReducer,
4661
environment: AppEnvironment(
4762
mainQueue: self.mainQueue,
48-
uuid: { UUID.incrementing() }
63+
uuid: UUID.incrementing
4964
)
5065
)
5166

@@ -76,7 +91,7 @@ final class TodosTests: XCTestCase {
7691
reducer: appReducer,
7792
environment: AppEnvironment(
7893
mainQueue: self.mainQueue,
79-
uuid: { UUID.incrementing() }
94+
uuid: UUID.incrementing
8095
)
8196
)
8297

@@ -112,7 +127,7 @@ final class TodosTests: XCTestCase {
112127
reducer: appReducer,
113128
environment: AppEnvironment(
114129
mainQueue: self.mainQueue,
115-
uuid: { UUID.incrementing() }
130+
uuid: UUID.incrementing
116131
)
117132
)
118133

@@ -147,7 +162,7 @@ final class TodosTests: XCTestCase {
147162
reducer: appReducer,
148163
environment: AppEnvironment(
149164
mainQueue: self.mainQueue,
150-
uuid: { UUID.incrementing() }
165+
uuid: UUID.incrementing
151166
)
152167
)
153168

@@ -183,7 +198,7 @@ final class TodosTests: XCTestCase {
183198
reducer: appReducer,
184199
environment: AppEnvironment(
185200
mainQueue: self.mainQueue,
186-
uuid: { UUID.incrementing() }
201+
uuid: UUID.incrementing
187202
)
188203
)
189204

@@ -220,7 +235,7 @@ final class TodosTests: XCTestCase {
220235
reducer: appReducer,
221236
environment: AppEnvironment(
222237
mainQueue: self.mainQueue,
223-
uuid: { UUID.incrementing() }
238+
uuid: UUID.incrementing
224239
)
225240
)
226241

@@ -268,7 +283,7 @@ final class TodosTests: XCTestCase {
268283
reducer: appReducer,
269284
environment: AppEnvironment(
270285
mainQueue: self.mainQueue,
271-
uuid: { UUID.incrementing() }
286+
uuid: UUID.incrementing
272287
)
273288
)
274289

@@ -310,7 +325,7 @@ final class TodosTests: XCTestCase {
310325
reducer: appReducer,
311326
environment: AppEnvironment(
312327
mainQueue: self.mainQueue,
313-
uuid: { UUID.incrementing() }
328+
uuid: UUID.incrementing
314329
)
315330
)
316331

@@ -325,11 +340,15 @@ final class TodosTests: XCTestCase {
325340

326341
extension UUID {
327342
// A deterministic, auto-incrementing "UUID" generator for testing.
328-
static var incrementing: () -> UUID {
329-
var uuid = 0
343+
static var incrementing: @Sendable () -> UUID {
344+
class UncheckedCount: @unchecked Sendable {
345+
var value = 0
346+
func increment() { self.value += 1 }
347+
}
348+
let count = UncheckedCount()
330349
return {
331-
defer { uuid += 1 }
332-
return UUID(uuidString: "00000000-0000-0000-0000-\(String(format: "%012x", uuid))")!
350+
defer { count.increment() }
351+
return UUID(uuidString: "00000000-0000-0000-0000-\(String(format: "%012x", count.value))")!
333352
}
334353
}
335354
}

0 commit comments

Comments
 (0)