Skip to content

Commit

Permalink
Merge pull request #1651 from nalind/regexper
Browse files Browse the repository at this point in the history
pkg/regexp: make sure that &Regexp implements the interfaces
  • Loading branch information
rhatdan authored Jun 28, 2023
2 parents 4bda4f0 + 7d87965 commit 8730e29
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/regexp/regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
// used as global variables. Using this structure helps speed the startup time
// of apps that want to use global regex variables. This library initializes them on
// first use as opposed to the start of the executable.
type Regexp = *regexpStruct
type Regexp struct {
*regexpStruct
}

type regexpStruct struct {
_ noCopy
Expand All @@ -26,7 +28,7 @@ func Delayed(val string) Regexp {
if precompile {
re.regexp = regexp.MustCompile(re.val)
}
return re
return Regexp{re}
}

func (re *regexpStruct) compile() {
Expand Down
8 changes: 8 additions & 0 deletions pkg/regexp/regexp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import (
"testing"
)

type partOfRegexp interface {
FindStringSubmatch(s string) []string
MatchString(s string) bool
NumSubexp() int
}

var _ partOfRegexp = &Regexp{}

func TestMatchString(t *testing.T) {
r := Delayed(`[0-9]+`)

Expand Down

0 comments on commit 8730e29

Please sign in to comment.