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

Function TestMatchStringAgreesWithFindStringMatch

decode_test.go:354–383  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

352}
353
354func TestMatchStringAgreesWithFindStringMatch(t *testing.T) {
355 tests := []struct {
356 pattern string
357 input string
358 }{
359 {`needle`, strings.Repeat("x", 100) + "needle"},
360 {`\bcat\b`, strings.Repeat("漢", 20) + " cat "},
361 {`\bcat\b`, strings.Repeat("x", 100) + "cat"},
362 {`(?<=x)foo`, strings.Repeat("z", 40) + "xfoo"},
363 {`(?<=x)foo`, strings.Repeat("z", 40) + "yfoo"},
364 {`apple|tiger`, strings.Repeat("z", 40) + "tiger9"},
365 {`\Gfoo`, "xxfoo"},
366 {`\Gfoo`, strings.Repeat("x", 80) + "foo"},
367 {`(?m)^foo`, "foo\nfoo"},
368 }
369 for _, tt := range tests {
370 re := MustCompile(tt.pattern)
371 ok, err := re.MatchString(tt.input)
372 if err != nil {
373 t.Fatalf("%s MatchString(%q): %v", tt.pattern, tt.input, err)
374 }
375 m, err := re.FindStringMatch(tt.input)
376 if err != nil {
377 t.Fatalf("%s FindStringMatch(%q): %v", tt.pattern, tt.input, err)
378 }
379 if ok != (m != nil) {
380 t.Fatalf("%s on %q: MatchString=%v FindStringMatch=%v", tt.pattern, tt.input, ok, m != nil)
381 }
382 }
383}
384
385func TestNegatedClassNotConvertedToPrefixes(t *testing.T) {
386 re := MustCompile(`a[^bc]d`)

Callers

nothing calls this directly

Calls 3

FindStringMatchMethod · 0.80
MustCompileFunction · 0.70
MatchStringMethod · 0.65

Tested by

no test coverage detected