Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041import Foundationimport Testing
@testable import ParcelUI
struct LocalizationPluralTests { @Test(arguments: ["fr", "pt-BR"], [0, 1, 2, 1_000_000]) func compiledWindowCountsKeepTheActualNumber(language: String, count: Int) throws { let bundle = try localizedBundle(language) let locale = Locale(identifier: language) let retiled = String(localized: "Retiled \(count) windows.", table: "Feedback", bundle: bundle, locale: locale) let suggestion = String( localized: "Use \(count) windows here", table: "Feedback", bundle: bundle, locale: locale) #expect(retiled.contains(count.formatted(.number.locale(locale))), "Incorrect count: \(retiled)") #expect(suggestion.contains(count.formatted(.number.locale(locale))), "Incorrect count: \(suggestion)") let noun = language == "fr" ? "fenêtre" : "janela" for value in [retiled, suggestion] { #expect(!value.contains("%"), "Unresolved format: \(value)") #expect(value.contains(noun), "Missing window noun: \(value)") #expect(value.contains(noun + "s") == (count >= 2), "Incorrect plural: \(value)") } }
@Test(arguments: ["fr", "pt-BR"], [0.0, 0.5, 1.0, 1.5, 2.0]) func compiledDelayKeepsFractionalCounts(language: String, seconds: Double) throws { let bundle = try localizedBundle(language) let locale = Locale(identifier: language) let value = String( localized: "Show after \(seconds, specifier: "%.1f") seconds", table: "UI", bundle: bundle, locale: locale) #expect(value != "Show after \(String(format: "%.1f", seconds)) seconds") #expect(!value.contains("%")) let expectedNumber = String(format: "%.1f", locale: locale, seconds) #expect(value.contains(expectedNumber), "Incorrect delay: \(value)") }
private func localizedBundle(_ language: String) throws -> Bundle { let url = try #require(Bundle.module.url(forResource: language.lowercased(), withExtension: "lproj")) return try #require(Bundle(url: url)) }}