@@ -655,8 +655,8 @@ extension ProgressManager.Properties {
655
655
656
656
extension ProgressManager . Properties {
657
657
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 {
660
660
661
661
typealias Value = String ?
662
662
@@ -690,65 +690,164 @@ extension ProgressManager.Properties {
690
690
691
691
manager. withProperties { properties in
692
692
properties. completedCount += 1
693
- properties. fileName = " Melon.jpg "
693
+ properties. downloadedFile = " Melon.jpg "
694
694
}
695
695
696
696
#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 " ] )
698
698
}
699
699
700
700
func doSomethingTwoLevels( subprogress: consuming Subprogress ) async {
701
701
let manager = subprogress. start ( totalCount: 2 )
702
702
703
703
manager. withProperties { properties in
704
704
properties. completedCount = 1
705
- properties. fileName = " Cherry.jpg "
705
+ properties. downloadedFile = " Cherry.jpg "
706
706
}
707
707
708
708
await doSomething ( subprogress: manager. subprogress ( assigningCount: 1 ) )
709
709
710
710
#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 " ] )
712
712
}
713
713
714
714
@Test func discreteManager( ) async throws {
715
715
let manager = ProgressManager ( totalCount: 1 )
716
716
717
717
manager. withProperties { properties in
718
718
properties. completedCount += 1
719
- properties. fileName = " Grape.jpg "
719
+ properties. downloadedFile = " Grape.jpg "
720
720
}
721
721
722
722
#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 " ] )
725
725
}
726
726
727
727
@Test func twoLevelsManager( ) async throws {
728
728
let manager = ProgressManager ( totalCount: 2 )
729
729
730
730
manager. withProperties { properties in
731
731
properties. completedCount = 1
732
- properties. fileName = " Watermelon.jpg "
732
+ properties. downloadedFile = " Watermelon.jpg "
733
733
}
734
734
735
735
await doSomething ( subprogress: manager. subprogress ( assigningCount: 1 ) )
736
736
737
737
#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 " ] )
739
739
}
740
740
741
741
@Test func threeLevelsManager( ) async throws {
742
742
let manager = ProgressManager ( totalCount: 2 )
743
743
744
744
manager. withProperties { properties in
745
745
properties. completedCount = 1
746
- properties. fileName = " Watermelon.jpg "
746
+ properties. downloadedFile = " Watermelon.jpg "
747
747
}
748
748
749
749
await doSomethingTwoLevels ( subprogress: manager. subprogress ( assigningCount: 1 ) )
750
750
751
751
#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 " ] )
753
852
}
754
853
}
0 commit comments