Skip to content

Commit c66a879

Browse files
committed
Added test for Locale static properties and methods
1 parent 7947051 commit c66a879

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

TestFoundation/TestNSLocale.swift

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class TestNSLocale : XCTestCase {
2121
("test_constants", test_constants),
2222
("test_Identifier", test_Identifier),
2323
("test_copy", test_copy),
24-
("test_availableIdentifiers", test_availableIdentifiers),
24+
("test_staticProperties", test_staticProperties),
2525
("test_localeProperties", test_localeProperties),
2626
]
2727
}
@@ -110,10 +110,29 @@ class TestNSLocale : XCTestCase {
110110
XCTAssertTrue(locale == localeCopy)
111111
}
112112

113-
func test_availableIdentifiers() {
114-
XCTAssertNoThrow(Locale.availableIdentifiers)
113+
func test_staticProperties() {
114+
let euroCurrencyCode = "EUR"
115+
let spainRegionCode = "ES"
116+
let galicianLanguageCode = "gl"
117+
let galicianLocaleIdentifier = Locale.identifier(fromComponents: [NSLocale.Key.languageCode.rawValue: galicianLanguageCode,
118+
NSLocale.Key.countryCode.rawValue: spainRegionCode])
119+
120+
XCTAssertTrue(galicianLocaleIdentifier == "\(galicianLanguageCode)_\(spainRegionCode)")
121+
122+
let components = Locale.components(fromIdentifier: galicianLocaleIdentifier)
123+
124+
XCTAssertTrue(components[NSLocale.Key.languageCode.rawValue] == galicianLanguageCode)
125+
XCTAssertTrue(components[NSLocale.Key.countryCode.rawValue] == spainRegionCode)
126+
127+
XCTAssertTrue(Locale.availableIdentifiers.contains(galicianLocaleIdentifier))
128+
XCTAssertTrue(Locale.commonISOCurrencyCodes.contains(euroCurrencyCode))
129+
XCTAssertTrue(Locale.isoCurrencyCodes.contains(euroCurrencyCode))
130+
XCTAssertTrue(Locale.isoRegionCodes.contains(spainRegionCode))
131+
XCTAssertTrue(Locale.isoLanguageCodes.contains(galicianLanguageCode))
132+
133+
XCTAssertTrue(Locale.preferredLanguages.count == UserDefaults.standard.array(forKey: "AppleLanguages")?.count ?? 0)
115134
}
116-
135+
117136
func test_localeProperties(){
118137
#if os(Android)
119138
XCTFail("Locale lookup unavailable on Android")

0 commit comments

Comments
 (0)