Test localized language sorting

This commit is contained in:
Davide De Rosa 2019-04-26 15:58:20 +02:00
parent e5d0d7abb3
commit 9356e02ea0
1 changed files with 18 additions and 0 deletions

View File

@ -48,4 +48,22 @@ class UtilsTests: XCTestCase {
XCTAssertEqual(1073741824.dataUnitDescription, "1.00GB")
XCTAssertEqual(1073741825.dataUnitDescription, "1.00GB")
}
func testLanguageLocalization() {
let languages = ["en", "it", "de", "pt-BR", "ru"]
let english = Locale(identifier: "en")
let italian = Locale(identifier: "it")
let languagesEN = privateSortedLanguages(languages, with: english)
let languagesIT = privateSortedLanguages(languages, with: italian)
XCTAssertEqual(languagesEN, ["en", "de", "it", "pt-BR", "ru"])
XCTAssertEqual(languagesIT, ["en", "it", "pt-BR", "ru", "de"])
}
private func privateSortedLanguages(_ languages: [String], with locale: Locale) -> [String] {
return languages.sorted {
return locale.localizedString(forLanguageCode: $0)! < locale.localizedString(forLanguageCode: $1)!
}
}
}