File: regexp_test.go

package info (click to toggle)
tiup 1.16.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,384 kB
  • sloc: sh: 1,988; makefile: 138; sql: 16
file content (30 lines) | stat: -rw-r--r-- 519 bytes parent folder | download
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))
	}
}