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

Function TestStdlibCompat_Count

stdlib_compat_test.go:1555–1582  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1553}
1554
1555func TestStdlibCompat_Count(t *testing.T) {
1556 tests := []struct {
1557 pattern string
1558 input string
1559 }{
1560 {`a`, "banana"},
1561 {`\d+`, "a1b22c333d4444"},
1562 {`\w+`, "hello world foo bar"},
1563 {`[aeiou]`, "hello world"},
1564 {`x`, "no match here"},
1565 }
1566
1567 for _, tc := range tests {
1568 t.Run(tc.pattern+"_"+tc.input, func(t *testing.T) {
1569 stdRe := regexp.MustCompile(tc.pattern)
1570 cgRe := MustCompile(tc.pattern)
1571
1572 // stdlib doesn't have Count, but we can compare with FindAll
1573 stdAll := stdRe.FindAllString(tc.input, -1)
1574 cgCount := cgRe.CountString(tc.input, -1)
1575
1576 if len(stdAll) != cgCount {
1577 t.Errorf("Count(%q, %q):\n stdlib FindAll: %d\n coregex Count: %d",
1578 tc.pattern, tc.input, len(stdAll), cgCount)
1579 }
1580 })
1581 }
1582}
1583
1584func TestStdlibCompat_LiteralMatch(t *testing.T) {
1585 // Use MustCompile to verify literal matching works same as stdlib

Callers

nothing calls this directly

Calls 3

MustCompileFunction · 0.85
FindAllStringMethod · 0.80
CountStringMethod · 0.80

Tested by

no test coverage detected