44// Comprehensive tests for Foundation-compatible numeric formatting API
55
66import 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