Skip to content

Commit

Permalink
feat(tricks): strings is empty
Browse files Browse the repository at this point in the history
Signed-off-by: Pouyan Heyratpour <[email protected]>
  • Loading branch information
pouyanh committed Dec 21, 2024
1 parent 2f3421f commit a6cc809
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tricks/string.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package tricks

import "strings"

func StringToRunes(src string) []rune {
return []rune(src)
}

func IsEmptyString(s string) bool {
return len(strings.TrimSpace(s)) == 0
}
22 changes: 22 additions & 0 deletions tricks/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,25 @@ func TestStringToRunes(t *testing.T) {
assert.Equal(t, []rune{'a', 'b', ' ', 'c', 'd'}, tricks.StringToRunes("ab cd"))
assert.Equal(t, []rune{'a', 'b', 'b', 'a'}, tricks.StringToRunes("abba"))
}

func TestIsEmptyString(t *testing.T) {
tcc := []struct {
s string
result bool
}{
{"", true},
{" ", true},
{" ", true},
{".", false},
{" .", false},
{" . ", false},
{" _ ", false},
{" - ", false},
{"hello", false},
}

for k, tc := range tcc {
result := tricks.IsEmptyString(tc.s)
assert.Equalf(t, tc.result, result, "test case #%d '%s': expected %v, got %v", k, tc.s, tc.result, result)
}
}

0 comments on commit a6cc809

Please sign in to comment.