@@ -6635,11 +6635,7 @@ func TestStructFiltered(t *testing.T) {
66356635 }
66366636
66376637 p3 := func (ns []byte ) bool {
6638- if bytes .HasSuffix (ns , []byte ("SubTest.Test" )) {
6639- return false
6640- }
6641-
6642- return true
6638+ return ! bytes .HasSuffix (ns , []byte ("SubTest.Test" ))
66436639 }
66446640
66456641 // p4 := []string{
@@ -6956,3 +6952,64 @@ func TestAlphanumericUnicodeValidation(t *testing.T) {
69566952 }
69576953 }
69586954}
6955+
6956+ func TestArrayStructNamespace (t * testing.T ) {
6957+
6958+ validate := New ()
6959+ validate .RegisterTagNameFunc (func (fld reflect.StructField ) string {
6960+ name := strings .SplitN (fld .Tag .Get ("json" ), "," , 2 )[0 ]
6961+
6962+ if name == "-" {
6963+ return ""
6964+ }
6965+
6966+ return name
6967+ })
6968+
6969+ type child struct {
6970+ Name string `json:"name" validate:"required"`
6971+ }
6972+ var input struct {
6973+ Children []child `json:"children" validate:"required,gt=0,dive"`
6974+ }
6975+ input .Children = []child {{"ok" }, {"" }}
6976+
6977+ errs := validate .Struct (input )
6978+ NotEqual (t , errs , nil )
6979+
6980+ ve := errs .(ValidationErrors )
6981+ Equal (t , len (ve ), 1 )
6982+ AssertError (t , errs , "children[1].name" , "Children[1].Name" , "name" , "Name" , "required" )
6983+ }
6984+
6985+ func TestMapStructNamespace (t * testing.T ) {
6986+
6987+ validate := New ()
6988+ validate .RegisterTagNameFunc (func (fld reflect.StructField ) string {
6989+ name := strings .SplitN (fld .Tag .Get ("json" ), "," , 2 )[0 ]
6990+
6991+ if name == "-" {
6992+ return ""
6993+ }
6994+
6995+ return name
6996+ })
6997+
6998+ type child struct {
6999+ Name string `json:"name" validate:"required"`
7000+ }
7001+ var input struct {
7002+ Children map [int ]child `json:"children" validate:"required,gt=0,dive"`
7003+ }
7004+ input .Children = map [int ]child {
7005+ 0 : {Name : "ok" },
7006+ 1 : {Name : "" },
7007+ }
7008+
7009+ errs := validate .Struct (input )
7010+ NotEqual (t , errs , nil )
7011+
7012+ ve := errs .(ValidationErrors )
7013+ Equal (t , len (ve ), 1 )
7014+ AssertError (t , errs , "children[1].name" , "Children[1].Name" , "name" , "Name" , "required" )
7015+ }
0 commit comments