1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
package utils
import (
"regexp"
"testing"
"github.com/stretchr/testify/require"
)
func TestMatchGroups(t *testing.T) {
cases := []struct {
re string
str string
expected map[string]string
}{
{
re: `^(?P<first>[a-zA-Z]*)(?P<second>[0-9]*)$`,
str: "abc123",
expected: map[string]string{
"": "abc123",
"first": "abc",
"second": "123",
},
},
}
for _, cas := range cases {
require.Equal(t, cas.expected, MatchGroups(regexp.MustCompile(cas.re), cas.str))
}
}
|