2017-10-09 17:21:23 +00:00
|
|
|
package validate
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSanitizeRules(t *testing.T) {
|
|
|
|
set := []struct {
|
|
|
|
input string
|
|
|
|
output []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
input: "apples, oranges , bananas",
|
|
|
|
output: []string{"apples", "oranges", "bananas"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "apples, oranges , bananas, peaches='with cream'",
|
|
|
|
output: []string{"apples", "oranges", "bananas", "peaches='with cream'"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range set {
|
|
|
|
filt := SanitizeFilters(set[i].input)
|
|
|
|
if !StringsSliceEqual(filt, set[i].output) {
|
|
|
|
t.Errorf("expected output like %v, but got %v", set[i].output, filt)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSliceHelpers(t *testing.T) {
|
|
|
|
set := []struct {
|
|
|
|
A, B []string
|
|
|
|
Equal bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
A: []string{"apples", "bananas", "oranges", "mango"},
|
|
|
|
B: []string{"oranges", "bananas", "apples", "mango"},
|
|
|
|
Equal: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
A: []string{"apples", "bananas", "oranges", "mango"},
|
|
|
|
B: []string{"waffles"},
|
|
|
|
Equal: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for i := range set {
|
|
|
|
got := StringsSliceEqual(set[i].A, set[i].B)
|
|
|
|
if got != set[i].Equal {
|
2017-10-09 19:49:59 +00:00
|
|
|
t.Errorf("expected %d A and B comparison to be %t, but got %t", i, set[i].Equal, got)
|
2017-10-09 17:21:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|