gf/util/gvalid/gvalid_z_unit_internal_test.go
2021-10-11 21:41:56 +08:00

45 lines
1.4 KiB
Go

// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package gvalid
import (
"testing"
"github.com/gogf/gf/v2/test/gtest"
)
func Test_parseSequenceTag(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
s := "name@required|length:2,20|password3|same:password1#||密码强度不足|两次密码不一致"
field, rule, msg := parseSequenceTag(s)
t.Assert(field, "name")
t.Assert(rule, "required|length:2,20|password3|same:password1")
t.Assert(msg, "||密码强度不足|两次密码不一致")
})
gtest.C(t, func(t *gtest.T) {
s := "required|length:2,20|password3|same:password1#||密码强度不足|两次密码不一致"
field, rule, msg := parseSequenceTag(s)
t.Assert(field, "")
t.Assert(rule, "required|length:2,20|password3|same:password1")
t.Assert(msg, "||密码强度不足|两次密码不一致")
})
gtest.C(t, func(t *gtest.T) {
s := "required|length:2,20|password3|same:password1"
field, rule, msg := parseSequenceTag(s)
t.Assert(field, "")
t.Assert(rule, "required|length:2,20|password3|same:password1")
t.Assert(msg, "")
})
gtest.C(t, func(t *gtest.T) {
s := "required"
field, rule, msg := parseSequenceTag(s)
t.Assert(field, "")
t.Assert(rule, "required")
t.Assert(msg, "")
})
}