Skip to content

Commit

Permalink
Merge pull request #109 from bluesuncorp/v5-development
Browse files Browse the repository at this point in the history
Merge latet changes into v5
  • Loading branch information
Dean Karn authored and Dean Karn committed Jul 9, 2015
2 parents e02a29b + 988489d commit 06aac46
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ func (v *Validate) fieldWithNameAndValue(val interface{}, current interface{}, f
var valueField reflect.Value

// This is a double check if coming from validate.Struct but need to be here in case function is called directly
if tag == noValidationTag {
if tag == noValidationTag || tag == "" {
return nil
}

Expand Down
30 changes: 29 additions & 1 deletion validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,18 @@ func AssertMapFieldError(t *testing.T, s map[string]*FieldError, field string, e
EqualSkip(t, 2, val.Tag, expectedTag)
}

func TestBadKeyValidation(t *testing.T) {
type Test struct {
Name string `validate:"required, "`
}

tst := &Test{
Name: "test",
}

PanicMatches(t, func() { validate.Struct(tst) }, "Invalid validation tag on field Name")
}

func TestFlattenValidation(t *testing.T) {

type Inner struct {
Expand Down Expand Up @@ -606,13 +618,29 @@ func TestInterfaceErrValidation(t *testing.T) {
Equal(t, err.IsPlaceholderErr, false)
Equal(t, err.IsSliceOrArray, false)
Equal(t, len(err.SliceOrArrayErrs), 0)

type MyStruct struct {
A, B string
C interface{}
}

var a MyStruct

a.A = "value"
a.C = "nu"

errs = validate.Struct(a)
Equal(t, errs, nil)
}

func TestMapDiveValidation(t *testing.T) {

n := map[int]interface{}{0: nil}
err := validate.Field(n, "omitempty,required")

m := map[int]string{0: "ok", 3: "", 4: "ok"}

err := validate.Field(m, "len=3,dive,required")
err = validate.Field(m, "len=3,dive,required")
NotEqual(t, err, nil)
Equal(t, err.IsPlaceholderErr, true)
Equal(t, err.IsMap, true)
Expand Down

0 comments on commit 06aac46

Please sign in to comment.