Skip to content

Commit 9d57f36

Browse files
authored
Re-enable disabled tests due to ICU-74 (#890)
resolves: rdar://121399858
1 parent aca65ac commit 9d57f36

File tree

4 files changed

+128
-171
lines changed

4 files changed

+128
-171
lines changed

Sources/TestSupport/TestSupport.swift

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -231,44 +231,3 @@ public typealias URLComponents = FoundationEssentials.URLComponents
231231
public typealias URLQueryItem = FoundationEssentials.URLQueryItem
232232

233233
#endif // FOUNDATION_FRAMEWORK
234-
235-
/// ICU uses `\u{202f}` and `\u{020f}` interchangeably.
236-
/// This function compares two strings ignoring the separator.
237-
public func XCTAssertEqualIgnoreSeparator(_ lhs: String, _ rhs: String, file: StaticString = #filePath, line: UInt = #line) {
238-
return XCTAssertEqual(
239-
lhs.normalizingICUSeparator(),
240-
rhs.normalizingICUSeparator(),
241-
file: file,
242-
line: line
243-
)
244-
}
245-
246-
/// ICU uses `\u{202f}` and `\u{020f}` interchangeably.
247-
/// This function compares two attributed strings ignoring the separator.
248-
public func XCTAssertEqualIgnoreSeparator(_ lhs: AttributedString, _ rhs: AttributedString, file: StaticString = #filePath, line: UInt = #line) {
249-
return XCTAssertEqual(lhs.normalizingICUSeparator(), rhs.normalizingICUSeparator(), file: file, line: line)
250-
}
251-
252-
extension String {
253-
/// This function normalizes whitespace used by ICU to `\u{020f}`.
254-
///
255-
/// ICU uses `\u{202f}` and `\u{020f}` interchangeably.
256-
public func normalizingICUSeparator() -> String {
257-
replacingOccurrences(of: "\u{202f}", with: " ")
258-
}
259-
}
260-
261-
extension AttributedString {
262-
/// This function normalizes whitespace used by ICU to `\u{020f}`.
263-
///
264-
/// ICU uses `\u{202f}` and `\u{020f}` interchangeably.
265-
public func normalizingICUSeparator() -> AttributedString {
266-
var str = self
267-
while let idx = str.characters.firstIndex(of: "\u{202f}") {
268-
str.characters.replaceSubrange(
269-
idx ..< str.characters.index(after: idx),
270-
with: CollectionOfOne(" "))
271-
}
272-
return str
273-
}
274-
}

Tests/FoundationInternationalizationTests/Formatting/DateFormatStyleTests.swift

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,14 @@ final class DateFormatStyleTests : XCTestCase {
278278
XCTAssertEqual(date.formatted(style.weekday(.short)), "Th")
279279

280280
XCTAssertEqual(date.formatted(style.hour(.defaultDigits(amPM: .omitted))), "12")
281-
XCTAssertEqualIgnoreSeparator(date.formatted(style.hour(.defaultDigits(amPM: .narrow))), "12 a")
282-
XCTAssertEqualIgnoreSeparator(date.formatted(style.hour(.defaultDigits(amPM: .abbreviated))), "12 AM")
283-
XCTAssertEqualIgnoreSeparator(date.formatted(style.hour(.defaultDigits(amPM: .wide))), "12 AM")
281+
XCTAssertEqual(date.formatted(style.hour(.defaultDigits(amPM: .narrow))), "12a")
282+
XCTAssertEqual(date.formatted(style.hour(.defaultDigits(amPM: .abbreviated))), "12AM")
283+
XCTAssertEqual(date.formatted(style.hour(.defaultDigits(amPM: .wide))), "12AM")
284284

285285
XCTAssertEqual(date.formatted(style.hour(.twoDigits(amPM: .omitted))), "12")
286-
XCTAssertEqualIgnoreSeparator(date.formatted(style.hour(.twoDigits(amPM: .narrow))), "12 a")
287-
XCTAssertEqualIgnoreSeparator(date.formatted(style.hour(.twoDigits(amPM: .abbreviated))), "12 AM")
288-
XCTAssertEqualIgnoreSeparator(date.formatted(style.hour(.twoDigits(amPM: .wide))), "12 AM")
286+
XCTAssertEqual(date.formatted(style.hour(.twoDigits(amPM: .narrow))), "12a")
287+
XCTAssertEqual(date.formatted(style.hour(.twoDigits(amPM: .abbreviated))), "12AM")
288+
XCTAssertEqual(date.formatted(style.hour(.twoDigits(amPM: .wide))), "12AM")
289289
}
290290

291291
func testFormattingWithHourCycleOverrides() throws {
@@ -294,12 +294,12 @@ final class DateFormatStyleTests : XCTestCase {
294294
let esES = "es_ES"
295295

296296
let style = Date.FormatStyle(date: .omitted, time: .standard, calendar: Calendar(identifier: .gregorian), timeZone: TimeZone(identifier: "PST")!, capitalizationContext: .standalone)
297-
XCTAssertEqualIgnoreSeparator(date.formatted(style.locale(Locale.localeAsIfCurrent(name: enUS, overrides: .init()))), "4:00:00 PM")
298-
XCTAssertEqualIgnoreSeparator(date.formatted(style.locale(Locale.localeAsIfCurrent(name: enUS, overrides: .init(force12Hour: true)))), "4:00:00 PM")
297+
XCTAssertEqual(date.formatted(style.locale(Locale.localeAsIfCurrent(name: enUS, overrides: .init()))), "4:00:00PM")
298+
XCTAssertEqual(date.formatted(style.locale(Locale.localeAsIfCurrent(name: enUS, overrides: .init(force12Hour: true)))), "4:00:00PM")
299299
XCTAssertEqual(date.formatted(style.locale(Locale.localeAsIfCurrent(name: enUS, overrides: .init(force24Hour: true)))), "16:00:00")
300300

301301
XCTAssertEqual(date.formatted(style.locale(Locale.localeAsIfCurrent(name: esES, overrides: .init()))), "16:00:00")
302-
XCTAssertEqualIgnoreSeparator(date.formatted(style.locale(Locale.localeAsIfCurrent(name: esES, overrides: .init(force12Hour: true)))), "4:00:00 p. m.")
302+
XCTAssertEqual(date.formatted(style.locale(Locale.localeAsIfCurrent(name: esES, overrides: .init(force12Hour: true)))), "4:00:00 p. m.")
303303
XCTAssertEqual(date.formatted(style.locale(Locale.localeAsIfCurrent(name: esES, overrides: .init(force24Hour: true)))), "16:00:00")
304304
}
305305

@@ -422,7 +422,7 @@ final class DateFormatStyleTests : XCTestCase {
422422
func verifyWithFormat(_ date: Date, expected: String, file: StaticString = #filePath, line: UInt = #line) {
423423
let fmt = format.locale(locale)
424424
let formatted = fmt.format(date)
425-
XCTAssertEqualIgnoreSeparator(formatted, expected, file: file, line: line)
425+
XCTAssertEqual(formatted, expected, file: file, line: line)
426426
}
427427

428428
do {
@@ -575,12 +575,12 @@ final class DateFormatStyleTests : XCTestCase {
575575
do {
576576
locale = Locale(identifier: "en_TW")
577577
format = .init(timeZone: .gmt).hour(.twoDigits(amPM: .wide)).minute().second()
578-
verifyWithFormat(middleOfNight, expected: "03:50:00 AM")
579-
verifyWithFormat(earlyMorning, expected: "06:50:00 AM")
580-
verifyWithFormat(morning, expected: "09:50:00 AM")
581-
verifyWithFormat(noon, expected: "12:50:00 PM")
582-
verifyWithFormat(afternoon, expected: "03:50:00 PM")
583-
verifyWithFormat(evening, expected: "09:50:00 PM")
578+
verifyWithFormat(middleOfNight, expected: "03:50:00AM")
579+
verifyWithFormat(earlyMorning, expected: "06:50:00AM")
580+
verifyWithFormat(morning, expected: "09:50:00AM")
581+
verifyWithFormat(noon, expected: "12:50:00PM")
582+
verifyWithFormat(afternoon, expected: "03:50:00PM")
583+
verifyWithFormat(evening, expected: "09:50:00PM")
584584
}
585585
}
586586

@@ -589,22 +589,22 @@ final class DateFormatStyleTests : XCTestCase {
589589
var format: Date.FormatStyle = .init(calendar: .init(identifier: .gregorian), timeZone: .gmt).locale(Locale(identifier: "en_US"))
590590
func verifyWithFormat(_ date: Date, expected: String, file: StaticString = #filePath, line: UInt = #line) {
591591
let formatted = format.format(date)
592-
XCTAssertEqualIgnoreSeparator(formatted, expected, file: file, line: line)
592+
XCTAssertEqual(formatted, expected, file: file, line: line)
593593
}
594594

595595
let date = Date(timeIntervalSince1970: 0)
596596

597-
verifyWithFormat(date, expected: "1/1/1970, 12:00 AM")
597+
verifyWithFormat(date, expected: "1/1/1970, 12:00AM")
598598
format = format.day(.omitted)
599-
verifyWithFormat(date, expected: "1/1970, 12:00 AM")
599+
verifyWithFormat(date, expected: "1/1970, 12:00AM")
600600
format = format.day(.defaultDigits)
601-
verifyWithFormat(date, expected: "1/1/1970, 12:00 AM")
601+
verifyWithFormat(date, expected: "1/1/1970, 12:00AM")
602602
format = format.minute()
603-
verifyWithFormat(date, expected: "1/1/1970, 12:00 AM")
603+
verifyWithFormat(date, expected: "1/1/1970, 12:00AM")
604604
format = format.minute(.omitted)
605-
verifyWithFormat(date, expected: "1/1/1970, 12 AM")
605+
verifyWithFormat(date, expected: "1/1/1970, 12AM")
606606
format = format.day(.omitted)
607-
verifyWithFormat(date, expected: "1/1970, 12 AM")
607+
verifyWithFormat(date, expected: "1/1970, 12AM")
608608

609609
format = .init(calendar: .init(identifier: .gregorian), timeZone: .gmt).locale(Locale(identifier: "en_US"))
610610
format = format.day()
@@ -639,13 +639,13 @@ final class DateAttributedFormatStyleTests : XCTestCase {
639639
("3", .hour),
640640
(":", nil),
641641
("04", .minute),
642-
(" ", nil),
642+
("", nil),
643643
("PM", .amPM)],
644644
]
645645

646646
for (style, expectation) in expectations {
647647
let formatted = style.attributed.format(date)
648-
XCTAssertEqualIgnoreSeparator(formatted, expectation.attributedString)
648+
XCTAssertEqual(formatted, expectation.attributedString)
649649
}
650650
}
651651
func testIndividualFields() throws {
@@ -662,15 +662,15 @@ final class DateAttributedFormatStyleTests : XCTestCase {
662662
baseStyle.day(): [ ("12", .day) ],
663663
baseStyle.dayOfYear(): [ ("102", .dayOfYear) ],
664664
baseStyle.weekday(): [ ("Mon", .weekday) ],
665-
baseStyle.hour(): [ ("3", .hour), (" ", nil), ("PM", .amPM) ],
665+
baseStyle.hour(): [ ("3", .hour), ("", nil), ("PM", .amPM) ],
666666
baseStyle.minute(): [ ("4", .minute) ],
667667
baseStyle.second(): [ ("32", .second) ],
668668
baseStyle.timeZone(): [ ("GMT", .timeZone) ],
669669
]
670670

671671
for (style, expectation) in expectations {
672672
let formatted = style.attributed.format(date)
673-
XCTAssertEqualIgnoreSeparator(formatted, expectation.attributedString)
673+
XCTAssertEqual(formatted, expectation.attributedString)
674674
}
675675
}
676676

@@ -715,7 +715,7 @@ final class DateAttributedFormatStyleTests : XCTestCase {
715715
func test(dateStyle: Date.FormatStyle.DateStyle, timeStyle: Date.FormatStyle.TimeStyle, dateFormatOverride: [Date.FormatStyle.DateStyle: String], expected: [Segment], file: StaticString = #filePath, line: UInt = #line) {
716716
let locale = Locale.localeAsIfCurrent(name: enUS, overrides: .init(dateFormats: dateFormatOverride))
717717
let style = Date.FormatStyle(date: dateStyle, time: timeStyle, locale: locale, calendar: Calendar(identifier: .gregorian), timeZone: TimeZone(identifier: "PST")!, capitalizationContext: .standalone).attributed
718-
XCTAssertEqualIgnoreSeparator(style.format(date), expected.attributedString, file: file, line: line)
718+
XCTAssertEqual(style.format(date), expected.attributedString, file: file, line: line)
719719
}
720720

721721
let dateFormatOverride: [Date.FormatStyle.DateStyle: String] = [
@@ -735,7 +735,7 @@ final class DateAttributedFormatStyleTests : XCTestCase {
735735
("4", .hour),
736736
(":", nil),
737737
("00", .minute),
738-
(" ", nil),
738+
("", nil),
739739
("PM", .amPM),
740740
]) // Ignoring override since there's no match for the specific style
741741

@@ -781,7 +781,7 @@ final class DateAttributedFormatStyleTests : XCTestCase {
781781
("00", .minute),
782782
(":", nil),
783783
("00", .second),
784-
(" ", nil),
784+
("", nil),
785785
("PM", .amPM),
786786
(" ", nil),
787787
("PST", .timeZone),
@@ -800,7 +800,7 @@ final class DateAttributedFormatStyleTests : XCTestCase {
800800
("00", .minute),
801801
(":", nil),
802802
("00", .second),
803-
(" ", nil),
803+
("", nil),
804804
("PM", .amPM),
805805
(" ", nil),
806806
("PST", .timeZone),
@@ -819,7 +819,7 @@ final class DateAttributedFormatStyleTests : XCTestCase {
819819
("00", .minute),
820820
(":", nil),
821821
("00", .second),
822-
(" ", nil),
822+
("", nil),
823823
("PM", .amPM),
824824
(" ", nil),
825825
("PST", .timeZone),
@@ -838,7 +838,7 @@ final class DateAttributedFormatStyleTests : XCTestCase {
838838
("00", .minute),
839839
(":", nil),
840840
("00", .second),
841-
(" ", nil),
841+
("", nil),
842842
("PM", .amPM),
843843
(" ", nil),
844844
("PST", .timeZone),
@@ -857,7 +857,7 @@ final class DateAttributedFormatStyleTests : XCTestCase {
857857
("00", .minute),
858858
(":", nil),
859859
("00", .second),
860-
(" ", nil),
860+
("", nil),
861861
("PM", .amPM),
862862
(" ", nil),
863863
("PST", .timeZone),
@@ -950,10 +950,10 @@ final class DateVerbatimFormatStyleTests : XCTestCase {
950950
// Weekday: standalone
951951
verify("\(weekday: .abbreviated)", localeID: "en_GB", calendarID: .gregorian, expectedString: "Thu")
952952

953-
#if FIXED_ICU_74_DAYPERIOD
954953
// Day period: formatting
955-
verify("\(hour: .twoDigits(clock: .twelveHour, hourCycle: .zeroBased)) \(dayPeriod: .standard(.abbreviated))", localeID: "en_GB", calendarID: .gregorian, expectedString: "00 am")
956-
#endif
954+
#if FIXED_ICU_74_DAYPERIOD
955+
verify("\(hour: .twoDigits(clock: .twelveHour, hourCycle: .zeroBased)) \(dayPeriod: .standard(.abbreviated))", localeID: "en_GB", calendarID: .gregorian, expectedString: "00 AM")
956+
#endif // FIXED_ICU_74_DAYPERIOD
957957
}
958958

959959
func test_95845290() throws {
@@ -1404,7 +1404,7 @@ final class TestDateStyleDiscreteConformance : XCTestCase {
14041404
} else {
14051405
return bound
14061406
}
1407-
}.lazy.map(\.output).map { $0.normalizingICUSeparator() },
1407+
}.lazy.map(\.output),
14081408
contains: expectedExcerpts,
14091409
"(lowerbound to upperbound)",
14101410
file: file,
@@ -1417,7 +1417,7 @@ final class TestDateStyleDiscreteConformance : XCTestCase {
14171417
} else {
14181418
return bound
14191419
}
1420-
}.lazy.map(\.output).map { $0.normalizingICUSeparator() },
1420+
}.lazy.map(\.output),
14211421
contains: expectedExcerpts
14221422
.reversed()
14231423
.map { $0.reversed() },
@@ -1432,53 +1432,53 @@ final class TestDateStyleDiscreteConformance : XCTestCase {
14321432
of: .init(date: .complete, time: .complete).secondFraction(.fractional(2)),
14331433
in: (now - 0.1)...(now + 0.1),
14341434
includes: [
1435-
"Monday, May 15, 2023 at 8:47:19.90 AM GMT",
1436-
"Monday, May 15, 2023 at 8:47:19.91 AM GMT",
1437-
"Monday, May 15, 2023 at 8:47:19.92 AM GMT",
1438-
"Monday, May 15, 2023 at 8:47:19.93 AM GMT",
1439-
"Monday, May 15, 2023 at 8:47:19.94 AM GMT",
1440-
"Monday, May 15, 2023 at 8:47:19.95 AM GMT",
1441-
"Monday, May 15, 2023 at 8:47:19.96 AM GMT",
1442-
"Monday, May 15, 2023 at 8:47:19.97 AM GMT",
1443-
"Monday, May 15, 2023 at 8:47:19.98 AM GMT",
1444-
"Monday, May 15, 2023 at 8:47:19.99 AM GMT",
1445-
"Monday, May 15, 2023 at 8:47:20.00 AM GMT",
1446-
"Monday, May 15, 2023 at 8:47:20.01 AM GMT",
1447-
"Monday, May 15, 2023 at 8:47:20.02 AM GMT",
1448-
"Monday, May 15, 2023 at 8:47:20.03 AM GMT",
1449-
"Monday, May 15, 2023 at 8:47:20.04 AM GMT",
1450-
"Monday, May 15, 2023 at 8:47:20.05 AM GMT",
1451-
"Monday, May 15, 2023 at 8:47:20.06 AM GMT",
1452-
"Monday, May 15, 2023 at 8:47:20.07 AM GMT",
1453-
"Monday, May 15, 2023 at 8:47:20.08 AM GMT",
1454-
"Monday, May 15, 2023 at 8:47:20.09 AM GMT",
1455-
"Monday, May 15, 2023 at 8:47:20.10 AM GMT",
1435+
"Monday, May 15, 2023 at 8:47:19.90AM GMT",
1436+
"Monday, May 15, 2023 at 8:47:19.91AM GMT",
1437+
"Monday, May 15, 2023 at 8:47:19.92AM GMT",
1438+
"Monday, May 15, 2023 at 8:47:19.93AM GMT",
1439+
"Monday, May 15, 2023 at 8:47:19.94AM GMT",
1440+
"Monday, May 15, 2023 at 8:47:19.95AM GMT",
1441+
"Monday, May 15, 2023 at 8:47:19.96AM GMT",
1442+
"Monday, May 15, 2023 at 8:47:19.97AM GMT",
1443+
"Monday, May 15, 2023 at 8:47:19.98AM GMT",
1444+
"Monday, May 15, 2023 at 8:47:19.99AM GMT",
1445+
"Monday, May 15, 2023 at 8:47:20.00AM GMT",
1446+
"Monday, May 15, 2023 at 8:47:20.01AM GMT",
1447+
"Monday, May 15, 2023 at 8:47:20.02AM GMT",
1448+
"Monday, May 15, 2023 at 8:47:20.03AM GMT",
1449+
"Monday, May 15, 2023 at 8:47:20.04AM GMT",
1450+
"Monday, May 15, 2023 at 8:47:20.05AM GMT",
1451+
"Monday, May 15, 2023 at 8:47:20.06AM GMT",
1452+
"Monday, May 15, 2023 at 8:47:20.07AM GMT",
1453+
"Monday, May 15, 2023 at 8:47:20.08AM GMT",
1454+
"Monday, May 15, 2023 at 8:47:20.09AM GMT",
1455+
"Monday, May 15, 2023 at 8:47:20.10AM GMT",
14561456
])
14571457

14581458
assertEvaluation(
14591459
of: .init(date: .complete, time: .complete),
14601460
in: (now - 3)...(now + 3),
14611461
includes: [
1462-
"Monday, May 15, 2023 at 8:47:17 AM GMT",
1463-
"Monday, May 15, 2023 at 8:47:18 AM GMT",
1464-
"Monday, May 15, 2023 at 8:47:19 AM GMT",
1465-
"Monday, May 15, 2023 at 8:47:20 AM GMT",
1466-
"Monday, May 15, 2023 at 8:47:21 AM GMT",
1467-
"Monday, May 15, 2023 at 8:47:22 AM GMT",
1468-
"Monday, May 15, 2023 at 8:47:23 AM GMT",
1462+
"Monday, May 15, 2023 at 8:47:17AM GMT",
1463+
"Monday, May 15, 2023 at 8:47:18AM GMT",
1464+
"Monday, May 15, 2023 at 8:47:19AM GMT",
1465+
"Monday, May 15, 2023 at 8:47:20AM GMT",
1466+
"Monday, May 15, 2023 at 8:47:21AM GMT",
1467+
"Monday, May 15, 2023 at 8:47:22AM GMT",
1468+
"Monday, May 15, 2023 at 8:47:23AM GMT",
14691469
])
14701470

14711471
assertEvaluation(
14721472
of: .init().hour(.twoDigits(amPM: .abbreviated)).minute(),
14731473
in: (now - 180)...(now + 180),
14741474
includes: [
1475-
"08:44 AM",
1476-
"08:45 AM",
1477-
"08:46 AM",
1478-
"08:47 AM",
1479-
"08:48 AM",
1480-
"08:49 AM",
1481-
"08:50 AM",
1475+
"08:44AM",
1476+
"08:45AM",
1477+
"08:46AM",
1478+
"08:47AM",
1479+
"08:48AM",
1480+
"08:49AM",
1481+
"08:50AM",
14821482
])
14831483

14841484
assertEvaluation(

0 commit comments

Comments
 (0)