MCPcopy Create free account
hub / github.com/coregx/coregex / TestPackageLevelMatchString

Function TestPackageLevelMatchString

regex_stdlib_compat_test.go:42–70  ·  view source on GitHub ↗

TestPackageLevelMatchString tests the package-level MatchString function.

(t *testing.T)

Source from the content-addressed store, hash-verified

40
41// TestPackageLevelMatchString tests the package-level MatchString function.
42func TestPackageLevelMatchString(t *testing.T) {
43 tests := []struct {
44 pattern string
45 input string
46 want bool
47 }{
48 {`\d+`, "hello 123", true},
49 {`\d+`, "hello", false},
50 {`^hello`, "hello world", true},
51 {`^hello`, "say hello", false},
52 }
53
54 for _, tt := range tests {
55 got, err := MatchString(tt.pattern, tt.input)
56 if err != nil {
57 t.Errorf("MatchString(%q, %q) error: %v", tt.pattern, tt.input, err)
58 continue
59 }
60 if got != tt.want {
61 t.Errorf("MatchString(%q, %q) = %v, want %v", tt.pattern, tt.input, got, tt.want)
62 }
63
64 // Compare with stdlib
65 stdGot, _ := regexp.MatchString(tt.pattern, tt.input)
66 if got != stdGot {
67 t.Errorf("MatchString(%q, %q) = %v, stdlib = %v", tt.pattern, tt.input, got, stdGot)
68 }
69 }
70}
71
72// TestCompilePOSIX tests POSIX compilation with leftmost-longest semantics.
73func TestCompilePOSIX(t *testing.T) {

Callers

nothing calls this directly

Calls 2

MatchStringFunction · 0.85
MatchStringMethod · 0.80

Tested by

no test coverage detected