Merge pull request #110 from bluesuncorp/v5

merge latest changes from v5
pull/115/head
Dean Karn 10 years ago
commit ed304c7fdf
  1. 12
      README.md
  2. 2
      validator.go
  3. 30
      validator_test.go

@ -1,5 +1,7 @@
Package validator Package validator
================ ================
[![Join the chat at https://gitter.im/bluesuncorp/validator](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/bluesuncorp/validator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build Status](https://travis-ci.org/bluesuncorp/validator.svg?branch=v5.1)](https://travis-ci.org/bluesuncorp/validator) [![Build Status](https://travis-ci.org/bluesuncorp/validator.svg?branch=v5.1)](https://travis-ci.org/bluesuncorp/validator)
[![Coverage Status](https://coveralls.io/repos/bluesuncorp/validator/badge.svg?branch=v5)](https://coveralls.io/r/bluesuncorp/validator?branch=v5) [![Coverage Status](https://coveralls.io/repos/bluesuncorp/validator/badge.svg?branch=v5)](https://coveralls.io/r/bluesuncorp/validator?branch=v5)
[![GoDoc](https://godoc.org/gopkg.in/bluesuncorp/validator.v5?status.svg)](https://godoc.org/gopkg.in/bluesuncorp/validator.v5) [![GoDoc](https://godoc.org/gopkg.in/bluesuncorp/validator.v5?status.svg)](https://godoc.org/gopkg.in/bluesuncorp/validator.v5)
@ -127,11 +129,11 @@ Benchmarks
```go ```go
$ go test -cpu=4 -bench=. -benchmem=true $ go test -cpu=4 -bench=. -benchmem=true
PASS PASS
BenchmarkValidateField-4 3000000 436 ns/op 192 B/op 2 allocs/op BenchmarkValidateField-4 3000000 429 ns/op 192 B/op 2 allocs/op
BenchmarkValidateStructSimple-4 500000 2863 ns/op 784 B/op 13 allocs/op BenchmarkValidateStructSimple-4 500000 2877 ns/op 657 B/op 10 allocs/op
BenchmarkTemplateParallelSimple-4 500000 3044 ns/op 784 B/op 13 allocs/op BenchmarkTemplateParallelSimple-4 500000 3097 ns/op 657 B/op 10 allocs/op
BenchmarkValidateStructLarge-4 100000 15226 ns/op 4853 B/op 74 allocs/op BenchmarkValidateStructLarge-4 100000 15228 ns/op 4350 B/op 62 allocs/op
BenchmarkTemplateParallelLarge-4 100000 14637 ns/op 4856 B/op 74 allocs/op BenchmarkTemplateParallelLarge-4 100000 14257 ns/op 4354 B/op 62 allocs/op
``` ```
How to Contribute How to Contribute

@ -610,7 +610,7 @@ func (v *Validate) fieldWithNameAndValue(val interface{}, current interface{}, f
var valueField reflect.Value 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 // 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 return nil
} }

@ -231,6 +231,18 @@ func AssertMapFieldError(t *testing.T, s map[string]*FieldError, field string, e
EqualSkip(t, 2, val.Tag, expectedTag) 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) { func TestFlattenValidation(t *testing.T) {
type Inner struct { type Inner struct {
@ -606,13 +618,29 @@ func TestInterfaceErrValidation(t *testing.T) {
Equal(t, err.IsPlaceholderErr, false) Equal(t, err.IsPlaceholderErr, false)
Equal(t, err.IsSliceOrArray, false) Equal(t, err.IsSliceOrArray, false)
Equal(t, len(err.SliceOrArrayErrs), 0) 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) { 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"} 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) NotEqual(t, err, nil)
Equal(t, err.IsPlaceholderErr, true) Equal(t, err.IsPlaceholderErr, true)
Equal(t, err.IsMap, true) Equal(t, err.IsMap, true)

Loading…
Cancel
Save