diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2018-09-19 20:36:40 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2018-09-19 20:36:40 +1000 |
commit | b9708c9f8850352d18ef4d10c285698be882f838 (patch) | |
tree | 8de824457cbbc104f4dd7290213b80708465daa1 /pkg/utils | |
parent | 7b90d2496b56d89863b552b226f45b8de2bd1551 (diff) |
fix issues with commit message panel losing focus
Diffstat (limited to 'pkg/utils')
-rw-r--r-- | pkg/utils/utils.go | 10 | ||||
-rw-r--r-- | pkg/utils/utils_test.go | 35 |
2 files changed, 45 insertions, 0 deletions
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index aef653c50..8e481b3a4 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -204,3 +204,13 @@ func getDisplayStringArrays(displayables []Displayable) [][]string { } return stringArrays } + +// IncludesString if the list contains the string +func IncludesString(list []string, a string) bool { + for _, b := range list { + if b == a { + return true + } + } + return false +} diff --git a/pkg/utils/utils_test.go b/pkg/utils/utils_test.go index 918031512..21e1d5031 100644 --- a/pkg/utils/utils_test.go +++ b/pkg/utils/utils_test.go @@ -376,3 +376,38 @@ func TestMin(t *testing.T) { assert.EqualValues(t, s.expected, Min(s.a, s.b)) } } + +func TestIncludesString(t *testing.T) { + type scenario struct { + list []string + element string + expected bool + } + + scenarios := []scenario{ + { + []string{"a", "b"}, + "a", + true, + }, + { + []string{"a", "b"}, + "c", + false, + }, + { + []string{"a", "b"}, + "", + false, + }, + { + []string{""}, + "", + true, + }, + } + + for _, s := range scenarios { + assert.EqualValues(t, s.expected, IncludesString(s.list, s.element)) + } +} |