Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 89 additions & 1 deletion validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10202,6 +10202,28 @@ func TestExcludedWith(t *testing.T) {
name := fmt.Sprintf("Field%d", i)
AssertError(t, errs, name, name, name, name, "excluded_with")
}

test3 := struct {
Inner *Inner
Inner2 *Inner
Field string `validate:"omitempty" json:"field"`
FieldE string `validate:"omitempty" json:"field_e"`
Field1 string `validate:"excluded_with=FieldE" json:"field_1"`
Field2 *string `validate:"excluded_with=FieldE" json:"field_2"`
Field3 map[string]string `validate:"excluded_with=FieldE" json:"field_3"`
Field4 interface{} `validate:"excluded_with=FieldE" json:"field_4"`
Field5 string `validate:"excluded_with=Inner.FieldE" json:"field_5"`
Field6 string `validate:"excluded_with=Inner2.FieldE" json:"field_6"`
}{
Inner: &Inner{FieldE: "populated"},
Inner2: &Inner{FieldE: "populated"},
FieldE: "populated",
}

validate = New()

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

func TestExcludedWithout(t *testing.T) {
Expand Down Expand Up @@ -10266,6 +10288,26 @@ func TestExcludedWithout(t *testing.T) {
name := fmt.Sprintf("Field%d", i)
AssertError(t, errs, name, name, name, name, "excluded_without")
}

test3 := struct {
Inner *Inner
Inner2 *Inner
Field string `validate:"omitempty" json:"field"`
FieldE string `validate:"omitempty" json:"field_e"`
Field1 string `validate:"excluded_without=Field" json:"field_1"`
Field2 *string `validate:"excluded_without=Field" json:"field_2"`
Field3 map[string]string `validate:"excluded_without=Field" json:"field_3"`
Field4 interface{} `validate:"excluded_without=Field" json:"field_4"`
Field5 string `validate:"excluded_without=Inner.Field" json:"field_5"`
}{
Inner: &Inner{Field: &fieldVal},
Field: "populated",
}

validate = New()

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

func TestExcludedWithAll(t *testing.T) {
Expand Down Expand Up @@ -10334,6 +10376,29 @@ func TestExcludedWithAll(t *testing.T) {
name := fmt.Sprintf("Field%d", i)
AssertError(t, errs, name, name, name, name, "excluded_with_all")
}

test3 := struct {
Inner *Inner
Inner2 *Inner
Field string `validate:"omitempty" json:"field"`
FieldE string `validate:"omitempty" json:"field_e"`
Field1 string `validate:"excluded_with_all=FieldE Field" json:"field_1"`
Field2 *string `validate:"excluded_with_all=FieldE Field" json:"field_2"`
Field3 map[string]string `validate:"excluded_with_all=FieldE Field" json:"field_3"`
Field4 interface{} `validate:"excluded_with_all=FieldE Field" json:"field_4"`
Field5 string `validate:"excluded_with_all=Inner.FieldE" json:"field_5"`
Field6 string `validate:"excluded_with_all=Inner2.FieldE" json:"field_6"`
}{
Inner: &Inner{FieldE: "populated"},
Inner2: &Inner{FieldE: "populated"},
Field: "populated",
FieldE: "populated",
}

validate = New()

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

func TestExcludedWithoutAll(t *testing.T) {
Expand All @@ -10352,9 +10417,10 @@ func TestExcludedWithoutAll(t *testing.T) {
Field2 *string `validate:"excluded_without_all=Field FieldE" json:"field_2"`
Field3 map[string]string `validate:"excluded_without_all=Field FieldE" json:"field_3"`
Field4 interface{} `validate:"excluded_without_all=Field FieldE" json:"field_4"`
Field5 string `validate:"excluded_without_all=Inner.Field Inner.Field2" json:"field_5"`
Field5 string `validate:"excluded_without_all=Inner.Field Inner2.Field" json:"field_5"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed like a typo

}{
Inner: &Inner{Field: &fieldVal},
Inner2: &Inner{Field: &fieldVal},
Field: "populated",
Field1: fieldVal,
Field2: &fieldVal,
Expand Down Expand Up @@ -10398,6 +10464,28 @@ func TestExcludedWithoutAll(t *testing.T) {
name := fmt.Sprintf("Field%d", i)
AssertError(t, errs, name, name, name, name, "excluded_without_all")
}

test3 := struct {
Inner *Inner
Inner2 *Inner
Field string `validate:"omitempty" json:"field"`
FieldE string `validate:"omitempty" json:"field_e"`
Field1 string `validate:"excluded_without_all=Field FieldE" json:"field_1"`
Field2 *string `validate:"excluded_without_all=Field FieldE" json:"field_2"`
Field3 map[string]string `validate:"excluded_without_all=Field FieldE" json:"field_3"`
Field4 interface{} `validate:"excluded_without_all=Field FieldE" json:"field_4"`
Field5 string `validate:"excluded_without_all=Inner.Field Inner2.Field" json:"field_5"`
}{
Inner: &Inner{Field: &fieldVal},
Inner2: &Inner{Field: &fieldVal},
Field: "populated",
FieldE: "populated",
}

validate = New()

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

func TestRequiredWithAll(t *testing.T) {
Expand Down