@@ -8160,6 +8160,49 @@ func TestUniqueValidation(t *testing.T) {
81608160 PanicMatches (t , func () { _ = validate .Var (1.0 , "unique" ) }, "Bad field type float64" )
81618161}
81628162
8163+ func TestUniqueValidationStructSlice (t * testing.T ) {
8164+ testStructs := []struct {
8165+ A string
8166+ B string
8167+ }{
8168+ {A : "one" , B : "two" },
8169+ {A : "one" , B : "three" },
8170+ }
8171+
8172+ tests := []struct {
8173+ target interface {}
8174+ param string
8175+ expected bool
8176+ }{
8177+ {testStructs , "unique" , true },
8178+ {testStructs , "unique=A" , false },
8179+ {testStructs , "unique=B" , true },
8180+ }
8181+
8182+ validate := New ()
8183+
8184+ for i , test := range tests {
8185+
8186+ errs := validate .Var (test .target , test .param )
8187+
8188+ if test .expected {
8189+ if ! IsEqual (errs , nil ) {
8190+ t .Fatalf ("Index: %d unique failed Error: %v" , i , errs )
8191+ }
8192+ } else {
8193+ if IsEqual (errs , nil ) {
8194+ t .Fatalf ("Index: %d unique failed Error: %v" , i , errs )
8195+ } else {
8196+ val := getError (errs , "" , "" )
8197+ if val .Tag () != "unique" {
8198+ t .Fatalf ("Index: %d unique failed Error: %v" , i , errs )
8199+ }
8200+ }
8201+ }
8202+ }
8203+ PanicMatches (t , func () { validate .Var (testStructs , "unique=C" ) }, "Bad field name C" )
8204+ }
8205+
81638206func TestHTMLValidation (t * testing.T ) {
81648207 tests := []struct {
81658208 param string
0 commit comments