damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

RepostedTests.swift (1747B)


      1 //
      2 //  RepostedTests.swift
      3 //  damusTests
      4 //
      5 //  Created by Terry Yiu on 2/23/25.
      6 //
      7 
      8 import XCTest
      9 @testable import damus
     10 
     11 final class RepostedTests: XCTestCase {
     12 
     13     func testPeopleRepostedText() throws {
     14         let enUsLocale = Locale(identifier: "en-US")
     15         let damusState = test_damus_state
     16         let pubkey = test_pubkey
     17 
     18         // reposts must be greater than 0. Empty string is returned as a fallback if not.
     19         XCTAssertEqual(people_reposted_text(profiles: damusState.profiles, pubkey: pubkey, reposts: -1, locale: enUsLocale), "")
     20         XCTAssertEqual(people_reposted_text(profiles: damusState.profiles, pubkey: pubkey, reposts: 0, locale: enUsLocale), "")
     21 
     22         // Verify the English pluralization variations.
     23         XCTAssertEqual(people_reposted_text(profiles: damusState.profiles, pubkey: pubkey, reposts: 1, locale: enUsLocale), "17ldvg64:nq5mhr77 reposted")
     24         XCTAssertEqual(people_reposted_text(profiles: damusState.profiles, pubkey: pubkey, reposts: 2, locale: enUsLocale), "17ldvg64:nq5mhr77 and 1 other reposted")
     25         XCTAssertEqual(people_reposted_text(profiles: damusState.profiles, pubkey: pubkey, reposts: 3, locale: enUsLocale), "17ldvg64:nq5mhr77 and 2 others reposted")
     26 
     27         // Sanity check that the non-English translations are likely not malformed.
     28         Bundle.main.localizations.map { Locale(identifier: $0) }.forEach {
     29             // -1...11 covers a lot (but not all) pluralization rules for different languages.
     30             // However, it is good enough for a sanity check.
     31             for reposts in -1...11 {
     32                 XCTAssertNoThrow(people_reposted_text(profiles: damusState.profiles, pubkey: pubkey, reposts: reposts, locale: $0))
     33             }
     34         }
     35     }
     36 
     37 }