Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ install:
go mod tidy && go mod vendor

tests:
go test -v ./tests
go test -v -covermode=set ./... -coverprofile=coverage.txt && go tool cover -func=coverage.txt
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ utils
[![Go Report Card](https://goreportcard.com/badge/github.com/gouef/utils)](https://goreportcard.com/report/github.com/gouef/utils)
[![codecov](https://codecov.io/github/gouef/utils/branch/main/graph/badge.svg?token=YUG8EMH6Q8)](https://codecov.io/github/gouef/utils)

## Vesions
## Versions
![Stable Version](https://img.shields.io/github/v/release/gouef/utils?label=Stable&labelColor=green)
![GitHub Release](https://img.shields.io/github/v/release/gouef/utils?label=RC&include_prereleases&filter=*rc*&logoSize=diago)
![GitHub Release](https://img.shields.io/github/v/release/gouef/utils?label=Beta&include_prereleases&filter=*beta*&logoSize=diago)
11 changes: 11 additions & 0 deletions array.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ func InArray[T comparable](needle T, haystack []T) bool {
return false
}

func InListArray[T comparable](needles []T, haystack []T) bool {

for _, needle := range needles {
if InArray(needle, haystack) {
return true
}
}

return false
}

func Explode(separator string, stringStr string) []string {
if separator == "" {
return []string{stringStr}
Expand Down
21 changes: 21 additions & 0 deletions tests/array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ func TestInArray(t *testing.T) {
}
}

func TestInListArray(t *testing.T) {
tests := []struct {
needle []string
haystack []string
expected bool
}{
{[]string{"apple"}, []string{"apple", "banana", "cherry"}, true},
{[]string{"cherry"}, []string{"apple", "banana", "cherry"}, true},
{[]string{"pineapple", "banana"}, []string{"apple", "banana", "cherry", "pineapple"}, true},
{[]string{"orange"}, []string{"apple", "banana", "cherry"}, false},
{[]string{""}, []string{"apple", "banana", "cherry"}, false},
}

for _, tt := range tests {
t.Run(utils.Implode("-", tt.needle), func(t *testing.T) {
result := utils.InListArray(tt.needle, tt.haystack)
assert.Equal(t, tt.expected, result)
})
}
}

func TestExplode(t *testing.T) {
tests := []struct {
separator string
Expand Down
Loading