Skip to content

Commit

Permalink
✨ feat: str - add new func for check ignore case string
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jan 28, 2023
1 parent b3d7669 commit 746eb35
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
14 changes: 12 additions & 2 deletions strutil/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,17 @@ func BytePos(s string, bt byte) int {
return strings.IndexByte(s, bt)
}

// ContainsOne substr(s) in the given string.
// IEqual ignore case check given two string is equals.
func IEqual(s1 string, s2 string) bool {
return strings.ToLower(s1) == strings.ToLower(s2)
}

// IContains ignore case check substr in the given string.
func IContains(s string, sub string) bool {
return strings.Contains(strings.ToLower(s), strings.ToLower(sub))
}

// ContainsOne substr(s) in the given string. alias of HasOneSub()
func ContainsOne(s string, subs []string) bool {
return HasOneSub(s, subs)
}
Expand All @@ -71,7 +81,7 @@ func HasOneSub(s string, subs []string) bool {
return false
}

// ContainsAll substr(s) in the given string.
// ContainsAll substr(s) in the given string. alias of HasAllSubs()
func ContainsAll(s string, subs []string) bool {
return HasAllSubs(s, subs)
}
Expand Down
16 changes: 16 additions & 0 deletions strutil/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,30 @@ func TestIsVersion(t *testing.T) {
assert.True(t, strutil.IsVersion("1.2.0-alpha1"))
}

func TestIEqual(t *testing.T) {
assert.False(t, strutil.IEqual("h3ab2c", "d"))
assert.False(t, strutil.IEqual("ab", "ac"))
assert.True(t, strutil.IEqual("ab", "AB"))
assert.True(t, strutil.IEqual("ab", "Ab"))
assert.True(t, strutil.IEqual("ab", "ab"))
}

func TestIContains(t *testing.T) {
assert.False(t, strutil.IContains("h3ab2c", "d"))
assert.True(t, strutil.IContains("h3ab2c", "AB"))
assert.True(t, strutil.IContains("H3AB2C", "aB"))
}

func TestHasOneSub(t *testing.T) {
assert.False(t, strutil.ContainsOne("h3ab2c", []string{"d"}))
assert.False(t, strutil.HasOneSub("h3ab2c", []string{"d"}))
assert.True(t, strutil.HasOneSub("h3ab2c", []string{"ab"}))
}

func TestHasAllSubs(t *testing.T) {
assert.False(t, strutil.HasAllSubs("h3ab2c", []string{"a", "d"}))
assert.True(t, strutil.HasAllSubs("h3ab2c", []string{"a", "b"}))
assert.True(t, strutil.ContainsAll("h3ab2c", []string{"a", "b"}))
}

func TestVersionCompare(t *testing.T) {
Expand Down

0 comments on commit 746eb35

Please sign in to comment.