@@ -683,7 +683,7 @@ extension ProgressManager.Properties {
683
683
}
684
684
685
685
686
- @Suite ( " Progress Manager String Properties " , . tags( . progressManager) ) struct ProgressManagerStringPropertiesTests {
686
+ @Suite ( " Progress Manager String (Retaining) Properties " , . tags( . progressManager) ) struct ProgressManagerStringPropertiesTests {
687
687
688
688
func doSomething( subprogress: consuming Subprogress ) async {
689
689
let manager = subprogress. start ( totalCount: 1 )
@@ -851,3 +851,98 @@ extension ProgressManager.Properties {
851
851
#expect( manager. summary ( of: ProgressManager . Properties. ProcessingFile. self) == [ " Howdy.jpg " ] )
852
852
}
853
853
}
854
+
855
+
856
+ extension ProgressManager . Properties {
857
+ var imageURL : ImageURL . Type { ImageURL . self }
858
+ struct ImageURL : Sendable , ProgressManager . Property {
859
+
860
+ typealias Value = URL ?
861
+
862
+ typealias Summary = [ URL ? ]
863
+
864
+ static var key : String { " MyApp.ImageURL " }
865
+
866
+ static var defaultValue : URL ? { nil }
867
+
868
+ static var defaultSummary : [ URL ? ] { [ ] }
869
+
870
+ static func reduce( into summary: inout [ URL ? ] , value: URL ? ) {
871
+ summary. append ( value)
872
+ }
873
+
874
+ static func merge( _ summary1: [ URL ? ] , _ summary2: [ URL ? ] ) -> [ URL ? ] {
875
+ summary1 + summary2
876
+ }
877
+
878
+ static func terminate( _ parentSummary: [ URL ? ] , _ childSummary: [ URL ? ] ) -> [ URL ? ] {
879
+ parentSummary
880
+ }
881
+ }
882
+ }
883
+
884
+ @Suite ( " Progress Manager Image URL (Non-retaining) Properties " , . tags( . progressManager) ) struct ProgressManagerImageURLProperties {
885
+ func doSomething( subprogress: consuming Subprogress ) async {
886
+ let manager = subprogress. start ( totalCount: 1 )
887
+
888
+ manager. withProperties { properties in
889
+ properties. completedCount = 1
890
+ properties. imageURL = URL ( string: " 112.jpg " )
891
+ }
892
+
893
+ #expect( manager. summary ( of: ProgressManager . Properties. ImageURL. self) == [ URL ( string: " 112.jpg " ) ] )
894
+ }
895
+
896
+ func doSomethingTwoLevels( subprogress: consuming Subprogress ) async {
897
+ let manager = subprogress. start ( totalCount: 2 )
898
+
899
+ manager. withProperties { properties in
900
+ properties. completedCount = 1
901
+ properties. imageURL = URL ( string: " 114.jpg " )
902
+ }
903
+
904
+ await doSomething ( subprogress: manager. subprogress ( assigningCount: 1 ) )
905
+
906
+ #expect( manager. summary ( of: ProgressManager . Properties. ImageURL. self) == [ URL ( string: " 114.jpg " ) ] )
907
+ }
908
+
909
+ @Test func discreteManager( ) async throws {
910
+ let manager = ProgressManager ( totalCount: 1 )
911
+
912
+ manager. withProperties { properties in
913
+ properties. imageURL = URL ( string: " 116.jpg " )
914
+ }
915
+
916
+ #expect( manager. fractionCompleted == 0.0 )
917
+ #expect( manager. summary ( of: ProgressManager . Properties. ImageURL. self) == [ URL ( string: " 116.jpg " ) ] )
918
+ }
919
+
920
+ @Test func twoLevelsManager( ) async throws {
921
+ let manager = ProgressManager ( totalCount: 2 )
922
+
923
+ manager. withProperties { properties in
924
+ properties. completedCount = 1
925
+ properties. imageURL = URL ( string: " 116.jpg " )
926
+ }
927
+
928
+ await doSomething ( subprogress: manager. subprogress ( assigningCount: 1 ) )
929
+
930
+ #expect( manager. fractionCompleted == 1.0 )
931
+ #expect( manager. summary ( of: ProgressManager . Properties. ImageURL. self) == [ URL ( string: " 116.jpg " ) ] )
932
+ }
933
+
934
+ @Test func threeLevelsManager( ) async throws {
935
+ let manager = ProgressManager ( totalCount: 2 )
936
+
937
+ manager. withProperties { properties in
938
+ properties. completedCount = 1
939
+ properties. imageURL = URL ( string: " 116.jpg " )
940
+ }
941
+
942
+ await doSomethingTwoLevels ( subprogress: manager. subprogress ( assigningCount: 1 ) )
943
+
944
+ #expect( manager. fractionCompleted == 1.0 )
945
+ #expect( manager. summary ( of: ProgressManager . Properties. ImageURL. self) == [ URL ( string: " 116.jpg " ) ] )
946
+ }
947
+ }
948
+
0 commit comments