Files
steipete--codexbar/TestsLinux/UsageFormatterLinuxTests.swift
thanthi-del 407bca37d8 Fix Linux segfault in UsageFormatter localization (#2094)
* Fix Linux segfault in UsageFormatter localization (#2092)

Bundle(for:) walks CFBundleGetAllBundles to locate the bundle that
defines BundleToken, which needs Objective-C runtime introspection
swift-corelibs-foundation can't provide on Linux — it crashes in
_CFIsSwift there. CodexBarCore has no .lproj resources of its own
(real localized strings are injected by the macOS app via
setLocalizationProvider), so the Bundle(for:)/NSLocalizedString
lookup was never useful on Linux to begin with. Skip it behind
#if canImport(ObjectiveC) and fall straight through to the existing
hardcoded English fallback table.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* fix: avoid Linux localization bundle crash

---------

Co-authored-by: KaoOo Mac <thanthipmontein@192.168.1.184>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-07-12 18:34:01 +01:00

16 lines
578 B
Swift

import CodexBarCore
import Testing
@Suite(.serialized)
struct UsageFormatterLinuxTests {
@Test
func `rate-window formatting uses the standalone English fallback`() {
UsageFormatter.clearLocalizationProvider()
UsageFormatter.clearLocaleProvider()
#expect(UsageFormatter.usageLine(remaining: 25, used: 75, showUsed: false) == "25% left")
#expect(UsageFormatter.usageLine(remaining: 25, used: 75, showUsed: true) == "75% used")
#expect(UsageFormatter.usageLine(remaining: 0.75, used: 99.25, showUsed: false) == "<1% left")
}
}