added tests for regex match
This commit is contained in:
parent
84c204cedf
commit
9e578a9e19
1 changed files with 31 additions and 0 deletions
|
@ -123,6 +123,37 @@ func TestFilterReplace(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFilterMatch(t *testing.T) {
|
||||||
|
var tests = []struct {
|
||||||
|
Input string
|
||||||
|
Query string
|
||||||
|
Want []string
|
||||||
|
}{
|
||||||
|
{"0123456789", "0123|789", []string{"0123", "789"}},
|
||||||
|
{"0123456789", "abc|321", []string{}},
|
||||||
|
{"0123456789", "[0-9]{3}", []string{"012", "345", "678"}},
|
||||||
|
{"世界日本語", "日本", []string{"日本"}},
|
||||||
|
{"世界日本語_世界日本語_世界日本語", "日本", []string{"日本", "日本", "日本"}},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
testname := fmt.Sprintf("%s", test.Query)
|
||||||
|
t.Run(testname, func(t *testing.T) {
|
||||||
|
want := []string{}
|
||||||
|
getFilterResultMatch(
|
||||||
|
test.Input,
|
||||||
|
&Filter{
|
||||||
|
From: test.Query,
|
||||||
|
},
|
||||||
|
&want,
|
||||||
|
)
|
||||||
|
if !reflect.DeepEqual(test.Want, want) {
|
||||||
|
t.Errorf("Got %s, want %s", want, test.Want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestFilterSubstring(t *testing.T) {
|
func TestFilterSubstring(t *testing.T) {
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
Input string
|
Input string
|
||||||
|
|
Loading…
Add table
Reference in a new issue