LocalizationUtilTests.swift (2013B)
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 ["follow_pack_user_count", "users", "user", "users"], 19 ["followers_count", "Followers", "Follower", "Followers"], 20 ["following_count", "Following", "Following", "Following"], 21 ["hellthread_notifications_disabled", "Hide notifications that tag more than 0 profiles", "Hide notifications that tag more than 1 profile", "Hide notifications that tag more than 2 profiles"], 22 ["imports_count", "Imports", "Import", "Imports"], 23 ["quoted_reposts_count", "Quotes", "Quote", "Quotes"], 24 ["reactions_count", "Reactions", "Reaction", "Reactions"], 25 ["relays_count", "Relays", "Relay", "Relays"], 26 ["reposts_count", "Reposts", "Repost", "Reposts"], 27 ["sats", "sats", "sat", "sats"], 28 ["users_talking_about_it", "0 users talking about it", "1 user talking about it", "2 users talking about it"], 29 ["word_count", "0 Words", "1 Word", "2 Words"], 30 ["zaps_count", "Zaps", "Zap", "Zaps"] 31 ] 32 33 for key in keys { 34 XCTAssertEqual(pluralizedString(key: key[0], count: 0, locale: enUsLocale), key[1]) 35 XCTAssertEqual(pluralizedString(key: key[0], count: 1, locale: enUsLocale), key[2]) 36 XCTAssertEqual(pluralizedString(key: key[0], count: 2, locale: enUsLocale), key[3]) 37 Bundle.main.localizations.map { Locale(identifier: $0) }.forEach { 38 for count in 1...10 { 39 XCTAssertNoThrow(pluralizedString(key: key[0], count: count, locale: $0)) 40 } 41 } 42 } 43 } 44 45 }