@ -8555,3 +8555,59 @@ func TestDirValidation(t *testing.T) {
validate . Var ( 2 , "dir" )
validate . Var ( 2 , "dir" )
} , "Bad field type int" )
} , "Bad field type int" )
}
}
func TestStartsWithValidation ( t * testing . T ) {
tests := [ ] struct {
Value string ` validate:"startswith=(/^ヮ^)/*:・゚✧" `
Tag string
ExpectedNil bool
} {
{ Value : "(/^ヮ^)/*:・゚✧ glitter" , Tag : "startswith=(/^ヮ^)/*:・゚✧" , ExpectedNil : true } ,
{ Value : "abcd" , Tag : "startswith=(/^ヮ^)/*:・゚✧" , ExpectedNil : false } ,
}
validate := New ( )
for i , s := range tests {
errs := validate . Var ( s . Value , s . Tag )
if ( s . ExpectedNil && errs != nil ) || ( ! s . ExpectedNil && errs == nil ) {
t . Fatalf ( "Index: %d failed Error: %s" , i , errs )
}
errs = validate . Struct ( s )
if ( s . ExpectedNil && errs != nil ) || ( ! s . ExpectedNil && errs == nil ) {
t . Fatalf ( "Index: %d failed Error: %s" , i , errs )
}
}
}
func TestEndsWithValidation ( t * testing . T ) {
tests := [ ] struct {
Value string ` validate:"endswith=(/^ヮ^)/*:・゚✧" `
Tag string
ExpectedNil bool
} {
{ Value : "glitter (/^ヮ^)/*:・゚✧" , Tag : "endswith=(/^ヮ^)/*:・゚✧" , ExpectedNil : true } ,
{ Value : "(/^ヮ^)/*:・゚✧ glitter" , Tag : "endswith=(/^ヮ^)/*:・゚✧" , ExpectedNil : false } ,
}
validate := New ( )
for i , s := range tests {
errs := validate . Var ( s . Value , s . Tag )
if ( s . ExpectedNil && errs != nil ) || ( ! s . ExpectedNil && errs == nil ) {
t . Fatalf ( "Index: %d failed Error: %s" , i , errs )
}
errs = validate . Struct ( s )
if ( s . ExpectedNil && errs != nil ) || ( ! s . ExpectedNil && errs == nil ) {
t . Fatalf ( "Index: %d failed Error: %s" , i , errs )
}
}
}