mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
strings: Add ContainsAny and ContainsRune to correspond to IndexAny etc.
R=golang-dev, r CC=golang-dev https://golang.org/cl/5430046
This commit is contained in:
parent
da62104169
commit
0f0c25dccc
2 changed files with 63 additions and 3 deletions
|
|
@ -908,6 +908,56 @@ func TestContains(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
var ContainsAnyTests = []struct {
|
||||
str, substr string
|
||||
expected bool
|
||||
}{
|
||||
{"", "", false},
|
||||
{"", "a", false},
|
||||
{"", "abc", false},
|
||||
{"a", "", false},
|
||||
{"a", "a", true},
|
||||
{"aaa", "a", true},
|
||||
{"abc", "xyz", false},
|
||||
{"abc", "xcz", true},
|
||||
{"a☺b☻c☹d", "uvw☻xyz", true},
|
||||
{"aRegExp*", ".(|)*+?^$[]", true},
|
||||
{dots + dots + dots, " ", false},
|
||||
}
|
||||
|
||||
func TestContainsAny(t *testing.T) {
|
||||
for _, ct := range ContainsAnyTests {
|
||||
if ContainsAny(ct.str, ct.substr) != ct.expected {
|
||||
t.Errorf("ContainsAny(%s, %s) = %v, want %v",
|
||||
ct.str, ct.substr, !ct.expected, ct.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var ContainsRuneTests = []struct {
|
||||
str string
|
||||
r rune
|
||||
expected bool
|
||||
}{
|
||||
{"", 'a', false},
|
||||
{"a", 'a', true},
|
||||
{"aaa", 'a', true},
|
||||
{"abc", 'y', false},
|
||||
{"abc", 'c', true},
|
||||
{"a☺b☻c☹d", 'x', false},
|
||||
{"a☺b☻c☹d", '☻', true},
|
||||
{"aRegExp*", '*', true},
|
||||
}
|
||||
|
||||
func TestContainsRune(t *testing.T) {
|
||||
for _, ct := range ContainsRuneTests {
|
||||
if ContainsRune(ct.str, ct.r) != ct.expected {
|
||||
t.Errorf("ContainsRune(%s, %s) = %v, want %v",
|
||||
ct.str, ct.r, !ct.expected, ct.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var EqualFoldTests = []struct {
|
||||
s, t string
|
||||
out bool
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue