mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
strings: Contains
Tiny helper to avoid strings.Index(s, sub) != -1 R=rsc, r2, r CC=golang-dev https://golang.org/cl/2265044
This commit is contained in:
parent
e8436689ad
commit
e198a5086a
11 changed files with 38 additions and 12 deletions
|
|
@ -739,3 +739,24 @@ func TestTitle(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
type ContainsTest struct {
|
||||
str, substr string
|
||||
expected bool
|
||||
}
|
||||
|
||||
var ContainsTests = []ContainsTest{
|
||||
{"abc", "bc", true},
|
||||
{"abc", "bcd", false},
|
||||
{"abc", "", true},
|
||||
{"", "a", false},
|
||||
}
|
||||
|
||||
func TestContains(t *testing.T) {
|
||||
for _, ct := range ContainsTests {
|
||||
if Contains(ct.str, ct.substr) != ct.expected {
|
||||
t.Errorf("Contains(%s, %s) = %v, want %v",
|
||||
ct.str, ct.substr, !ct.expected, ct.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue