github.com/jxskiss/gopkg@v0.17.3/easy/regexp_test.go (about)

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