diff --git a/cmd/cmd_util.go b/cmd/cmd_util.go index 9740bfa..a78f1d5 100644 --- a/cmd/cmd_util.go +++ b/cmd/cmd_util.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" "os" + "strings" "github.com/MakeNowJust/heredoc/v2" ) @@ -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 } } diff --git a/cmd/cmd_util_test.go b/cmd/cmd_util_test.go new file mode 100644 index 0000000..7b055e5 --- /dev/null +++ b/cmd/cmd_util_test.go @@ -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) + } +}