Skip to content

Commit 0ce022c

Browse files
committed
separate string additional properties into retaining vs non-retaining version
1 parent cb26bca commit 0ce022c

File tree

1 file changed

+112
-13
lines changed

1 file changed

+112
-13
lines changed

Tests/FoundationEssentialsTests/ProgressManager/ProgressManagerPropertiesTests.swift

Lines changed: 112 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,8 @@ extension ProgressManager.Properties {
655655

656656
extension ProgressManager.Properties {
657657

658-
var fileName: FileName.Type { FileName.self }
659-
struct FileName: Sendable, ProgressManager.Property {
658+
var downloadedFile: DownloadedFile.Type { DownloadedFile.self }
659+
struct DownloadedFile: Sendable, ProgressManager.Property {
660660

661661
typealias Value = String?
662662

@@ -690,65 +690,164 @@ extension ProgressManager.Properties {
690690

691691
manager.withProperties { properties in
692692
properties.completedCount += 1
693-
properties.fileName = "Melon.jpg"
693+
properties.downloadedFile = "Melon.jpg"
694694
}
695695

696696
#expect(manager.fractionCompleted == 1.0)
697-
#expect(manager.summary(of: ProgressManager.Properties.FileName.self) == ["Melon.jpg"])
697+
#expect(manager.summary(of: ProgressManager.Properties.DownloadedFile.self) == ["Melon.jpg"])
698698
}
699699

700700
func doSomethingTwoLevels(subprogress: consuming Subprogress) async {
701701
let manager = subprogress.start(totalCount: 2)
702702

703703
manager.withProperties { properties in
704704
properties.completedCount = 1
705-
properties.fileName = "Cherry.jpg"
705+
properties.downloadedFile = "Cherry.jpg"
706706
}
707707

708708
await doSomething(subprogress: manager.subprogress(assigningCount: 1))
709709

710710
#expect(manager.fractionCompleted == 1.0)
711-
#expect(manager.summary(of: ProgressManager.Properties.FileName.self) == ["Cherry.jpg", "Melon.jpg"])
711+
#expect(manager.summary(of: ProgressManager.Properties.DownloadedFile.self) == ["Cherry.jpg", "Melon.jpg"])
712712
}
713713

714714
@Test func discreteManager() async throws {
715715
let manager = ProgressManager(totalCount: 1)
716716

717717
manager.withProperties { properties in
718718
properties.completedCount += 1
719-
properties.fileName = "Grape.jpg"
719+
properties.downloadedFile = "Grape.jpg"
720720
}
721721

722722
#expect(manager.fractionCompleted == 1.0)
723-
#expect(manager.withProperties { $0.fileName } == "Grape.jpg")
724-
#expect(manager.summary(of: ProgressManager.Properties.FileName.self) == ["Grape.jpg"])
723+
#expect(manager.withProperties { $0.downloadedFile } == "Grape.jpg")
724+
#expect(manager.summary(of: ProgressManager.Properties.DownloadedFile.self) == ["Grape.jpg"])
725725
}
726726

727727
@Test func twoLevelsManager() async throws {
728728
let manager = ProgressManager(totalCount: 2)
729729

730730
manager.withProperties { properties in
731731
properties.completedCount = 1
732-
properties.fileName = "Watermelon.jpg"
732+
properties.downloadedFile = "Watermelon.jpg"
733733
}
734734

735735
await doSomething(subprogress: manager.subprogress(assigningCount: 1))
736736

737737
#expect(manager.fractionCompleted == 1.0)
738-
#expect(manager.summary(of: ProgressManager.Properties.FileName.self) == ["Watermelon.jpg", "Melon.jpg"])
738+
#expect(manager.summary(of: ProgressManager.Properties.DownloadedFile.self) == ["Watermelon.jpg", "Melon.jpg"])
739739
}
740740

741741
@Test func threeLevelsManager() async throws {
742742
let manager = ProgressManager(totalCount: 2)
743743

744744
manager.withProperties { properties in
745745
properties.completedCount = 1
746-
properties.fileName = "Watermelon.jpg"
746+
properties.downloadedFile = "Watermelon.jpg"
747747
}
748748

749749
await doSomethingTwoLevels(subprogress: manager.subprogress(assigningCount: 1))
750750

751751
#expect(manager.fractionCompleted == 1.0)
752-
#expect(manager.summary(of: ProgressManager.Properties.FileName.self) == ["Watermelon.jpg", "Cherry.jpg", "Melon.jpg"])
752+
#expect(manager.summary(of: ProgressManager.Properties.DownloadedFile.self) == ["Watermelon.jpg", "Cherry.jpg", "Melon.jpg"])
753+
}
754+
}
755+
756+
extension ProgressManager.Properties {
757+
758+
var processingFile: ProcessingFile.Type { ProcessingFile.self }
759+
struct ProcessingFile: Sendable, ProgressManager.Property {
760+
761+
typealias Value = String?
762+
763+
typealias Summary = [String?]
764+
765+
static var key: String { return "ProcessingFile" }
766+
767+
static var defaultValue: String? { return "" }
768+
769+
static var defaultSummary: [String?] { return [] }
770+
771+
static func reduce(into summary: inout [String?], value: String?) {
772+
summary.append(value)
773+
}
774+
775+
static func merge(_ summary1: [String?], _ summary2: [String?]) -> [String?] {
776+
return summary1 + summary2
777+
}
778+
779+
static func terminate(_ parentSummary: [String?], _ childSummary: [String?]) -> [String?] {
780+
return parentSummary
781+
}
782+
}
783+
}
784+
785+
@Suite("Progress Manager String (Non-retaining) Properties", .tags(.progressManager)) struct ProgressManagerStringNonRetainingProperties {
786+
787+
func doSomething(subprogress: consuming Subprogress) async {
788+
let manager = subprogress.start(totalCount: 1)
789+
790+
manager.withProperties { properties in
791+
properties.completedCount += 1
792+
properties.processingFile = "Hello.jpg"
793+
}
794+
795+
#expect(manager.fractionCompleted == 1.0)
796+
#expect(manager.summary(of: ProgressManager.Properties.ProcessingFile.self) == ["Hello.jpg"])
797+
}
798+
799+
func doSomethingTwoLevels(subprogress: consuming Subprogress) async {
800+
let manager = subprogress.start(totalCount: 2)
801+
802+
manager.withProperties { properties in
803+
properties.completedCount = 1
804+
properties.processingFile = "Hi.jpg"
805+
}
806+
807+
await doSomething(subprogress: manager.subprogress(assigningCount: 1))
808+
809+
#expect(manager.fractionCompleted == 1.0)
810+
#expect(manager.summary(of: ProgressManager.Properties.ProcessingFile.self) == ["Hi.jpg"])
811+
}
812+
813+
@Test func discreteManager() async throws {
814+
let manager = ProgressManager(totalCount: 1)
815+
816+
manager.withProperties { properties in
817+
properties.completedCount += 1
818+
properties.processingFile = "Howdy.jpg"
819+
}
820+
821+
#expect(manager.fractionCompleted == 1.0)
822+
#expect(manager.withProperties { $0.processingFile } == "Howdy.jpg")
823+
#expect(manager.summary(of: ProgressManager.Properties.ProcessingFile.self) == ["Howdy.jpg"])
824+
}
825+
826+
@Test func twoLevelsManager() async throws {
827+
let manager = ProgressManager(totalCount: 2)
828+
829+
manager.withProperties { properties in
830+
properties.completedCount = 1
831+
properties.processingFile = "Howdy.jpg"
832+
}
833+
834+
await doSomething(subprogress: manager.subprogress(assigningCount: 1))
835+
836+
#expect(manager.fractionCompleted == 1.0)
837+
#expect(manager.summary(of: ProgressManager.Properties.ProcessingFile.self) == ["Howdy.jpg"])
838+
}
839+
840+
@Test func threeLevelsManager() async throws {
841+
let manager = ProgressManager(totalCount: 2)
842+
843+
manager.withProperties { properties in
844+
properties.completedCount = 1
845+
properties.processingFile = "Howdy.jpg"
846+
}
847+
848+
await doSomethingTwoLevels(subprogress: manager.subprogress(assigningCount: 1))
849+
850+
#expect(manager.fractionCompleted == 1.0)
851+
#expect(manager.summary(of: ProgressManager.Properties.ProcessingFile.self) == ["Howdy.jpg"])
753852
}
754853
}

0 commit comments

Comments
 (0)