Added tests for FindString
This commit is contained in:
22
re_test.go
22
re_test.go
@@ -204,6 +204,28 @@ func TestFindAllMatches(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFindString(t *testing.T) {
|
||||||
|
for _, test := range reTests {
|
||||||
|
t.Run(test.re+" "+test.str, func(t *testing.T) {
|
||||||
|
regComp, err := Compile(test.re)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
foundString := FindString(regComp, test.str)
|
||||||
|
if len(test.result) == 0 {
|
||||||
|
if foundString != "" {
|
||||||
|
t.Errorf("Expected no match got %v\n", foundString)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
expectedString := test.str[test.result[0].startIdx:test.result[0].endIdx]
|
||||||
|
if foundString != foundString {
|
||||||
|
t.Errorf("Wanted %v Got %v\n", expectedString, foundString)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestFindAllGroups(t *testing.T) {
|
func TestFindAllGroups(t *testing.T) {
|
||||||
for _, test := range groupTests {
|
for _, test := range groupTests {
|
||||||
t.Run(test.re+" "+test.str, func(t *testing.T) {
|
t.Run(test.re+" "+test.str, func(t *testing.T) {
|
||||||
|
Reference in New Issue
Block a user