39 lines
1.3 KiB
Swift
39 lines
1.3 KiB
Swift
import XCTest
|
|
@testable import HermesPrediction
|
|
|
|
private struct TestFailure: Error, CustomStringConvertible {
|
|
let description: String
|
|
}
|
|
|
|
@MainActor
|
|
final class LocalizationStoreTests: XCTestCase {
|
|
func testEnglishBundleStringsLoad() throws {
|
|
let store = LocalizationStore(localeCode: "en")
|
|
|
|
try expectEqual(store.string(for: "app.name"), "Hermes")
|
|
try expectEqual(store.string(for: "settings.title"), "Settings")
|
|
try expectEqual(store.string(for: "settings.enabled"), "Enabled")
|
|
}
|
|
|
|
func testSwedishBundleStringsLoad() throws {
|
|
let store = LocalizationStore(localeCode: "sv")
|
|
|
|
try expectEqual(store.string(for: "app.name"), "Hermes")
|
|
try expectEqual(store.string(for: "settings.title"), "Inställningar")
|
|
try expectEqual(store.string(for: "settings.enabled"), "Aktiverad")
|
|
}
|
|
|
|
func testUnsupportedLocaleFallsBackToEnglish() throws {
|
|
let store = LocalizationStore(localeCode: "fr")
|
|
|
|
try expectEqual(store.string(for: "settings.analytics"), "Analytics")
|
|
try expectEqual(store.localeName(for: "sv", displayLocaleCode: "fr"), "Swedish")
|
|
}
|
|
|
|
private func expectEqual(_ actual: String, _ expected: String) throws {
|
|
guard actual == expected else {
|
|
throw TestFailure(description: "Expected \(expected), got \(actual)")
|
|
}
|
|
}
|
|
}
|