Expose public/ API as submodule (#23345)
* model -> public/model * plugin -> public/plugin * public/model/utils -> public/utils * platform/shared/mlog -> public/shared/mlog * platform/shared/i18n -> public/shared/i18n * platform/shared/markdown -> public/shared/markdown * platform/services/timezones -> public/shared/timezones * channels/einterfaces -> einterfaces * expose public/ submodule * go mod tidy * .github: cache-dependency-path, setup-go-work * modules-tidy for public/ too * remove old gomodtidy
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
070ee26081
Коммит
bb02b35048
69
server/public/shared/i18n/i18n_test.go
Обычный файл
69
server/public/shared/i18n/i18n_test.go
Обычный файл
@@ -0,0 +1,69 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package i18n
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/go-i18n/i18n/bundle"
|
||||
"github.com/mattermost/go-i18n/i18n/language"
|
||||
"github.com/mattermost/go-i18n/i18n/translation"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var htmlTestTranslationBundle *bundle.Bundle
|
||||
|
||||
func init() {
|
||||
htmlTestTranslationBundle = bundle.New()
|
||||
fooBold, _ := translation.NewTranslation(map[string]any{
|
||||
"id": "foo.bold",
|
||||
"translation": "<p>[[{{ .Foo }}]]</p>",
|
||||
})
|
||||
htmlTestTranslationBundle.AddTranslation(&language.Language{Tag: "en"}, fooBold)
|
||||
}
|
||||
|
||||
func TestTranslateAsHTML(t *testing.T) {
|
||||
assert.EqualValues(t, "<p><strong><i>foo</i></strong></p>", TranslateAsHTML(TranslateFunc(htmlTestTranslationBundle.MustTfunc("en")), "foo.bold", map[string]any{
|
||||
"Foo": "<i>foo</i>",
|
||||
}))
|
||||
}
|
||||
|
||||
func TestEscapeForHTML(t *testing.T) {
|
||||
stringForPointer := "<b>abc</b>"
|
||||
for name, tc := range map[string]struct {
|
||||
In any
|
||||
Expected any
|
||||
}{
|
||||
"NoHTML": {
|
||||
In: "abc",
|
||||
Expected: "abc",
|
||||
},
|
||||
"String": {
|
||||
In: "<b>abc</b>",
|
||||
Expected: "<b>abc</b>",
|
||||
},
|
||||
"StringPointer": {
|
||||
In: &stringForPointer,
|
||||
Expected: "<b>abc</b>",
|
||||
},
|
||||
"Map": {
|
||||
In: map[string]any{
|
||||
"abc": "abc",
|
||||
"123": "<b>123</b>",
|
||||
},
|
||||
Expected: map[string]any{
|
||||
"abc": "abc",
|
||||
"123": "<b>123</b>",
|
||||
},
|
||||
},
|
||||
"Unsupported": {
|
||||
In: struct{ string }{"<b>abc</b>"},
|
||||
Expected: "",
|
||||
},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert.Equal(t, tc.Expected, escapeForHTML(tc.In))
|
||||
})
|
||||
}
|
||||
}
|
||||
Ссылка в новой задаче
Block a user