55// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
66//
77//===----------------------------------------------------------------------===//
8- //
9- // RUN: %target-run-simple-swift
10- // REQUIRES: executable_test
118
12- import XCTest
9+ import Testing
1310
1411#if canImport(FoundationEssentials)
1512@testable import FoundationEssentials
16- #endif
17-
18- #if FOUNDATION_FRAMEWORK
13+ #else
1914@testable import Foundation
2015#endif
2116
@@ -27,16 +22,17 @@ import Numberick
2722import BigInt
2823#endif
2924
30- final class BinaryIntegerFormatStyleTests : XCTestCase {
25+ @Suite ( " BinaryIntegerFormatStyle " )
26+ private struct BinaryIntegerFormatStyleTests {
3127 // NSR == numericStringRepresentation
32- func checkNSR( value: some BinaryInteger , expected: String ) {
33- XCTAssertEqual ( String ( decoding: value. numericStringRepresentation. utf8, as: Unicode . ASCII. self) , expected)
28+ func checkNSR( value: some BinaryInteger , expected: String , sourceLocation : SourceLocation = #_sourceLocation ) {
29+ #expect ( String ( decoding: value. numericStringRepresentation. utf8, as: Unicode . ASCII. self) == expected)
3430 }
3531
36- func testNumericStringRepresentation_builtinIntegersLimits ( ) throws {
37- func check< I: FixedWidthInteger > ( type: I . Type = I . self, min: String , max: String ) {
38- checkNSR ( value: I . min, expected: min)
39- checkNSR ( value: I . max, expected: max)
32+ @ Test func numericStringRepresentation_builtinIntegersLimits ( ) throws {
33+ func check< I: FixedWidthInteger > ( type: I . Type = I . self, min: String , max: String , sourceLocation : SourceLocation = #_sourceLocation ) {
34+ checkNSR ( value: I . min, expected: min, sourceLocation : sourceLocation )
35+ checkNSR ( value: I . max, expected: max, sourceLocation : sourceLocation )
4036 }
4137
4238 check ( type: Int8 . self, min: " -128 " , max: " 127 " )
@@ -52,13 +48,13 @@ final class BinaryIntegerFormatStyleTests: XCTestCase {
5248 check ( type: UInt128 . self, min: " 0 " , max: " 340282366920938463463374607431768211455 " )
5349 }
5450
55- func testNumericStringRepresentation_builtinIntegersAroundDecimalMagnitude ( ) throws {
56- func check< I: FixedWidthInteger > ( type: I . Type = I . self, magnitude: String , oneLess: String , oneMore: String ) {
51+ @Test func numericStringRepresentation_builtinIntegersAroundDecimalMagnitude ( ) throws {
52+ func check< I: FixedWidthInteger > ( type: I . Type = I . self, magnitude: String , oneLess: String , oneMore: String , sourceLocation : SourceLocation = #_sourceLocation ) {
5753 var mag = I ( 1 ) ; while !mag. multipliedReportingOverflow ( by: 10 ) . overflow { mag *= 10 }
5854
59- checkNSR ( value: mag, expected: magnitude)
60- checkNSR ( value: mag - 1 , expected: oneLess)
61- checkNSR ( value: mag + 1 , expected: oneMore)
55+ checkNSR ( value: mag, expected: magnitude, sourceLocation : sourceLocation )
56+ checkNSR ( value: mag - 1 , expected: oneLess, sourceLocation : sourceLocation )
57+ checkNSR ( value: mag + 1 , expected: oneMore, sourceLocation : sourceLocation )
6258 }
6359
6460 check ( type: Int8 . self, magnitude: " 100 " , oneLess: " 99 " , oneMore: " 101 " )
@@ -105,22 +101,22 @@ final class BinaryIntegerFormatStyleTests: XCTestCase {
105101 String ( repeating: " 1234567890 " , count: 10 ) ,
106102 String ( repeating: " 1234567890 " , count: 100 ) ] {
107103 if let value = initialiser ( valueAsString) { // The test cases cover a wide range of values, that don't all fit into every type tested (i.e. the fixed-width types from Numberick).
108- XCTAssertEqual ( value. description, valueAsString) // Sanity check that it initialised from the string correctly.
104+ #expect ( value. description == valueAsString) // Sanity check that it initialised from the string correctly.
109105 checkNSR ( value: value, expected: valueAsString)
110106
111107 if I . isSigned {
112108 let negativeValueAsString = " - " + valueAsString
113109 let negativeValue = initialiser ( negativeValueAsString) !
114110
115- XCTAssertEqual ( negativeValue. description, negativeValueAsString) // Sanity check that it initialised from the string correctly.
111+ #expect ( negativeValue. description == negativeValueAsString) // Sanity check that it initialised from the string correctly.
116112 checkNSR ( value: negativeValue, expected: negativeValueAsString)
117113 }
118114 }
119115 }
120116 }
121117
122118#if canImport(Numberick)
123- func testNumericStringRepresentation_largeIntegers ( ) throws {
119+ @Test func numericStringRepresentation_largeIntegers ( ) throws {
124120 check ( type: Int128 . self, initialiser: { Int128 ( $0) } )
125121 check ( type: UInt128 . self, initialiser: { UInt128 ( $0) } )
126122
@@ -130,19 +126,19 @@ final class BinaryIntegerFormatStyleTests: XCTestCase {
130126#endif
131127
132128#if canImport(BigInt)
133- func testNumericStringRepresentation_arbitraryPrecisionIntegers ( ) throws {
129+ @Test func numericStringRepresentation_arbitraryPrecisionIntegers ( ) throws {
134130 check ( type: BigInt . self, initialiser: { BigInt ( $0) ! } )
135131 check ( type: BigUInt . self, initialiser: { BigUInt ( $0) ! } )
136132 }
137133#endif
138134#endif // canImport(Numberick) || canImport(BigInt)
139135}
140136
141- final class BinaryIntegerFormatStyleTestsUsingBinaryIntegerWords : XCTestCase {
137+ struct BinaryIntegerFormatStyleTestsUsingBinaryIntegerWords {
142138
143139 // MARK: Tests
144140
145- func testInt32 ( ) {
141+ @ Test func int32 ( ) {
146142 check ( Int32 ( truncatingIfNeeded: 0x00000000 as UInt32 ) , expectation: " 0 " )
147143 check ( Int32 ( truncatingIfNeeded: 0x03020100 as UInt32 ) , expectation: " 50462976 " )
148144 check ( Int32 ( truncatingIfNeeded: 0x7fffffff as UInt32 ) , expectation: " 2147483647 " ) // Int32.max
@@ -152,7 +148,7 @@ final class BinaryIntegerFormatStyleTestsUsingBinaryIntegerWords: XCTestCase {
152148 check ( Int32 ( truncatingIfNeeded: 0xffffffff as UInt32 ) , expectation: " -1 " )
153149 }
154150
155- func testUInt32 ( ) {
151+ @ Test func uint32 ( ) {
156152 check ( UInt32 ( truncatingIfNeeded: 0x00000000 as UInt32 ) , expectation: " 0 " ) // UInt32.min
157153 check ( UInt32 ( truncatingIfNeeded: 0x03020100 as UInt32 ) , expectation: " 50462976 " )
158154 check ( UInt32 ( truncatingIfNeeded: 0x7fffffff as UInt32 ) , expectation: " 2147483647 " )
@@ -162,7 +158,7 @@ final class BinaryIntegerFormatStyleTestsUsingBinaryIntegerWords: XCTestCase {
162158 check ( UInt32 ( truncatingIfNeeded: 0xffffffff as UInt32 ) , expectation: " 4294967295 " ) // UInt32.max
163159 }
164160
165- func testInt64 ( ) {
161+ @ Test func int64 ( ) {
166162 check ( Int64 ( truncatingIfNeeded: 0x0000000000000000 as UInt64 ) , expectation: " 0 " )
167163 check ( Int64 ( truncatingIfNeeded: 0x0706050403020100 as UInt64 ) , expectation: " 506097522914230528 " )
168164 check ( Int64 ( truncatingIfNeeded: 0x7fffffffffffffff as UInt64 ) , expectation: " 9223372036854775807 " ) // Int64.max
@@ -172,7 +168,7 @@ final class BinaryIntegerFormatStyleTestsUsingBinaryIntegerWords: XCTestCase {
172168 check ( Int64 ( truncatingIfNeeded: 0xffffffffffffffff as UInt64 ) , expectation: " -1 " )
173169 }
174170
175- func testUInt64 ( ) {
171+ @ Test func uint64 ( ) {
176172 check ( UInt64 ( truncatingIfNeeded: 0x0000000000000000 as UInt64 ) , expectation: " 0 " ) // UInt64.min
177173 check ( UInt64 ( truncatingIfNeeded: 0x0706050403020100 as UInt64 ) , expectation: " 506097522914230528 " )
178174 check ( UInt64 ( truncatingIfNeeded: 0x7fffffffffffffff as UInt64 ) , expectation: " 9223372036854775807 " )
@@ -184,7 +180,7 @@ final class BinaryIntegerFormatStyleTestsUsingBinaryIntegerWords: XCTestCase {
184180
185181 // MARK: Tests + Big Integer
186182
187- func testInt128 ( ) {
183+ @ Test func int128 ( ) {
188184 check ( x64: [ 0x0000000000000000 , 0x0000000000000000 ] as [ UInt64 ] , isSigned: true , expectation: " 0 " )
189185 check ( x64: [ 0x0706050403020100 , 0x0f0e0d0c0b0a0908 ] as [ UInt64 ] , isSigned: true , expectation: " 20011376718272490338853433276725592320 " )
190186 check ( x64: [ 0xffffffffffffffff , 0x7fffffffffffffff ] as [ UInt64 ] , isSigned: true , expectation: " 170141183460469231731687303715884105727 " ) // Int128.max
@@ -193,7 +189,7 @@ final class BinaryIntegerFormatStyleTestsUsingBinaryIntegerWords: XCTestCase {
193189 check ( x64: [ 0xffffffffffffffff , 0xffffffffffffffff ] as [ UInt64 ] , isSigned: true , expectation: " -1 " )
194190 }
195191
196- func testUInt128 ( ) {
192+ @ Test func uint128 ( ) {
197193 check ( x64: [ 0x0000000000000000 , 0x0000000000000000 ] as [ UInt64 ] , isSigned: false , expectation: " 0 " ) // UInt128.min
198194 check ( x64: [ 0x0706050403020100 , 0x0f0e0d0c0b0a0908 ] as [ UInt64 ] , isSigned: false , expectation: " 20011376718272490338853433276725592320 " )
199195 check ( x64: [ 0x0000000000000000 , 0x8000000000000000 ] as [ UInt64 ] , isSigned: false , expectation: " 170141183460469231731687303715884105728 " )
@@ -204,12 +200,12 @@ final class BinaryIntegerFormatStyleTestsUsingBinaryIntegerWords: XCTestCase {
204200
205201 // MARK: Tests + Big Integer + Miscellaneous
206202
207- func testWordsIsEmptyResultsInZero ( ) {
203+ @ Test func wordsIsEmptyResultsInZero ( ) {
208204 check ( words: [ ] as [ UInt ] , isSigned: true , expectation: " 0 " )
209205 check ( words: [ ] as [ UInt ] , isSigned: false , expectation: " 0 " )
210206 }
211207
212- func testSignExtendingDoesNotChangeTheResult ( ) {
208+ @ Test func signExtendingDoesNotChangeTheResult ( ) {
213209 check ( words: [ 0 ] as [ UInt ] , isSigned: true , expectation: " 0 " )
214210 check ( words: [ 0 , 0 ] as [ UInt ] , isSigned: true , expectation: " 0 " )
215211 check ( words: [ 0 , 0 , 0 ] as [ UInt ] , isSigned: true , expectation: " 0 " )
@@ -228,22 +224,22 @@ final class BinaryIntegerFormatStyleTestsUsingBinaryIntegerWords: XCTestCase {
228224
229225 // MARK: Assertions
230226
231- func check( _ integer: some BinaryInteger , expectation: String , file : StaticString = #filePath , line : UInt = #line ) {
232- XCTAssertEqual ( integer. description, expectation, " integer description does not match expectation " , file : file , line : line )
233- check ( ascii: integer. numericStringRepresentation. utf8, expectation: expectation, file : file , line : line )
234- check ( words: Array ( integer. words) , isSigned: type ( of: integer) . isSigned, expectation: expectation, file : file , line : line )
227+ func check( _ integer: some BinaryInteger , expectation: String , sourceLocation : SourceLocation = #_sourceLocation ) {
228+ #expect ( integer. description == expectation, " integer description does not match expectation " , sourceLocation : sourceLocation )
229+ check ( ascii: integer. numericStringRepresentation. utf8, expectation: expectation, sourceLocation : sourceLocation )
230+ check ( words: Array ( integer. words) , isSigned: type ( of: integer) . isSigned, expectation: expectation, sourceLocation : sourceLocation )
235231 }
236232
237- func check( x64: [ UInt64 ] , isSigned: Bool , expectation: String , file : StaticString = #filePath , line : UInt = #line ) {
238- check ( words: x64. flatMap ( \. words) , isSigned: isSigned, expectation: expectation, file : file , line : line )
233+ func check( x64: [ UInt64] , isSigned: Bool, expectation: String, sourceLocation : SourceLocation = #_sourceLocation ) {
234+ check ( words: x64. flatMap ( \. words) , isSigned: isSigned, expectation: expectation, sourceLocation : sourceLocation )
239235 }
240236
241- func check( words: [ UInt ] , isSigned: Bool , expectation: String , file : StaticString = #filePath , line : UInt = #line ) {
237+ func check( words: [ UInt] , isSigned: Bool, expectation: String, sourceLocation : SourceLocation = #_sourceLocation ) {
242238 let ascii = numericStringRepresentationForBinaryInteger ( words: words, isSigned: isSigned) . utf8
243- check ( ascii: ascii, expectation: expectation, file : file , line : line )
239+ check ( ascii: ascii, expectation: expectation, sourceLocation : sourceLocation )
244240 }
245241
246- func check( ascii: some Collection < UInt8 > , expectation: String , file : StaticString = #filePath , line : UInt = #line ) {
247- XCTAssertEqual ( String ( decoding: ascii, as: Unicode . ASCII. self) , expectation, file : file , line : line )
242+ func check( ascii: some Collection< UInt8 > , expectation: String, sourceLocation : SourceLocation = #_sourceLocation ) {
243+ #expect ( String ( decoding: ascii, as: Unicode . ASCII. self) == expectation, sourceLocation : sourceLocation )
248244 }
249245}
0 commit comments