1
0
Fork 0
mirror of https://github.com/vbatts/git-validation.git synced 2024-11-22 16:15:40 +00:00
git-validation/validate/rules_test.go
Vincent Batts 00823a324b
message_regexp: regular expression rule for messages
Fixes: #30

now you can add a regular expression to the rules to be run
i.e. `git-validation -run "dco,message_regexp='^JIRA-[0-9]+ [A-Z].*$'"`

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2017-10-09 16:07:40 -04:00

52 lines
1.1 KiB
Go

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 {
t.Errorf("expected %d A and B comparison to be %t, but got %t", i, set[i].Equal, got)
}
}
}