From 383e0eafa611bb11da209765e31867fe7159db5a Mon Sep 17 00:00:00 2001 From: Masahiro Kondou Date: Sun, 22 Aug 2021 13:35:38 +0900 Subject: [PATCH] fix util (#11) --- cmd/cmd_util.go | 5 +++-- cmd/cmd_util_test.go | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 cmd/cmd_util_test.go 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) + } +}