github.com/jxskiss/gopkg/v2@v2.14.9-0.20240514120614-899f3e7952b4/easy/regexp_test.go (about) 1 package easy 2 3 import ( 4 "regexp" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestMatchGroups(t *testing.T) { 11 text := "Tom saw a cat got a mat." 12 re := regexp.MustCompile(`(\w+)\s(?P<action>\w+)\s.*`) 13 14 want1 := map[string][]byte{ 15 "action": []byte("saw"), 16 } 17 got1 := MatchGroups(re, []byte(text)) 18 assert.Equal(t, want1, got1) 19 20 want2 := map[string]string{ 21 "action": "saw", 22 } 23 got2 := MatchStringGroups(re, text) 24 assert.Equal(t, want2, got2) 25 }