refactor(i18n): add service snapshot stringers
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
87f582f43f
commit
0c26ef0caa
4 changed files with 14 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
5
state.go
5
state.go
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue