2016-04-06 00:30:38 +00:00
|
|
|
package strutil
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
2016-07-22 12:44:16 +00:00
|
|
|
func TestStrutil_EquivalentSlices(t *testing.T) {
|
2016-07-22 14:21:45 +00:00
|
|
|
slice1 := []string{"test2", "test1", "test3"}
|
|
|
|
slice2 := []string{"test3", "test2", "test1"}
|
2016-07-22 12:44:16 +00:00
|
|
|
if !EquivalentSlices(slice1, slice2) {
|
|
|
|
t.Fatalf("bad: expected a match")
|
|
|
|
}
|
|
|
|
|
|
|
|
slice2 = append(slice2, "test4")
|
|
|
|
if EquivalentSlices(slice1, slice2) {
|
|
|
|
t.Fatalf("bad: expected a mismatch")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-06 00:30:38 +00:00
|
|
|
func TestStrListContains(t *testing.T) {
|
|
|
|
haystack := []string{
|
|
|
|
"dev",
|
|
|
|
"ops",
|
|
|
|
"prod",
|
|
|
|
"root",
|
|
|
|
}
|
|
|
|
if StrListContains(haystack, "tubez") {
|
|
|
|
t.Fatalf("Bad")
|
|
|
|
}
|
|
|
|
if !StrListContains(haystack, "root") {
|
|
|
|
t.Fatalf("Bad")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStrListSubset(t *testing.T) {
|
|
|
|
parent := []string{
|
|
|
|
"dev",
|
|
|
|
"ops",
|
|
|
|
"prod",
|
|
|
|
"root",
|
|
|
|
}
|
|
|
|
child := []string{
|
|
|
|
"prod",
|
|
|
|
"ops",
|
|
|
|
}
|
|
|
|
if !StrListSubset(parent, child) {
|
|
|
|
t.Fatalf("Bad")
|
|
|
|
}
|
|
|
|
if !StrListSubset(parent, parent) {
|
|
|
|
t.Fatalf("Bad")
|
|
|
|
}
|
|
|
|
if !StrListSubset(child, child) {
|
|
|
|
t.Fatalf("Bad")
|
|
|
|
}
|
|
|
|
if !StrListSubset(child, nil) {
|
|
|
|
t.Fatalf("Bad")
|
|
|
|
}
|
|
|
|
if StrListSubset(child, parent) {
|
|
|
|
t.Fatalf("Bad")
|
|
|
|
}
|
|
|
|
if StrListSubset(nil, child) {
|
|
|
|
t.Fatalf("Bad")
|
|
|
|
}
|
|
|
|
}
|