zh/zh_tw/ko add test case for required_if/required_unless/required_with/required_with_all/required_without/required_without_all

pull/947/head
kakuilan 3 years ago
parent 0aa3d587e9
commit 04582ec18f
  1. 50
      translations/ko/ko_test.go
  2. 55
      translations/zh/zh_test.go
  3. 56
      translations/zh_tw/zh_tw_test.go

@ -22,12 +22,17 @@ func TestTranslations(t *testing.T) {
Equal(t, err, nil)
type Inner struct {
EqCSFieldString string
NeCSFieldString string
GtCSFieldString string
GteCSFieldString string
LtCSFieldString string
LteCSFieldString string
EqCSFieldString string
NeCSFieldString string
GtCSFieldString string
GteCSFieldString string
LtCSFieldString string
LteCSFieldString string
RequiredIf string
RequiredUnless string
RequiredWith string
RequiredWithout string
RequiredWithoutAll string
}
type Test struct {
@ -35,6 +40,12 @@ func TestTranslations(t *testing.T) {
RequiredString string `validate:"required"`
RequiredNumber int `validate:"required"`
RequiredMultiple []string `validate:"required"`
RequiredIf string `validate:"required_if=Inner.RequiredIf abcd"`
RequiredUnless string `validate:"required_unless=Inner.RequiredUnless abcd"`
RequiredWith string `validate:"required_with=Inner.RequiredWith"`
RequiredWithAll string `validate:"required_with_all=Inner.GtCSFieldString Inner.GteCSFieldString"`
RequiredWithout string `validate:"required_without=Inner.RequiredWithout"`
RequiredWithoutAll string `validate:"required_without_all=Inner.RequiredUnless Inner.RequiredWithout"`
LenString string `validate:"len=1"`
LenNumber float64 `validate:"len=1113.00"`
LenMultiple []string `validate:"len=7"`
@ -161,6 +172,9 @@ func TestTranslations(t *testing.T) {
test.Inner.EqCSFieldString = "1234"
test.Inner.GtCSFieldString = "1234"
test.Inner.GteCSFieldString = "1234"
test.Inner.RequiredIf = "abcd"
test.Inner.RequiredUnless = ""
test.Inner.RequiredWith = "abcd"
test.MaxString = "1234"
test.MaxNumber = 2000
@ -638,6 +652,30 @@ func TestTranslations(t *testing.T) {
ns: "Test.RequiredMultiple",
expected: "RequiredMultiple필요한필드입니다",
},
{
ns: "Test.RequiredIf",
expected: "RequiredIf필요한필드입니다",
},
{
ns: "Test.RequiredUnless",
expected: "RequiredUnless필요한필드입니다",
},
{
ns: "Test.RequiredWith",
expected: "RequiredWith필요한필드입니다",
},
{
ns: "Test.RequiredWithAll",
expected: "RequiredWithAll필요한필드입니다",
},
{
ns: "Test.RequiredWithout",
expected: "RequiredWithout필요한필드입니다",
},
{
ns: "Test.RequiredWithoutAll",
expected: "RequiredWithoutAll필요한필드입니다",
},
{
ns: "Test.StrPtrMinLen",
expected: "StrPtrMinLen길이는10자이상이어야합니다",

@ -5,14 +5,14 @@ import (
"time"
. "github.com/go-playground/assert/v2"
zhongwen "github.com/go-playground/locales/zh"
chinese "github.com/go-playground/locales/zh"
ut "github.com/go-playground/universal-translator"
"github.com/go-playground/validator/v10"
)
func TestTranslations(t *testing.T) {
zh := zhongwen.New()
zh := chinese.New()
uni := ut.New(zh, zh)
trans, _ := uni.GetTranslator("zh")
@ -22,12 +22,17 @@ func TestTranslations(t *testing.T) {
Equal(t, err, nil)
type Inner struct {
EqCSFieldString string
NeCSFieldString string
GtCSFieldString string
GteCSFieldString string
LtCSFieldString string
LteCSFieldString string
EqCSFieldString string
NeCSFieldString string
GtCSFieldString string
GteCSFieldString string
LtCSFieldString string
LteCSFieldString string
RequiredIf string
RequiredUnless string
RequiredWith string
RequiredWithout string
RequiredWithoutAll string
}
type Test struct {
@ -35,6 +40,12 @@ func TestTranslations(t *testing.T) {
RequiredString string `validate:"required"`
RequiredNumber int `validate:"required"`
RequiredMultiple []string `validate:"required"`
RequiredIf string `validate:"required_if=Inner.RequiredIf abcd"`
RequiredUnless string `validate:"required_unless=Inner.RequiredUnless abcd"`
RequiredWith string `validate:"required_with=Inner.RequiredWith"`
RequiredWithAll string `validate:"required_with_all=Inner.GtCSFieldString Inner.GteCSFieldString"`
RequiredWithout string `validate:"required_without=Inner.RequiredWithout"`
RequiredWithoutAll string `validate:"required_without_all=Inner.RequiredUnless Inner.RequiredWithout"`
LenString string `validate:"len=1"`
LenNumber float64 `validate:"len=1113.00"`
LenMultiple []string `validate:"len=7"`
@ -161,6 +172,9 @@ func TestTranslations(t *testing.T) {
test.Inner.EqCSFieldString = "1234"
test.Inner.GtCSFieldString = "1234"
test.Inner.GteCSFieldString = "1234"
test.Inner.RequiredIf = "abcd"
test.Inner.RequiredUnless = ""
test.Inner.RequiredWith = "abcd"
test.MaxString = "1234"
test.MaxNumber = 2000
@ -226,6 +240,7 @@ func TestTranslations(t *testing.T) {
ns string
expected string
}{
{
ns: "Test.IsColor",
expected: "IsColor必须是一个有效的颜色",
@ -638,6 +653,30 @@ func TestTranslations(t *testing.T) {
ns: "Test.RequiredMultiple",
expected: "RequiredMultiple为必填字段",
},
{
ns: "Test.RequiredIf",
expected: "RequiredIf为必填字段",
},
{
ns: "Test.RequiredUnless",
expected: "RequiredUnless为必填字段",
},
{
ns: "Test.RequiredWith",
expected: "RequiredWith为必填字段",
},
{
ns: "Test.RequiredWithAll",
expected: "RequiredWithAll为必填字段",
},
{
ns: "Test.RequiredWithout",
expected: "RequiredWithout为必填字段",
},
{
ns: "Test.RequiredWithoutAll",
expected: "RequiredWithoutAll为必填字段",
},
{
ns: "Test.StrPtrMinLen",
expected: "StrPtrMinLen长度必须至少为10个字符",

@ -5,16 +5,16 @@ import (
"time"
. "github.com/go-playground/assert/v2"
zhongwen "github.com/go-playground/locales/zh_Hant_TW"
chinese "github.com/go-playground/locales/zh_Hant_TW"
ut "github.com/go-playground/universal-translator"
"github.com/go-playground/validator/v10"
)
func TestTranslations(t *testing.T) {
zh := zhongwen.New()
zh := chinese.New()
uni := ut.New(zh, zh)
trans, _ := uni.GetTranslator("zh")
trans, _ := uni.GetTranslator("zh_tw")
validate := validator.New()
@ -22,12 +22,17 @@ func TestTranslations(t *testing.T) {
Equal(t, err, nil)
type Inner struct {
EqCSFieldString string
NeCSFieldString string
GtCSFieldString string
GteCSFieldString string
LtCSFieldString string
LteCSFieldString string
EqCSFieldString string
NeCSFieldString string
GtCSFieldString string
GteCSFieldString string
LtCSFieldString string
LteCSFieldString string
RequiredIf string
RequiredUnless string
RequiredWith string
RequiredWithout string
RequiredWithoutAll string
}
type Test struct {
@ -35,6 +40,12 @@ func TestTranslations(t *testing.T) {
RequiredString string `validate:"required"`
RequiredNumber int `validate:"required"`
RequiredMultiple []string `validate:"required"`
RequiredIf string `validate:"required_if=Inner.RequiredIf abcd"`
RequiredUnless string `validate:"required_unless=Inner.RequiredUnless abcd"`
RequiredWith string `validate:"required_with=Inner.RequiredWith"`
RequiredWithAll string `validate:"required_with_all=Inner.GtCSFieldString Inner.GteCSFieldString"`
RequiredWithout string `validate:"required_without=Inner.RequiredWithout"`
RequiredWithoutAll string `validate:"required_without_all=Inner.RequiredUnless Inner.RequiredWithout"`
LenString string `validate:"len=1"`
LenNumber float64 `validate:"len=1113.00"`
LenMultiple []string `validate:"len=7"`
@ -161,6 +172,9 @@ func TestTranslations(t *testing.T) {
test.Inner.EqCSFieldString = "1234"
test.Inner.GtCSFieldString = "1234"
test.Inner.GteCSFieldString = "1234"
test.Inner.RequiredIf = "abcd"
test.Inner.RequiredUnless = ""
test.Inner.RequiredWith = "abcd"
test.MaxString = "1234"
test.MaxNumber = 2000
@ -638,6 +652,30 @@ func TestTranslations(t *testing.T) {
ns: "Test.RequiredMultiple",
expected: "RequiredMultiple為必填欄位",
},
{
ns: "Test.RequiredIf",
expected: "RequiredIf為必填欄位",
},
{
ns: "Test.RequiredUnless",
expected: "RequiredUnless為必填欄位",
},
{
ns: "Test.RequiredWith",
expected: "RequiredWith為必填欄位",
},
{
ns: "Test.RequiredWithAll",
expected: "RequiredWithAll為必填欄位",
},
{
ns: "Test.RequiredWithout",
expected: "RequiredWithout為必填欄位",
},
{
ns: "Test.RequiredWithoutAll",
expected: "RequiredWithoutAll為必填欄位",
},
{
ns: "Test.StrPtrMinLen",
expected: "StrPtrMinLen長度必須至少為10個字元",

Loading…
Cancel
Save