diff options
Diffstat (limited to 'modules/util')
-rw-r--r-- | modules/util/util.go | 5 | ||||
-rw-r--r-- | modules/util/util_test.go | 17 |
2 files changed, 22 insertions, 0 deletions
diff --git a/modules/util/util.go b/modules/util/util.go index 5dcbe448fc..b2067c8df6 100644 --- a/modules/util/util.go +++ b/modules/util/util.go @@ -98,3 +98,8 @@ func Min(a, b int) int { } return a } + +// IsEmptyString checks if the provided string is empty +func IsEmptyString(s string) bool { + return len(strings.TrimSpace(s)) == 0 +} diff --git a/modules/util/util_test.go b/modules/util/util_test.go index d9357ffa3d..3a2b4b71ff 100644 --- a/modules/util/util_test.go +++ b/modules/util/util_test.go @@ -77,3 +77,20 @@ func TestIsExternalURL(t *testing.T) { assert.Equal(t, test.Expected, IsExternalURL(test.RawURL)) } } + +func TestIsEmptyString(t *testing.T) { + + cases := []struct { + s string + expected bool + }{ + {"", true}, + {" ", true}, + {" ", true}, + {" a", false}, + } + + for _, v := range cases { + assert.Equal(t, v.expected, IsEmptyString(v.s)) + } +} |