diff --git a/builtin.go b/builtin.go index cc1ac0a..fdc2ec0 100644 --- a/builtin.go +++ b/builtin.go @@ -17,9 +17,6 @@ func (f Func) Validate(field Field) Errors { return f(field) } -// FromFunc is DEPRECATED. -type FromFunc = Func - // validateSchema do the validation per the given schema, which is associated // with the given field. func validateSchema(schema Schema, field Field, prefixFunc func(string) string) (errs Errors) { @@ -204,41 +201,6 @@ func Not(validator Validator) (mv *MessageValidator) { return } -// Nested is a composite validator factory used to create a validator, which will -// delegate the actual validation to its inner schema. -// -// This composite validator is DEPRECATED. -func Nested(schema Schema) Validator { - return Func(func(field Field) Errors { - nestedSchema := make(Schema, len(schema)) - for f, v := range schema { - nestedSchema[F(field.Name+f.Name, f.ValuePtr)] = v - } - return Validate(nestedSchema) - }) -} - -// NestedMulti is a composite validator factory used to create a validator, which will -// delegate the actual validation to its inner multiple schemas, which are -// returned by calling f. -// -// This composite validator is DEPRECATED. -func NestedMulti(f func() []Schema) Validator { - schemas := f() - validators := make([]Validator, len(schemas)) - for i, schema := range schemas { - validators[i] = Nested(schema) - } - return Func(func(field Field) (errs Errors) { - for _, v := range validators { - if err := v.Validate(field); err != nil { - errs.Extend(err) - } - } - return - }) -} - // Lazy is a composite validator factory used to create a validator, which will // call f only as needed, to delegate the actual validation to // the validator returned by f. @@ -862,6 +824,3 @@ func Match(re *regexp.Regexp) (mv *MessageValidator) { } return } - -// RegexpMatch is DEPRECATED. -var RegexpMatch = Match diff --git a/validating_test.go b/validating_test.go index 51a9a99..2acdd82 100644 --- a/validating_test.go +++ b/validating_test.go @@ -1,7 +1,6 @@ package validating import ( - "fmt" "math" "reflect" "regexp" @@ -229,56 +228,6 @@ func TestNot(t *testing.T) { } } -func TestNested(t *testing.T) { - cases := []struct { - schemaMaker func() Schema - errs Errors - }{ - { - func() Schema { - post := Post{} - return Schema{ - F("author", &post.Author): Nested(Schema{}), - } - }, - nil, - }, - { - func() Schema { - post := Post{} - return Schema{ - F("author", &post.Author): Nested(Schema{ - F(".name", &post.Author.Name): Nonzero(), - F(".age", &post.Author.Age): Nonzero(), - }), - } - }, - Errors{ - NewError("author.name", ErrInvalid, "is zero valued"), - NewError("author.age", ErrInvalid, "is zero valued"), - }, - }, - { - func() Schema { - post := Post{Author: Author{"russell", 10}} - return Schema{ - F("author", &post.Author): Nested(Schema{ - F(".name", &post.Author.Name): Nonzero(), - F(".age", &post.Author.Age): Nonzero(), - }), - } - }, - nil, - }, - } - for _, c := range cases { - errs := Validate(c.schemaMaker()) - if !reflect.DeepEqual(makeErrsMap(errs), makeErrsMap(c.errs)) { - t.Errorf("Got (%+v) != Want (%+v)", errs, c.errs) - } - } -} - func TestMap(t *testing.T) { cases := []struct { schemaMaker func() Schema @@ -349,7 +298,7 @@ func TestMap(t *testing.T) { } } -func TestNestedSlice(t *testing.T) { +func TestSlice(t *testing.T) { cases := []struct { schemaMaker func() Schema errs Errors @@ -417,72 +366,6 @@ func TestNestedSlice(t *testing.T) { } } -func TestNestedMulti(t *testing.T) { - cases := []struct { - schemaMaker func() Schema - errs Errors - }{ - { - func() Schema { - post := Post{} - return Schema{ - F("comments", &post.Comments): NestedMulti(func() []Schema { - return nil - }), - } - }, - nil, - }, - { - func() Schema { - post := Post{Comments: []Comment{ - {"", time.Time{}}, - }} - return Schema{ - F("comments", &post.Comments): NestedMulti(func() (schemas []Schema) { - for i := range post.Comments { - schemas = append(schemas, Schema{ - F(fmt.Sprintf("[%d].content", i), &post.Comments[i].Content): Nonzero(), - F(fmt.Sprintf("[%d].created_at", i), &post.Comments[i].CreatedAt): Nonzero(), - }) - } - return - }), - } - }, - Errors{ - NewError("comments[0].content", ErrInvalid, "is zero valued"), - NewError("comments[0].created_at", ErrInvalid, "is zero valued"), - }, - }, - { - func() Schema { - post := Post{Comments: []Comment{ - {Content: "thanks", CreatedAt: time.Now()}, - }} - return Schema{ - F("comments", &post.Comments): NestedMulti(func() (schemas []Schema) { - for i := range post.Comments { - schemas = append(schemas, Schema{ - F(fmt.Sprintf("[%d].content", i), &post.Comments[i].Content): Nonzero(), - F(fmt.Sprintf("[%d].created_at", i), &post.Comments[i].CreatedAt): Nonzero(), - }) - } - return - }), - } - }, - nil, - }, - } - for _, c := range cases { - errs := Validate(c.schemaMaker()) - if !reflect.DeepEqual(makeErrsMap(errs), makeErrsMap(c.errs)) { - t.Errorf("Got (%+v) != Want (%+v)", errs, c.errs) - } - } -} - func TestLazy(t *testing.T) { cases := []struct { schemaMaker func(*bool) Schema