5
5
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
6
6
//
7
7
//===----------------------------------------------------------------------===//
8
- //
9
- // RUN: %target-run-simple-swift
10
- // REQUIRES: executable_test
11
- // REQUIRES: objc_interop
12
8
13
- #if canImport(TestSupport)
14
- import TestSupport
15
- #endif
9
+ import Testing
16
10
17
11
#if canImport(FoundationInternationalization)
18
12
@testable import FoundationEssentials
@@ -23,68 +17,69 @@ import TestSupport
23
17
@testable import Foundation
24
18
#endif
25
19
26
- class ListFormatStyleTests : XCTestCase {
27
- func test_orList( ) {
20
+ @Suite ( " ListFormatStyle " )
21
+ private struct ListFormatStyleTests {
22
+ @Test func orList( ) {
28
23
var style : ListFormatStyle < StringStyle , [ String ] > = . list( type: . or, width: . standard)
29
24
style. locale = Locale ( identifier: " en_US " )
30
25
31
- XCTAssertEqual ( [ " one " , " two " ] . formatted ( style) , " one or two " )
32
- XCTAssertEqual ( [ " one " , " two " , " three " ] . formatted ( style) , " one, two, or three " )
26
+ #expect ( [ " one " , " two " ] . formatted ( style) == " one or two " )
27
+ #expect ( [ " one " , " two " , " three " ] . formatted ( style) == " one, two, or three " )
33
28
}
34
29
35
- func test_andList ( ) {
30
+ @ Test func andList ( ) {
36
31
var style : ListFormatStyle < StringStyle , [ String ] > = . list( type: . and, width: . standard)
37
32
style. locale = Locale ( identifier: " en_US " )
38
33
39
- XCTAssertEqual ( [ " one " , " two " ] . formatted ( style) , " one and two " )
40
- XCTAssertEqual ( [ " one " , " two " , " three " ] . formatted ( style) , " one, two, and three " )
34
+ #expect ( [ " one " , " two " ] . formatted ( style) == " one and two " )
35
+ #expect ( [ " one " , " two " , " three " ] . formatted ( style) == " one, two, and three " )
41
36
}
42
37
43
- func test_narrowList ( ) {
38
+ @ Test func narrowList ( ) {
44
39
var style : ListFormatStyle < StringStyle , [ String ] > = . list( type: . and, width: . narrow)
45
40
style. locale = Locale ( identifier: " en_US " )
46
41
47
- XCTAssertEqual ( [ " one " , " two " ] . formatted ( style) , " one, two " )
48
- XCTAssertEqual ( [ " one " , " two " , " three " ] . formatted ( style) , " one, two, three " )
42
+ #expect ( [ " one " , " two " ] . formatted ( style) == " one, two " )
43
+ #expect ( [ " one " , " two " , " three " ] . formatted ( style) == " one, two, three " )
49
44
}
50
45
51
- func test_shortList ( ) {
46
+ @ Test func shortList ( ) {
52
47
var style : ListFormatStyle < StringStyle , [ String ] > = . list( type: . and, width: . short)
53
48
style. locale = Locale ( identifier: " en_US " )
54
49
55
- XCTAssertEqual ( [ " one " , " two " ] . formatted ( style) , " one & two " )
56
- XCTAssertEqual ( [ " one " , " two " , " three " ] . formatted ( style) , " one, two, & three " )
50
+ #expect ( [ " one " , " two " ] . formatted ( style) == " one & two " )
51
+ #expect ( [ " one " , " two " , " three " ] . formatted ( style) == " one, two, & three " )
57
52
}
58
53
59
- #if FOUNDATION_FRAMEWORK // FIXME: rdar://104091257
60
- func test_leadingDotSyntax( ) {
54
+ @Test func leadingDotSyntax( ) {
61
55
let _ = [ " one " , " two " ] . formatted ( . list( type: . and) )
62
56
let _ = [ " one " , " two " ] . formatted ( )
63
57
let _ = [ 1 , 2 ] . formatted ( . list( memberStyle: . number, type: . or, width: . standard) )
64
58
}
65
- #endif
66
59
67
- func testAutoupdatingCurrentChangesFormatResults( ) {
68
- let locale = Locale . autoupdatingCurrent
69
- let list = [ " one " , " two " , " three " , " four " ]
70
-
71
- // Get a formatted result from es-ES
72
- var prefs = LocalePreferences ( )
73
- prefs. languages = [ " es-ES " ]
74
- prefs. locale = " es_ES "
75
- LocaleCache . cache. resetCurrent ( to: prefs)
76
- let formattedSpanish = list. formatted ( . list( type: . and) . locale ( locale) )
77
-
78
- // Get a formatted result from en-US
79
- prefs. languages = [ " en-US " ]
80
- prefs. locale = " en_US "
81
- LocaleCache . cache. resetCurrent ( to: prefs)
82
- let formattedEnglish = list. formatted ( . list( type: . and) . locale ( locale) )
83
-
84
- // Reset to current preferences before any possibility of failing this test
85
- LocaleCache . cache. reset ( )
86
-
87
- // No matter what 'current' was before this test was run, formattedSpanish and formattedEnglish should be different.
88
- XCTAssertNotEqual ( formattedSpanish, formattedEnglish)
60
+ @Test func autoupdatingCurrentChangesFormatResults( ) async {
61
+ await usingCurrentInternationalizationPreferences {
62
+ let locale = Locale . autoupdatingCurrent
63
+ let list = [ " one " , " two " , " three " , " four " ]
64
+
65
+ // Get a formatted result from es-ES
66
+ var prefs = LocalePreferences ( )
67
+ prefs. languages = [ " es-ES " ]
68
+ prefs. locale = " es_ES "
69
+ LocaleCache . cache. resetCurrent ( to: prefs)
70
+ let formattedSpanish = list. formatted ( . list( type: . and) . locale ( locale) )
71
+
72
+ // Get a formatted result from en-US
73
+ prefs. languages = [ " en-US " ]
74
+ prefs. locale = " en_US "
75
+ LocaleCache . cache. resetCurrent ( to: prefs)
76
+ let formattedEnglish = list. formatted ( . list( type: . and) . locale ( locale) )
77
+
78
+ // Reset to current preferences before any possibility of failing this test
79
+ LocaleCache . cache. reset ( )
80
+
81
+ // No matter what 'current' was before this test was run, formattedSpanish and formattedEnglish should be different.
82
+ #expect( formattedSpanish != formattedEnglish)
83
+ }
89
84
}
90
85
}
0 commit comments