feat(i18n): add package-level clear handlers
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
40e00d13f1
commit
18d7ba1f2c
2 changed files with 24 additions and 0 deletions
7
i18n.go
7
i18n.go
|
|
@ -122,6 +122,13 @@ func PrependHandler(handlers ...KeyHandler) {
|
|||
}
|
||||
}
|
||||
|
||||
// ClearHandlers removes all handlers from the default service.
|
||||
func ClearHandlers() {
|
||||
if svc := Default(); svc != nil {
|
||||
svc.ClearHandlers()
|
||||
}
|
||||
}
|
||||
|
||||
func executeIntentTemplate(tmplStr string, data templateData) string {
|
||||
if tmplStr == "" {
|
||||
return ""
|
||||
|
|
|
|||
17
i18n_test.go
17
i18n_test.go
|
|
@ -250,6 +250,23 @@ func TestPrependHandler_Good_Variadic(t *testing.T) {
|
|||
assert.IsType(t, ProgressHandler{}, handlers[1])
|
||||
}
|
||||
|
||||
func TestClearHandlers_Good(t *testing.T) {
|
||||
svc, err := New()
|
||||
require.NoError(t, err)
|
||||
_ = Init()
|
||||
prev := Default()
|
||||
SetDefault(svc)
|
||||
t.Cleanup(func() {
|
||||
SetDefault(prev)
|
||||
})
|
||||
|
||||
AddHandler(LabelHandler{})
|
||||
require.NotEmpty(t, svc.Handlers())
|
||||
|
||||
ClearHandlers()
|
||||
assert.Empty(t, svc.Handlers())
|
||||
}
|
||||
|
||||
// --- executeIntentTemplate ---
|
||||
|
||||
func TestExecuteIntentTemplate_Good(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue