Skip to content

Commit 9fce2a5

Browse files
authored
formattedAttributedLeadingDotSyntax() test failed (#1422)
This test and other tests testing the dot syntax assume that the left hand side of the comparison is using the same locale as the right side, in which case is `Locale.autoupdatingCurrent`. This further assumes that the state of the host machine remains unchanged throughout the tests. Fix this by specifying the locale of the left and right side so they don't depend on the current locale settings. Addresses 154994643
1 parent c5f4563 commit 9fce2a5

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

Tests/FoundationInternationalizationTests/Formatting/NumberFormatStyleTests.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -242,20 +242,22 @@ private struct NumberFormatStyleTests {
242242
}
243243

244244
@Test func formattedAttributedLeadingDotSyntax() throws {
245+
let locale = Locale(identifier: "fr_FR")
245246
let int = 42
246-
#expect(int.formatted(.number.attributed) == IntegerFormatStyle().attributed.format(int))
247-
#expect(int.formatted(.percent.attributed) == IntegerFormatStyle.Percent().attributed.format(int))
248-
#expect(int.formatted(.currency(code: "GBP").attributed) == IntegerFormatStyle.Currency(code: "GBP").attributed.format(int))
247+
#expect(int.formatted(.number.attributed.locale(locale)) == IntegerFormatStyle().attributed.locale(locale).format(int))
248+
#expect(int.formatted(.percent.attributed.locale(locale)) == IntegerFormatStyle.Percent().attributed.locale(locale).format(int))
249+
#expect(int.formatted(.currency(code: "GBP").attributed.locale(locale)) == IntegerFormatStyle.Currency(code: "GBP").attributed.locale(locale).format(int))
249250

250251
let float = 3.14159
251-
#expect(float.formatted(.number.attributed) == FloatingPointFormatStyle<Double>().attributed.format(float))
252-
#expect(float.formatted(.percent.attributed) == FloatingPointFormatStyle.Percent().attributed.format(float))
253-
#expect(float.formatted(.currency(code: "GBP").attributed) == FloatingPointFormatStyle.Currency(code: "GBP").attributed.format(float))
252+
#expect(float.formatted(.number.attributed.locale(locale)) == FloatingPointFormatStyle<Double>().attributed.locale(locale).format(float))
253+
#expect(float.formatted(.percent.attributed.locale(locale)) == FloatingPointFormatStyle.Percent().attributed.locale(locale).format(float))
254+
#expect(float.formatted(.currency(code: "GBP").attributed.locale(locale)) == FloatingPointFormatStyle.Currency(code: "GBP").attributed.locale(locale).format(float))
254255

255256
let decimal = Decimal(2.999)
256-
#expect(decimal.formatted(.number.attributed) == Decimal.FormatStyle().attributed.format(decimal))
257-
#expect(decimal.formatted(.percent.attributed) == Decimal.FormatStyle.Percent().attributed.format(decimal))
258-
#expect(decimal.formatted(.currency(code: "GBP").attributed) == Decimal.FormatStyle.Currency(code: "GBP").attributed.format(decimal))
257+
#expect(decimal.formatted(.number.attributed.locale(locale)) == Decimal.FormatStyle().attributed.locale(locale).format(decimal))
258+
#expect(decimal.formatted(.percent.attributed.locale(locale)) == Decimal.FormatStyle.Percent().attributed.locale(locale).format(decimal))
259+
#expect(decimal.formatted(.currency(code: "GBP").attributed.locale(locale)) == Decimal.FormatStyle.Currency(code: "GBP").attributed.locale(locale).format(decimal))
260+
259261
}
260262

261263
@Test func decimalFormatStyle() throws {

0 commit comments

Comments
 (0)