Skip to content

Commit 2467de9

Browse files
committed
fix typo + add unit tests for fileURL
1 parent 7c319f9 commit 2467de9

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

Sources/FoundationEssentials/ProgressManager/ProgressManager+Values.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ extension ProgressManager {
172172
}
173173
}
174174

175-
public subscript(dyanamicMember key: KeyPath<ProgressManager.Properties, ProgressManager.Properties.FileURL.Type>) -> URL? {
175+
public subscript(dynamicMember key: KeyPath<ProgressManager.Properties, ProgressManager.Properties.FileURL.Type>) -> URL? {
176176
get {
177177
return state.fileURL
178178
}

Tests/FoundationEssentialsTests/ProgressManager/ProgressManagerPropertiesTests.swift

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,66 @@ import Testing
376376
}
377377

378378
}
379+
380+
@Suite("Progress Manager File URL Properties") struct ProgressManagerFileURLTests {
381+
382+
func doSomething(subprogress: consuming Subprogress) async {
383+
let manager = subprogress.start(totalCount: 1)
384+
385+
manager.withProperties { properties in
386+
properties.completedCount += 1
387+
properties.fileURL = URL(string: "https://www.kittens.com")
388+
}
389+
390+
#expect(manager.fractionCompleted == 1.0)
391+
#expect(manager.summary(of: ProgressManager.Properties.FileURL.self) == [URL(string: "https://www.kittens.com")])
392+
}
393+
394+
@Test func discreteManager() async throws {
395+
let manager = ProgressManager(totalCount: 1)
396+
397+
manager.withProperties { properties in
398+
properties.completedCount += 1
399+
properties.fileURL = URL(string: "https://www.cats.com")
400+
}
401+
402+
#expect(manager.fractionCompleted == 1.0)
403+
#expect(manager.summary(of: ProgressManager.Properties.FileURL.self) == [URL(string: "https://www.cats.com")])
404+
}
405+
406+
@Test func twoLevelManagerWithFinishedChild() async throws {
407+
let manager = ProgressManager(totalCount: 2)
408+
409+
manager.withProperties { properties in
410+
properties.completedCount = 1
411+
properties.fileURL = URL(string: "https://www.cats.com")
412+
}
413+
414+
await doSomething(subprogress: manager.subprogress(assigningCount: 1))
415+
416+
#expect(manager.fractionCompleted == 1.0)
417+
#expect(manager.summary(of: ProgressManager.Properties.FileURL.self) == [URL(string: "https://www.cats.com")])
418+
}
419+
420+
@Test func twoLevelManagerWithUnfinishedChild() async throws {
421+
let manager = ProgressManager(totalCount: 2)
422+
423+
manager.withProperties { properties in
424+
properties.completedCount = 1
425+
properties.fileURL = URL(string: "https://www.cats.com")
426+
}
427+
428+
let childManager = manager.subprogress(assigningCount: 1).start(totalCount: 2)
429+
430+
childManager.withProperties { properties in
431+
properties.completedCount = 1
432+
properties.fileURL = URL(string: "https://www.kittens.com")
433+
}
434+
435+
#expect(manager.fractionCompleted == 0.75)
436+
#expect(manager.summary(of: ProgressManager.Properties.FileURL.self) == [URL(string: "https://www.cats.com"), URL(string: "https://www.kittens.com")])
437+
}
438+
}
379439

380440
extension ProgressManager.Properties {
381441

0 commit comments

Comments
 (0)