Skip to content

Commit

Permalink
fix util (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
kondoumh authored Aug 22, 2021
1 parent c54d33c commit 383e0ea
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cmd/cmd_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"os"
"strings"

"github.com/MakeNowJust/heredoc/v2"
)
Expand Down Expand Up @@ -31,10 +32,10 @@ func CheckProject(projectName string) {
}
}

// Contains will check if a string is present in a slice
// Contains will check if a string is present in a slice ignoring case
func Contains(s []string, str string) bool {
for _, v := range s {
if v == str {
if strings.ToLower(v) == strings.ToLower(str) {
return true
}
}
Expand Down
19 changes: 19 additions & 0 deletions cmd/cmd_util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import "testing"

func TestContains(t *testing.T) {
strs := []string{"Foo", "Bar", "あああ"}
got := Contains(strs, "foo")
if !got {
t.Errorf("Contains() %v, want %v", got, true)
}
got = Contains(strs, "BAR")
if !got {
t.Errorf("Contains() %v, want %v", got, true)
}
got = Contains(strs, "あああ")
if !got {
t.Errorf("Contains() %v, want %v", got, true)
}
}

0 comments on commit 383e0ea

Please sign in to comment.