VictoriaMetrics/lib/bytesutil/fast_string_matcher_test.go
Aliaksandr Valialkin b4bb1477fe
lib/regexutil: cache MatchString results for unoptimized regexps
This increases relabeling performance by 3x for unoptimized regexs
2022-09-30 12:28:25 +03:00

26 lines
525 B
Go

package bytesutil
import (
"strings"
"testing"
)
func TestFastStringMatcher(t *testing.T) {
fsm := NewFastStringMatcher(func(s string) bool {
return strings.HasPrefix(s, "foo")
})
f := func(s string, resultExpected bool) {
t.Helper()
for i := 0; i < 10; i++ {
result := fsm.Match(s)
if result != resultExpected {
t.Fatalf("unexpected result for Match(%q) at iteration %d; got %v; want %v", s, i, result, resultExpected)
}
}
}
f("", false)
f("foo", true)
f("a_b-C", false)
f("foobar", true)
}