1010//
1111//===----------------------------------------------------------------------===//
1212
13+ import Testing
14+
1315#if FOUNDATION_FRAMEWORK
1416@testable import Foundation
1517#else
1618@testable import FoundationEssentials
1719@testable import FoundationInternationalization
1820#endif // FOUNDATION_FRAMEWORK
1921
20- #if canImport(TestSupport)
21- import TestSupport
22- #endif
23-
2422extension String {
2523 var _scalarViewDescription : String {
2624 return unicodeScalars. map { " \\ u{ \( String ( $0. value, radix: 16 , uppercase: true ) ) } " } . joined ( )
2725 }
2826}
2927
30- final class StringLocaleTests : XCTestCase {
28+ @Suite ( " String (Locale) " )
29+ private struct StringLocaleTests {
3130
32- func testCapitalize_localized ( ) {
31+ @ Test func capitalize_localized ( ) {
3332 var locale : Locale ?
34- // `extension StringProtocol { func capitalized(with: Locale) }` is
35- // declared twice on Darwin: once in FoundationInternationalization
36- // and once in SDK. Therefore it is ambiguous when building the package
37- // on Darwin. Workaround it by testing the internal implementation.
38- func test( _ string: String , _ expected: String , file: StaticString = #filePath, line: UInt = #line) {
39- XCTAssertEqual ( string. _capitalized ( with: locale) , expected, file: file, line: line)
33+ func test( _ string: String , _ expected: String , sourceLocation: SourceLocation = #_sourceLocation) {
34+ #expect( string. capitalized ( with: locale) == expected, sourceLocation: sourceLocation)
4035 }
4136
4237 do {
@@ -84,18 +79,18 @@ final class StringLocaleTests: XCTestCase {
8479 }
8580 }
8681
87- func testUppercase_localized ( ) {
82+ @Test func uppercase_localized ( ) {
8883
89- func test( _ localeID: String ? , _ string: String , _ expected: String , file : StaticString = #filePath , line : UInt = #line ) {
84+ func test( _ localeID: String ? , _ string: String , _ expected: String , sourceLocation : SourceLocation = #_sourceLocation ) {
9085 let locale : Locale ?
9186 if let localeID {
9287 locale = Locale ( identifier: localeID)
9388 } else {
9489 locale = nil
9590 }
96- let actual = string. _uppercased ( with: locale)
91+ let actual = string. uppercased ( with: locale)
9792
98- XCTAssertEqual ( actual, expected, " actual: \( actual. _scalarViewDescription) , expected: \( expected. _scalarViewDescription) " , file : file , line : line )
93+ #expect ( actual == expected, " actual: \( actual. _scalarViewDescription) , expected: \( expected. _scalarViewDescription) " , sourceLocation : sourceLocation )
9994 }
10095
10196 test( nil , " ffl " , " FFL " ) // 0xFB04
@@ -128,17 +123,17 @@ final class StringLocaleTests: XCTestCase {
128123 test( " el_GR " , " \u{03B9} \u{0308} \u{0301} " , " \u{0399} \u{0308} " )
129124 }
130125
131- func testLowercase_localized ( ) {
132- func test( _ localeID: String ? , _ string: String , _ expected: String , file : StaticString = #filePath , line : UInt = #line ) {
126+ @Test func lowercase_localized ( ) {
127+ func test( _ localeID: String ? , _ string: String , _ expected: String , sourceLocation : SourceLocation = #_sourceLocation ) {
133128 let locale : Locale ?
134129 if let localeID {
135130 locale = Locale ( identifier: localeID)
136131 } else {
137132 locale = nil
138133 }
139- let actual = string. _lowercased ( with: locale)
134+ let actual = string. lowercased ( with: locale)
140135
141- XCTAssertEqual ( actual, expected, " actual: \( actual. _scalarViewDescription) , expected: \( expected. _scalarViewDescription) " , file : file , line : line )
136+ #expect ( actual == expected, " actual: \( actual. _scalarViewDescription) , expected: \( expected. _scalarViewDescription) " , sourceLocation : sourceLocation )
142137 }
143138
144139 test( nil , " ᾈ " , " ᾀ " ) // 0x1F88
@@ -156,8 +151,9 @@ final class StringLocaleTests: XCTestCase {
156151 test( " tr " , " İİ " , " ii " )
157152 }
158153
159- func testFuzzFailure( ) throws {
160- let input = String ( data: Data ( base64Encoded: " 77+977+977+977+977+977+977+977+977+977+9Cg== " ) !, encoding: . utf8) !
154+ @Test func fuzzFailure( ) throws {
155+ let data = try #require( Data ( base64Encoded: " 77+977+977+977+977+977+977+977+977+977+9Cg== " ) )
156+ let input = try #require( String ( data: data, encoding: . utf8) )
161157 _ = input. lowercased ( with: Locale ( identifier: " en_US " ) )
162158 _ = input. capitalized ( with: Locale ( identifier: " en_US " ) )
163159 _ = input. capitalized ( with: Locale ( identifier: " en_US " ) )
0 commit comments