File tree 6 files changed +14
-17
lines changed
6 files changed +14
-17
lines changed Original file line number Diff line number Diff line change 5
5
"reflect"
6
6
)
7
7
8
-
9
8
func validateOut (output reflect.Value ) error {
10
9
zeroValue := reflect.Value {}
11
10
if output == zeroValue {
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import (
14
14
// Validations:
15
15
//
16
16
// 1. Input and Output's slice should be of same type
17
- // 2. Predicate function can take one argment and return one argument
17
+ // 2. Predicate function can take one argument and return one argument
18
18
// 3. Predicate's return argument is always boolean.
19
19
// 4. Predicate's input argument should be input/output slice's element type.
20
20
//
Original file line number Diff line number Diff line change @@ -23,23 +23,22 @@ func TestFilter(t *testing.T) {
23
23
24
24
t .Run ("should struct types" , func (t * testing.T ) {
25
25
type person struct {
26
- name string
27
- age int
26
+ age int
28
27
}
29
28
input := []person {
30
- {"john" , 30 },
31
- {"doe" , 20 },
32
- {"foo" , 40 },
33
- {"bar" , 10 },
29
+ {30 },
30
+ {20 },
31
+ {40 },
32
+ {10 },
34
33
}
35
34
var output []person
36
35
37
36
err := godash .Filter (input , & output , func (p person ) bool {
38
37
return p .age > 20
39
38
})
40
39
expected := []person {
41
- {"john" , 30 },
42
- {"foo" , 40 },
40
+ {30 },
41
+ {40 },
43
42
}
44
43
45
44
assert .NoError (t , err )
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
2
2
github.com/davecgh/go-spew v1.1.0 /go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38 =
3
3
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM =
4
4
github.com/pmezard/go-difflib v1.0.0 /go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4 =
5
+ github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4 =
5
6
github.com/stretchr/objx v0.1.0 /go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME =
6
7
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk =
7
8
github.com/stretchr/testify v1.4.0 /go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4 =
Original file line number Diff line number Diff line change @@ -24,12 +24,11 @@ func TestMap(t *testing.T) {
24
24
t .Run ("support structs" , func (t * testing.T ) {
25
25
type person struct {
26
26
name string
27
- age int
28
27
}
29
28
30
29
in := []person {
31
- {name : "john" , age : 20 },
32
- {name : "doe" , age : 23 },
30
+ {name : "john" },
31
+ {name : "doe" },
33
32
}
34
33
out := make ([]string , 0 )
35
34
expected := []string {"john" , "doe" }
Original file line number Diff line number Diff line change @@ -56,13 +56,12 @@ func TestReduce(t *testing.T) {
56
56
57
57
t .Run ("support structs" , func (t * testing.T ) {
58
58
type person struct {
59
- name string
60
- age int
59
+ age int
61
60
}
62
61
63
62
in := []person {
64
- {name : "john" , age : 20 },
65
- {name : "doe" , age : 23 },
63
+ {age : 20 },
64
+ {age : 23 },
66
65
}
67
66
out := 0
68
67
expected := 43
You can’t perform that action at this time.
0 commit comments