MCPcopy Create free account
hub / github.com/dlclark/regexp2 / TestFindStringMatchStart

Function TestFindStringMatchStart

stringprefixfilter_test.go:338–370  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

336}
337
338func TestFindStringMatchStart(t *testing.T) {
339 re := &Regexp{}
340
341 candidateByteIndex, ok, err := re.findStringMatchStart("abc", -1)
342 if err != nil {
343 t.Fatalf("findStringMatchStart failed: %v", err)
344 }
345 if !ok {
346 t.Fatal("expected candidate")
347 }
348 if got, want := candidateByteIndex, 0; got != want {
349 t.Fatalf("candidateByteIndex = %d, want %d", got, want)
350 }
351
352 re.options = RightToLeft
353 candidateByteIndex, ok, err = re.findStringMatchStart("abc", -1)
354 if err != nil {
355 t.Fatalf("findStringMatchStart failed: %v", err)
356 }
357 if !ok {
358 t.Fatal("expected candidate")
359 }
360 if got, want := candidateByteIndex, 3; got != want {
361 t.Fatalf("candidateByteIndex = %d, want %d", got, want)
362 }
363
364 if _, _, err := re.findStringMatchStart("abc", 4); err == nil {
365 t.Fatal("expected startAt too large error")
366 }
367 if _, _, err := re.findStringMatchStart("aé", 2); err == nil {
368 t.Fatal("expected invalid rune boundary error")
369 }
370}
371
372func BenchmarkStringIndexPrefixesFilter(b *testing.B) {
373 prefixes := []string{

Callers

nothing calls this directly

Calls 1

findStringMatchStartMethod · 0.95

Tested by

no test coverage detected