Skip to content

Commit 2b79753

Browse files
committed
add stringsutil.ContainsAllI func
1 parent 08a61a6 commit 2b79753

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

strings/stringsutil.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,13 @@ func ContainsAll(s string, ss ...string) bool {
312312
}
313313
return true
314314
}
315+
316+
// ContainsAllI returns true if s contains all specified substrings (case-insensitive).
317+
func ContainsAllI(s string, ss ...string) bool {
318+
for _, sub := range ss {
319+
if !strings.Contains(strings.ToLower(s), strings.ToLower(sub)) {
320+
return false
321+
}
322+
}
323+
return true
324+
}

strings/stringsutil_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,3 +407,20 @@ func TestContainsAll(t *testing.T) {
407407
require.Equal(t, test.result, res)
408408
}
409409
}
410+
411+
func TestContainsAllI(t *testing.T) {
412+
tests := []struct {
413+
s string
414+
ss []string
415+
result bool
416+
}{
417+
{"abcdefg", []string{"A", "b"}, true},
418+
{"abcdefg", []string{"A", "z"}, false},
419+
{"abcdefg", []string{"A", "b", "c", "d", "e", "f", "g"}, true},
420+
{"abcdefg", []string{"A", "b", "c", "d", "e", "f", "g", "z"}, false},
421+
}
422+
for _, test := range tests {
423+
res := ContainsAllI(test.s, test.ss...)
424+
require.Equal(t, test.result, res)
425+
}
426+
}

0 commit comments

Comments
 (0)