refactor(i18n): add service snapshot stringers
Some checks are pending
Test / test (push) Waiting to run
Security Scan / security (push) Successful in 21s

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 14:30:28 +00:00
parent 87f582f43f
commit 0c26ef0caa
4 changed files with 14 additions and 0 deletions

View file

@ -347,6 +347,11 @@ func (s *CoreService) CurrentState() ServiceState {
return s.State()
}
// String returns a concise snapshot of the wrapped service state.
func (s *CoreService) String() string {
return s.State().String()
}
// AddHandler appends handlers to the wrapped service's chain.
func (s *CoreService) AddHandler(handlers ...KeyHandler) {
if svc := s.wrapped(); svc != nil {

View file

@ -35,6 +35,7 @@ func TestCoreServiceNilSafe(t *testing.T) {
assert.Equal(t, core.Result{Value: "hello", OK: false}, svc.Translate("hello"))
assert.Equal(t, defaultServiceStateSnapshot(), svc.State())
assert.Equal(t, defaultServiceStateSnapshot(), svc.CurrentState())
assert.Equal(t, defaultServiceStateSnapshot().String(), svc.String())
})
assert.Nil(t, defaultService.Load())

View file

@ -280,6 +280,9 @@ func TestServiceNilReceiverIsSafe(t *testing.T) {
if got, want := svc.State(), defaultServiceStateSnapshot(); got.Language != want.Language || got.Mode != want.Mode || got.Fallback != want.Fallback || got.Formality != want.Formality || got.Location != want.Location || got.Direction != want.Direction || got.IsRTL != want.IsRTL || got.Debug != want.Debug || len(got.AvailableLanguages) != len(want.AvailableLanguages) || len(got.Handlers) != len(want.Handlers) {
t.Fatalf("nil Service.State() = %+v, want %+v", got, want)
}
if got, want := svc.String(), defaultServiceStateSnapshot().String(); got != want {
t.Fatalf("nil Service.String() = %q, want %q", got, want)
}
if got, want := svc.T("prompt.yes"), "prompt.yes"; got != want {
t.Fatalf("nil Service.T(prompt.yes) = %q, want %q", got, want)
}

View file

@ -160,6 +160,11 @@ func (s *Service) State() ServiceState {
)
}
// String returns a concise snapshot of the service state.
func (s *Service) String() string {
return s.State().String()
}
// CurrentState is a more explicit alias for State.
func (s *Service) CurrentState() ServiceState {
return s.State()