Skip to content

Commit cecd0a3

Browse files
committed
code change for defaultValue
1 parent 872fcdc commit cecd0a3

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

Sources/FoundationEssentials/ProgressReporter/ProgressReporter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ internal struct AnyMetatypeWrapper: Hashable, Equatable, Sendable {
173173
if let val = state.otherProperties[AnyMetatypeWrapper(metatype: P.self)] as? P.T {
174174
return val
175175
} else {
176-
return P.Type.defaultValue
176+
return P.defaultValue
177177
}
178178
}
179179

Sources/FoundationInternationalization/ProgressReporter/ProgressReporter+FileFormatStyle.swift

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,15 @@ extension ProgressReporter.FileFormatStyle: FormatStyle {
9999

100100
let properties = reporter.withProperties(\.self)
101101

102-
if let totalFileCount = properties.totalFileCount {
103-
let completedFileCount = properties.completedFileCount ?? 0
104-
fileCountLSR = LocalizedStringResource("\(completedFileCount, format: IntegerFormatStyle<Int>()) of \(totalFileCount, format: IntegerFormatStyle<Int>()) files", locale: self.locale, bundle: .forClass(ProgressReporter.self))
105-
}
102+
fileCountLSR = LocalizedStringResource("\(properties.completedFileCount, format: IntegerFormatStyle<Int>()) of \(properties.totalFileCount, format: IntegerFormatStyle<Int>()) files", locale: self.locale, bundle: .forClass(ProgressReporter.self))
106103

107-
if let totalByteCount = properties.totalByteCount {
108-
let completedByteCount = properties.completedByteCount ?? 0
109-
byteCountLSR = LocalizedStringResource("\(completedByteCount, format: ByteCountFormatStyle()) of \(totalByteCount, format: ByteCountFormatStyle())", locale: self.locale, bundle: .forClass(ProgressReporter.self))
110-
}
111104

112-
if let throughput = properties.throughput {
113-
throughputLSR = LocalizedStringResource("\(throughput, format: ByteCountFormatStyle())/s", locale: self.locale, bundle: .forClass(ProgressReporter.self))
114-
}
105+
byteCountLSR = LocalizedStringResource("\(properties.completedByteCount, format: ByteCountFormatStyle()) of \(properties.totalByteCount, format: ByteCountFormatStyle())", locale: self.locale, bundle: .forClass(ProgressReporter.self))
115106

116-
if let timeRemaining = properties.estimatedTimeRemaining {
117-
timeRemainingLSR = LocalizedStringResource("\(timeRemaining, format: Duration.UnitsFormatStyle(allowedUnits: [.hours, .minutes], width: .wide)) remaining", locale: self.locale, bundle: .forClass(ProgressReporter.self))
118-
}
107+
108+
throughputLSR = LocalizedStringResource("\(properties.throughput, format: ByteCountFormatStyle())/s", locale: self.locale, bundle: .forClass(ProgressReporter.self))
109+
110+
timeRemainingLSR = LocalizedStringResource("\(properties.estimatedTimeRemaining, format: Duration.UnitsFormatStyle(allowedUnits: [.hours, .minutes], width: .wide)) remaining", locale: self.locale, bundle: .forClass(ProgressReporter.self))
119111

120112
return """
121113
\(String(localized: fileCountLSR ?? ""))

Tests/FoundationEssentialsTests/ProgressReporter/ProgressReporterTests.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class TestProgressReporter: XCTestCase {
5454
}
5555

5656
XCTAssertEqual(reporter.withProperties(\.totalFileCount), 100)
57-
XCTAssertNil(reporter.withProperties(\.completedFileCount))
5857

5958
reporter.complete(count: 100)
6059
XCTAssertEqual(reporter.fractionCompleted, 1.0)
@@ -248,13 +247,13 @@ class TestProgressReporter: XCTestCase {
248247
let childProgress1 = reporter1.subprogress(assigningCount: 3)
249248
let childReporter1 = childProgress1.reporter(totalCount: nil)
250249
childReporter1.withProperties { properties in
251-
properties.totalFileCount = 10
250+
properties.totalFileCount += 10
252251
}
253252

254253
let childProgress2 = reporter1.subprogress(assigningCount: 2)
255254
let childReporter2 = childProgress2.reporter(totalCount: nil)
256255
childReporter2.withProperties { properties in
257-
properties.totalFileCount = 10
256+
properties.totalFileCount += 10
258257
}
259258

260259
XCTAssertEqual(reporter1.withProperties(\.totalFileCount), 20)

0 commit comments

Comments
 (0)