Skip to content

Commit 231321a

Browse files
committed
add unit tests for additional properties
1 parent 01c2f77 commit 231321a

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

Tests/FoundationEssentialsTests/ProgressManager/ProgressManagerPropertiesTests.swift

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,21 @@ extension ProgressManager.Properties {
482482
#expect(manager.summary(of: ProgressManager.Properties.Counter.self) == 30)
483483
}
484484

485+
func doSomethingTwoLevels(subprogress: consuming Subprogress) async {
486+
let manager = subprogress.start(totalCount: 2)
487+
488+
manager.complete(count: 1)
489+
490+
manager.withProperties { properties in
491+
properties.counter = 15
492+
}
493+
494+
await doSomething(subprogress: manager.subprogress(assigningCount: 1))
495+
496+
#expect(manager.fractionCompleted == 1.0)
497+
#expect(manager.summary(of: ProgressManager.Properties.Counter.self) == 45)
498+
}
499+
485500
@Test func discreteManager() async throws {
486501
let manager = ProgressManager(totalCount: 1)
487502

@@ -507,9 +522,24 @@ extension ProgressManager.Properties {
507522
#expect(manager.fractionCompleted == 1.0)
508523
#expect(manager.summary(of: ProgressManager.Properties.Counter.self) == 40)
509524
}
525+
526+
@Test func threeLevelManager() async throws {
527+
let manager = ProgressManager(totalCount: 2)
528+
529+
manager.withProperties { properties in
530+
properties.completedCount += 1
531+
properties.counter += 10
532+
}
533+
534+
await doSomethingTwoLevels(subprogress: manager.subprogress(assigningCount: 1))
535+
536+
#expect(manager.fractionCompleted == 1.0)
537+
#expect(manager.summary(of: ProgressManager.Properties.Counter.self) == 55)
538+
}
510539
}
511540

512541
extension ProgressManager.Properties {
542+
513543
var justADouble: JustADouble.Type { JustADouble.self }
514544
struct JustADouble: Sendable, ProgressManager.Property {
515545

@@ -552,6 +582,19 @@ extension ProgressManager.Properties {
552582
#expect(manager.summary(of: ProgressManager.Properties.JustADouble.self) == 30.0)
553583
}
554584

585+
func doSomethingTwoLevels(subprogress: consuming Subprogress) async throws {
586+
let manager = subprogress.start(totalCount: 2)
587+
588+
manager.withProperties { properties in
589+
properties.completedCount = 1
590+
properties.justADouble = 7.0
591+
}
592+
593+
try await doSomething(subprogress: manager.subprogress(assigningCount: 1))
594+
595+
#expect(manager.summary(of: ProgressManager.Properties.JustADouble.self) == 37.0)
596+
}
597+
555598
@Test func discreteManager() async throws {
556599
let manager = ProgressManager(totalCount: 1)
557600

@@ -577,9 +620,25 @@ extension ProgressManager.Properties {
577620
#expect(manager.fractionCompleted == 1.0)
578621
#expect(manager.summary(of: ProgressManager.Properties.JustADouble.self) == 110.0)
579622
}
623+
624+
@Test func threeLevelManager() async throws {
625+
626+
let manager = ProgressManager(totalCount: 2)
627+
628+
manager.withProperties { properties in
629+
properties.completedCount += 1
630+
properties.justADouble = 80.0
631+
}
632+
633+
try await doSomethingTwoLevels(subprogress: manager.subprogress(assigningCount: 1))
634+
635+
#expect(manager.fractionCompleted == 1.0)
636+
#expect(manager.summary(of: ProgressManager.Properties.JustADouble.self) == 117.0)
637+
}
580638
}
581639

582640
extension ProgressManager.Properties {
641+
583642
var fileName: FileName.Type { FileName.self }
584643
struct FileName: Sendable, ProgressManager.Property {
585644

@@ -618,6 +677,20 @@ extension ProgressManager.Properties {
618677
#expect(manager.summary(of: ProgressManager.Properties.FileName.self) == "Melon.jpg")
619678
}
620679

680+
func doSomethingTwoLevels(subprogress: consuming Subprogress) async {
681+
let manager = subprogress.start(totalCount: 2)
682+
683+
manager.withProperties { properties in
684+
properties.completedCount = 1
685+
properties.fileName = "Cherry.jpg"
686+
}
687+
688+
await doSomething(subprogress: manager.subprogress(assigningCount: 1))
689+
690+
#expect(manager.fractionCompleted == 1.0)
691+
#expect(manager.summary(of: ProgressManager.Properties.FileName.self) == "Cherry.jpg, Melon.jpg")
692+
}
693+
621694
@Test func discreteManager() async throws {
622695
let manager = ProgressManager(totalCount: 1)
623696

@@ -644,4 +717,18 @@ extension ProgressManager.Properties {
644717
#expect(manager.fractionCompleted == 1.0)
645718
#expect(manager.summary(of: ProgressManager.Properties.FileName.self) == "Watermelon.jpg, Melon.jpg")
646719
}
720+
721+
@Test func threeLevelsManager() async throws {
722+
let manager = ProgressManager(totalCount: 2)
723+
724+
manager.withProperties { properties in
725+
properties.completedCount = 1
726+
properties.fileName = "Watermelon.jpg"
727+
}
728+
729+
await doSomethingTwoLevels(subprogress: manager.subprogress(assigningCount: 1))
730+
731+
#expect(manager.fractionCompleted == 1.0)
732+
#expect(manager.summary(of: ProgressManager.Properties.FileName.self) == "Watermelon.jpg, Cherry.jpg, Melon.jpg")
733+
}
647734
}

0 commit comments

Comments
 (0)