Skip to content

Commit b0498eb

Browse files
authored
Merge pull request #1 from invopop/each-by-fix
Each function passes value or pointer to By rules
2 parents 75b205c + f9d0bf7 commit b0498eb

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

each.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,8 @@ func (r EachRule) getInterface(value reflect.Value) interface{} {
7878
if value.IsNil() {
7979
return nil
8080
}
81-
return value.Elem().Interface()
82-
default:
83-
return value.Interface()
8481
}
82+
return value.Interface()
8583
}
8684

8785
func (r EachRule) getString(value reflect.Value) string {

each_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,16 @@ func TestEachWithContext(t *testing.T) {
7272
assertError(t, test.err, err, test.tag)
7373
}
7474
}
75+
76+
func TestEachAndBy(t *testing.T) {
77+
var byAddr bool
78+
var s string
79+
_ = Each(By(func(v interface{}) error {
80+
_, byAddr = v.(*string)
81+
return nil
82+
})).Validate([]*string{&s})
83+
84+
if !byAddr {
85+
t.Fatal("slice of pointers does not get passed to `By` function by ref")
86+
}
87+
}

0 commit comments

Comments
 (0)