Initial commit of modash
This was taken from github.com/lmika/gopkgs/fp
This commit is contained in:
commit
a20530ddfd
20 changed files with 425 additions and 0 deletions
29
moslice/filter_test.go
Normal file
29
moslice/filter_test.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package moslice_test
|
||||
|
||||
import (
|
||||
"lmika.dev/pkg/modash/moslice"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestFilter(t *testing.T) {
|
||||
var (
|
||||
ints = []int{1, 2, 3, 4, 5}
|
||||
strs = []string{"foo", "bar", "baz"}
|
||||
)
|
||||
|
||||
t.Run("should filter items matching the predicate", func(t *testing.T) {
|
||||
assert.Equal(t, []int{2, 4}, moslice.Filter(ints, func(x int) bool { return x%2 == 0 }))
|
||||
assert.Equal(t, []string{"bar", "baz"}, moslice.Filter(strs, func(x string) bool { return strings.Contains(x, "b") }))
|
||||
})
|
||||
|
||||
t.Run("should moslice nil if the passed in slice is nil", func(t *testing.T) {
|
||||
assert.Nil(t, moslice.Filter(nil, func(x int) bool { return x%2 == 0 }))
|
||||
})
|
||||
|
||||
t.Run("should return empty slice if the passed in slice is empty slice", func(t *testing.T) {
|
||||
assert.Equal(t, []int{}, moslice.Filter([]int{}, func(x int) bool { return x%2 == 0 }))
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue