LocalizationUtilTests.swift (1551B)
1 // 2 // LocalizationUtilTests.swift 3 // damusTests 4 // 5 // Created by Terry Yiu on 7/13/23. 6 // 7 8 import XCTest 9 @testable import damus 10 11 final class LocalizationUtilTests: XCTestCase { 12 13 func testPluralizedString() throws { 14 let enUsLocale = Locale(identifier: "en-US") 15 16 // Test cases of the localization string key, and the expected en-US strings for a count of 0, 1, and 2. 17 let keys = [ 18 ["followers_count", "Followers", "Follower", "Followers"], 19 ["following_count", "Following", "Following", "Following"], 20 ["imports_count", "Imports", "Import", "Imports"], 21 ["reactions_count", "Reactions", "Reaction", "Reactions"], 22 ["relays_count", "Relays", "Relay", "Relays"], 23 ["reposts_count", "Reposts", "Repost", "Reposts"], 24 ["sats", "sats", "sat", "sats"], 25 ["zaps_count", "Zaps", "Zap", "Zaps"], 26 ["word_count", "0 Words", "1 Word", "2 Words"] 27 ] 28 29 for key in keys { 30 XCTAssertEqual(pluralizedString(key: key[0], count: 0, locale: enUsLocale), key[1]) 31 XCTAssertEqual(pluralizedString(key: key[0], count: 1, locale: enUsLocale), key[2]) 32 XCTAssertEqual(pluralizedString(key: key[0], count: 2, locale: enUsLocale), key[3]) 33 Bundle.main.localizations.map { Locale(identifier: $0) }.forEach { 34 for count in 1...10 { 35 XCTAssertNoThrow(pluralizedString(key: key[0], count: count, locale: $0)) 36 } 37 } 38 } 39 } 40 41 }