Skip to content

Commit

Permalink
Merge pull request #1 from invopop/each-by-fix
Browse files Browse the repository at this point in the history
Each function passes value or pointer to By rules
  • Loading branch information
samlown authored Feb 23, 2023
2 parents 75b205c + f9d0bf7 commit b0498eb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 1 addition & 3 deletions each.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ func (r EachRule) getInterface(value reflect.Value) interface{} {
if value.IsNil() {
return nil
}
return value.Elem().Interface()
default:
return value.Interface()
}
return value.Interface()
}

func (r EachRule) getString(value reflect.Value) string {
Expand Down
13 changes: 13 additions & 0 deletions each_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,16 @@ func TestEachWithContext(t *testing.T) {
assertError(t, test.err, err, test.tag)
}
}

func TestEachAndBy(t *testing.T) {
var byAddr bool
var s string
_ = Each(By(func(v interface{}) error {
_, byAddr = v.(*string)
return nil
})).Validate([]*string{&s})

if !byAddr {
t.Fatal("slice of pointers does not get passed to `By` function by ref")
}
}

0 comments on commit b0498eb

Please sign in to comment.