1 Star 0 Fork 13

爱你的款/validate

forked from gookit/validate 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
messages_test.go 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
inhere 提交于 2020-06-21 19:58 . up: allow read field map from struct tags
package validate
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestBuiltinMessages(t *testing.T) {
bm := BuiltinMessages()
assert.NotContains(t, bm, "testMsg0")
AddBuiltinMessages(map[string]string{
"testMsg0": "message value",
})
bm = BuiltinMessages()
assert.Contains(t, bm, "testMsg0")
}
func TestErrorsBasic(t *testing.T) {
es := Errors{}
assert.True(t, es.Empty())
assert.Equal(t, "", es.One())
es.Add("test", "v0", "err msg0")
assert.Len(t, es, 1)
assert.Equal(t, "err msg0", es.One())
assert.Equal(t, "err msg0", es.FieldOne("test"))
assert.Equal(t, "test:\n v0: err msg0", es.String())
es.Add("test2", "v1", "err msg2")
assert.Contains(t, fmt.Sprintf("%v", es.All()), "test:map[v0:err msg0]")
assert.Contains(t, fmt.Sprintf("%v", es.All()), "test2:map[v1:err msg2]")
es.Add("test", "v1", "err msg1")
assert.Len(t, es.Field("test"), 2)
}
func TestTranslatorBasic(t *testing.T) {
tr := NewTranslator()
assert.True(t, tr.HasMessage("min"))
assert.False(t, tr.HasMessage("not-exists"))
assert.False(t, tr.HasField("FIELD1"))
tr.AddMessage("FIELD1.min", "{field} message1")
assert.True(t, tr.HasMessage("FIELD1.min"))
assert.Equal(t, "FIELD1 message1", tr.Message("min", "FIELD1"))
tr.AddFieldMap(map[string]string{"FIELD1": "Show Name"})
assert.Equal(t, "Show Name message1", tr.Message("min", "FIELD1"))
tr.Reset()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/xdnice/validate.git
git@gitee.com:xdnice/validate.git
xdnice
validate
validate
master

搜索帮助