Skip to content

Commit 2efc79a

Browse files
committed
wip
1 parent e197f15 commit 2efc79a

File tree

5 files changed

+46
-38
lines changed

5 files changed

+46
-38
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ Thumbs.db
2323
!CODE_OF_CONDUCT.md
2424
!SECURITY.md
2525
!**/*.docc/**/*.md
26+
27+
28+
# SwiftLint Remote Config Cache
29+
.swiftlint/RemoteConfigCache

Package.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let package = Package(
2424
.macOS(.v15),
2525
.iOS(.v18),
2626
.tvOS(.v18),
27-
.watchOS(.v11)
27+
.watchOS(.v11),
2828
],
2929
products: [
3030
.library(
@@ -43,16 +43,16 @@ let package = Package(
4343
dependencies: [
4444
.product(name: "Standards", package: "swift-standards"),
4545
.product(name: "Formatting", package: "swift-standards"),
46-
.product(name: "ISO 9899", package: "swift-iso-9899")
46+
.product(name: "ISO 9899", package: "swift-iso-9899"),
4747
]
4848
),
4949
.testTarget(
5050
name: "Numeric Formatting".tests,
5151
dependencies: [
5252
"Numeric Formatting",
53-
.product(name: "StandardsTestSupport", package: "swift-standards")
53+
.product(name: "StandardsTestSupport", package: "swift-standards"),
5454
]
55-
)
55+
),
5656
],
5757
swiftLanguageModes: [.v6]
5858
)
@@ -63,9 +63,10 @@ extension String {
6363

6464
for target in package.targets where ![.system, .binary, .plugin].contains(target.type) {
6565
let existing = target.swiftSettings ?? []
66-
target.swiftSettings = existing + [
67-
.enableUpcomingFeature("ExistentialAny"),
68-
.enableUpcomingFeature("InternalImportsByDefault"),
69-
.enableUpcomingFeature("MemberImportVisibility")
70-
]
66+
target.swiftSettings =
67+
existing + [
68+
.enableUpcomingFeature("ExistentialAny"),
69+
.enableUpcomingFeature("InternalImportsByDefault"),
70+
.enableUpcomingFeature("MemberImportVisibility"),
71+
]
7172
}

Sources/Numeric Formatting/Format.Numeric.Style.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,8 @@ extension Format.Numeric.Style {
337337
let intValue = Int64(value)
338338

339339
// If any of these features are needed, convert to Double for proper handling
340-
if scale != 1.0 || notation != .automatic || roundingRule != nil ||
341-
significantDigits != nil || minimumFractionDigits != nil ||
342-
decimalSeparatorStrategy == .always {
340+
if scale != 1.0 || notation != .automatic || roundingRule != nil || significantDigits != nil
341+
|| minimumFractionDigits != nil || decimalSeparatorStrategy == .always {
343342
return format(Double(intValue))
344343
}
345344

@@ -551,7 +550,7 @@ extension Format.Numeric.Style {
551550
}
552551

553552
// Format mantissa with trailing zeros removed
554-
let rounded = (value * 1000000).rounded() / 1000000
553+
let rounded = (value * 1_000_000).rounded() / 1_000_000
555554
let intPart = Int64(rounded)
556555
let fracPart = rounded - Double(intPart)
557556

@@ -726,6 +725,3 @@ extension Format.Numeric.Style {
726725
}
727726

728727
// MARK: - Value Extensions
729-
730-
731-

Sources/Numeric Formatting/Format.Numeric.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ public import Formatting
1515
///
1616
/// Built on ISO 9899 (C Standard Library Math) for hardware-accelerated operations.
1717
extension Format {
18-
public enum Numeric { }
18+
public enum Numeric {}
1919
}

Tests/Numeric Formatting Tests/Numeric.Formatting.Style Tests.swift

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// Comprehensive tests for Foundation-compatible numeric formatting API
55

66
import Testing
7+
78
@testable import Numeric_Formatting
89

910
@Suite
@@ -43,16 +44,16 @@ struct `Format.Numeric.Style Tests` {
4344
func `compact notation`() {
4445
#expect(1000.formatted(.number.notation(.compactName)) == "1K")
4546
#expect(1500.formatted(.number.notation(.compactName)) == "1.5K")
46-
#expect(1000000.formatted(.number.notation(.compactName)) == "1M")
47-
#expect(1500000.formatted(.number.notation(.compactName)) == "1.5M")
48-
#expect(1000000000.formatted(.number.notation(.compactName)) == "1B")
47+
#expect(1_000_000.formatted(.number.notation(.compactName)) == "1M")
48+
#expect(1_500_000.formatted(.number.notation(.compactName)) == "1.5M")
49+
#expect(1_000_000_000.formatted(.number.notation(.compactName)) == "1B")
4950
}
5051

5152
@Test
5253
func `scientific notation`() {
5354
#expect(1234.formatted(.number.notation(.scientific)) == "1.234E3")
5455
#expect(0.00001.formatted(.number.notation(.scientific)) == "1E-5")
55-
#expect(1000000.formatted(.number.notation(.scientific)) == "1E6")
56+
#expect(1_000_000.formatted(.number.notation(.scientific)) == "1E6")
5657
}
5758
}
5859

@@ -97,13 +98,13 @@ struct `Format.Numeric.Style Tests` {
9798

9899
@Test
99100
func `automatic grouping`() {
100-
#expect(1234567.formatted(.number.grouping(.automatic)) == "1,234,567")
101+
#expect(1_234_567.formatted(.number.grouping(.automatic)) == "1,234,567")
101102
#expect(100.formatted(.number.grouping(.automatic)) == "100")
102103
}
103104

104105
@Test
105106
func `never use grouping`() {
106-
#expect(1234567.formatted(.number.grouping(.never)) == "1234567")
107+
#expect(1_234_567.formatted(.number.grouping(.never)) == "1234567")
107108
#expect(1000.formatted(.number.grouping(.never)) == "1000")
108109
}
109110
}
@@ -215,8 +216,13 @@ struct `Format.Numeric.Style Tests` {
215216

216217
@Test
217218
func `combined with ranges`() {
218-
#expect(42.5.formatted(.number.precision(.integerAndFractionLength(integerLimits: 2...4, fractionLimits: 1...3))) == "42.5")
219-
#expect(1.formatted(.number.precision(.integerAndFractionLength(integerLimits: 2...4, fractionLimits: 1...3))) == "01.0")
219+
#expect(
220+
42.5.formatted(
221+
.number.precision(.integerAndFractionLength(integerLimits: 2...4, fractionLimits: 1...3))) == "42.5"
222+
)
223+
#expect(
224+
1.formatted(.number.precision(.integerAndFractionLength(integerLimits: 2...4, fractionLimits: 1...3)))
225+
== "01.0")
220226
}
221227
}
222228

@@ -322,7 +328,7 @@ struct `Format.Numeric.Style Tests` {
322328
@Test
323329
func `compact with precision`() {
324330
#expect(1500.formatted(.number.notation(.compactName).precision(.fractionLength(2))) == "1.50K")
325-
#expect(1234567.formatted(.number.notation(.compactName).precision(.fractionLength(1))) == "1.2M")
331+
#expect(1_234_567.formatted(.number.notation(.compactName).precision(.fractionLength(1))) == "1.2M")
326332
}
327333

328334
@Test
@@ -332,20 +338,21 @@ struct `Format.Numeric.Style Tests` {
332338

333339
@Test
334340
func `grouping with sign display`() {
335-
#expect(1234567.formatted(.number.grouping(.automatic).sign(strategy: .always())) == "+1,234,567")
336-
#expect((-1234567).formatted(.number.grouping(.automatic).sign(strategy: .always())) == "-1,234,567")
341+
#expect(1_234_567.formatted(.number.grouping(.automatic).sign(strategy: .always())) == "+1,234,567")
342+
#expect((-1_234_567).formatted(.number.grouping(.automatic).sign(strategy: .always())) == "-1,234,567")
337343
}
338344

339345
@Test
340346
func `full formatting chain`() {
341-
#expect(1234.5678.formatted(
342-
.number
343-
.notation(.automatic)
344-
.grouping(.automatic)
345-
.precision(.fractionLength(2))
346-
.sign(strategy: .always())
347-
.decimalSeparator(strategy: .always)
348-
) == "+1,234.57")
347+
#expect(
348+
1234.5678.formatted(
349+
.number
350+
.notation(.automatic)
351+
.grouping(.automatic)
352+
.precision(.fractionLength(2))
353+
.sign(strategy: .always())
354+
.decimalSeparator(strategy: .always)
355+
) == "+1,234.57")
349356
}
350357
}
351358

@@ -359,7 +366,7 @@ struct `Format.Numeric.Style Tests` {
359366
let int8: Int8 = 42
360367
let int16: Int16 = 1000
361368
let int32: Int32 = 100000
362-
let int64: Int64 = 1000000
369+
let int64: Int64 = 1_000_000
363370

364371
#expect(int8.formatted(.number) == "42")
365372
#expect(int16.formatted(.number.grouping(.automatic)) == "1,000")
@@ -371,7 +378,7 @@ struct `Format.Numeric.Style Tests` {
371378
func `UInt types`() {
372379
let uint8: UInt8 = 255
373380
let uint16: UInt16 = 65535
374-
let uint32: UInt32 = 4294967295
381+
let uint32: UInt32 = 4_294_967_295
375382

376383
#expect(uint8.formatted(.number) == "255")
377384
#expect(uint16.formatted(.number.grouping(.automatic)) == "65,535")

0 commit comments

Comments
 (0)