influxdb/pkg/slices/strings_test.go

84 lines
1.4 KiB
Go
Raw Normal View History

2018-09-28 14:51:47 +00:00
package slices
import "testing"
func TestExists(t *testing.T) {
tests := []struct {
set []string
find string
output bool
}{
{
set: []string{},
find: "foo",
output: false,
},
{
set: []string{"foo"},
find: "foo",
output: true,
},
{
set: []string{"bar", "foo"},
find: "foo",
output: true,
},
{
set: []string{"bar", "foo"},
find: "stuff",
output: false,
},
{
set: []string{"bar", "Foo"},
find: "foo",
output: false,
},
}
for i, tt := range tests {
actual := Exists(tt.set, tt.find)
if actual != tt.output {
t.Errorf("[%d] set: %v , find: %s , expected: %t , actual: %t", i, tt.set, tt.find, tt.output, actual)
}
}
}
func TestExistsIgnoreCase(t *testing.T) {
tests := []struct {
set []string
find string
output bool
}{
{
set: []string{},
find: "foo",
output: false,
},
{
set: []string{"foo"},
find: "foo",
output: true,
},
{
set: []string{"bar", "foo"},
find: "foo",
output: true,
},
{
set: []string{"bar", "foo"},
find: "stuff",
output: false,
},
{
set: []string{"bar", "Foo"},
find: "foo",
output: true,
},
}
for i, tt := range tests {
actual := ExistsIgnoreCase(tt.set, tt.find)
if actual != tt.output {
t.Errorf("[%d] set: %v , find: %s , expected: %t , actual: %t", i, tt.set, tt.find, tt.output, actual)
}
}
}