|
|
|
@ -861,6 +861,60 @@ func TestFindStringSubmatch(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFindAllStringSubmatch(t *testing.T) {
|
|
|
|
|
for _, test := range groupTests {
|
|
|
|
|
t.Run(test.re+" "+test.str, func(t *testing.T) {
|
|
|
|
|
regComp, err := Compile(test.re, test.flags...)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if test.result != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
matchStrs := regComp.FindAllStringSubmatch(test.str)
|
|
|
|
|
if matchStrs == nil {
|
|
|
|
|
if len(test.result) != 0 {
|
|
|
|
|
expectedStrs := funcMap(test.result, func(m Match) []string {
|
|
|
|
|
return funcMap(m, func(g Group) string {
|
|
|
|
|
if g.IsValid() {
|
|
|
|
|
return test.str[g.StartIdx:g.EndIdx]
|
|
|
|
|
} else {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
t.Errorf("Wanted %v got no match\n", expectedStrs)
|
|
|
|
|
}
|
|
|
|
|
} else if len(test.result) == 0 {
|
|
|
|
|
t.Errorf("Wanted no match got %v\n", matchStrs)
|
|
|
|
|
} else {
|
|
|
|
|
expectedStrs := funcMap(test.result, func(m Match) []string {
|
|
|
|
|
return funcMap(m, func(g Group) string {
|
|
|
|
|
if g.IsValid() {
|
|
|
|
|
return test.str[g.StartIdx:g.EndIdx]
|
|
|
|
|
} else {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
for i, matchStr := range matchStrs {
|
|
|
|
|
for j, groupStr := range matchStr {
|
|
|
|
|
if groupStr == "" {
|
|
|
|
|
if j < len(expectedStrs[i]) && expectedStrs[i][j] != "" {
|
|
|
|
|
t.Errorf("Wanted %v Got %v\n", expectedStrs, matchStrs)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if expectedStrs[i][j] != groupStr {
|
|
|
|
|
t.Errorf("Wanted %v Got %v\n", expectedStrs, matchStrs)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFindAllSubmatch(t *testing.T) {
|
|
|
|
|
for _, test := range groupTests {
|
|
|
|
|
t.Run(test.re+" "+test.str, func(t *testing.T) {
|
|
|
|
|