Files
damus/damusTests/RepostedTests.swift
Daniel D’Aquino c22c819bc0 Update tests to the new npub abbreviation format
Changelog-None
Closes: https://github.com/damus-io/damus/issues/3501
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2026-01-26 16:17:14 -08:00

39 lines
1.7 KiB
Swift

//
// RepostedTests.swift
// damusTests
//
// Created by Terry Yiu on 2/23/25.
//
import XCTest
@testable import damus
final class RepostedTests: XCTestCase {
@MainActor
func testPeopleRepostedText() throws {
let enUsLocale = Locale(identifier: "en-US")
let damusState = test_damus_state
let pubkey = test_pubkey
// reposts must be greater than 0. Empty string is returned as a fallback if not.
XCTAssertEqual(people_reposted_text(profiles: damusState.profiles, pubkey: pubkey, reposts: -1, locale: enUsLocale), "")
XCTAssertEqual(people_reposted_text(profiles: damusState.profiles, pubkey: pubkey, reposts: 0, locale: enUsLocale), "")
// Verify the English pluralization variations.
XCTAssertEqual(people_reposted_text(profiles: damusState.profiles, pubkey: pubkey, reposts: 1, locale: enUsLocale), "npub17ldv...hr77 reposted")
XCTAssertEqual(people_reposted_text(profiles: damusState.profiles, pubkey: pubkey, reposts: 2, locale: enUsLocale), "npub17ldv...hr77 and 1 other reposted")
XCTAssertEqual(people_reposted_text(profiles: damusState.profiles, pubkey: pubkey, reposts: 3, locale: enUsLocale), "npub17ldv...hr77 and 2 others reposted")
// Sanity check that the non-English translations are likely not malformed.
Bundle.main.localizations.map { Locale(identifier: $0) }.forEach {
// -1...11 covers a lot (but not all) pluralization rules for different languages.
// However, it is good enough for a sanity check.
for reposts in -1...11 {
XCTAssertNoThrow(people_reposted_text(profiles: damusState.profiles, pubkey: pubkey, reposts: reposts, locale: $0))
}
}
}
}