Logo
Explore Help
Sign In
1berry/docker-cli
1
0
Fork 0
You've already forked docker-cli
Code Issues Packages Projects Releases Wiki Activity
docker-cli/internal/lazyregexp/lazyregexp_test.go

24 lines
389 B
Go
Raw Normal View History

implement lazyregexp package Based on the "lazyregexp" package in golang.org/x/mod; https://cs.opensource.google/go/x/mod/+/refs/tags/v0.19.0:internal/lazyregexp/lazyre.go;l=66-78 This package allows defining regular expressions that should not be compiled until used, but still providing validation to prevent invalid regular expressions from producing a panic at runtime. This is largely a copy of the package from golang.org/x/mod, with FindAllStringSubmatch and ReplaceAllStringFunc added Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-16 13:26:26 +02:00
package lazyregexp
import (
"testing"
)
func TestCompileOnce(t *testing.T) {
t.Run("invalid regexp", func(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("expected a panic")
}
}()
_ = New("[")
})
t.Run("valid regexp", func(t *testing.T) {
re := New("[a-z]")
ok := re.MatchString("hello")
if !ok {
t.Errorf("expected a match")
}
})
}
Reference in New Issue Copy Permalink
Powered by Gitea Version: 1.23.8 Page: 97ms Template: 4ms
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어
Licenses API