github.com/jxgolibs/go-oauth2-server@v1.0.1/util/regex_test.go (about)

     1  package util_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/RichardKnop/go-oauth2-server/util"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestRegexExtractMatch(t *testing.T) {
    11  	match, err := util.RegexExtractMatch(
    12  		"...FOO...",
    13  		"^...(?P<the_name>[A-Z]{3})...$",
    14  		"the_name",
    15  	)
    16  
    17  	assert.Nil(t, err)
    18  	assert.Equal(t, "FOO", match)
    19  }
    20  
    21  func TestRegexExtractMatches(t *testing.T) {
    22  	matches, err := util.RegexExtractMatches(
    23  		"HKDJPY",
    24  		"^(?P<from_currency>[A-Z]{3})(?P<to_currency>[A-Z]{3})$",
    25  		"from_currency",
    26  		"to_currency",
    27  	)
    28  
    29  	assert.Nil(t, err)
    30  	assert.Equal(t, "HKD", matches["from_currency"])
    31  	assert.Equal(t, "JPY", matches["to_currency"])
    32  }