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

Function TestFindStringSubmatch_DotPlusCapture

regex_test.go:793–912  ·  view source on GitHub ↗

TestFindStringSubmatch_DotPlusCapture tests capture groups with .+ (any character) patterns. This is a regression test for a bug where .+ in capture groups returned incorrect values. The bug was caused by StateSplit not cloning captures, breaking COW semantics. See: docs/dev/BUG_REPORT_CAPTURE_GROUP

(t *testing.T)

Source from the content-addressed store, hash-verified

791// The bug was caused by StateSplit not cloning captures, breaking COW semantics.
792// See: docs/dev/BUG_REPORT_CAPTURE_GROUPS.md
793func TestFindStringSubmatch_DotPlusCapture(t *testing.T) {
794 tests := []struct {
795 name string
796 pattern string
797 input string
798 want []string
799 }{
800 // Basic .+ capture group tests (the bug scenario)
801 {
802 name: "dot_plus_basic",
803 pattern: `^(.+)-(\d+)$`,
804 input: "hello-123",
805 want: []string{"hello-123", "hello", "123"},
806 },
807 {
808 name: "dot_plus_multiple_dashes",
809 pattern: `^(.+)-(\d+)$`,
810 input: "a-b-c-123",
811 want: []string{"a-b-c-123", "a-b-c", "123"},
812 },
813 {
814 name: "dot_plus_path_like",
815 pattern: `^(.+)-(\d+)$`,
816 input: "dev-java/pkg-17",
817 want: []string{"dev-java/pkg-17", "dev-java/pkg", "17"},
818 },
819 // Non-greedy .+? tests
820 {
821 name: "dot_plus_nongreedy",
822 pattern: `^(.+?)-(\d+)$`,
823 input: "hello-123",
824 want: []string{"hello-123", "hello", "123"},
825 },
826 // .* tests (zero or more)
827 {
828 name: "dot_star_basic",
829 pattern: `^(.*)x(\d+)$`,
830 input: "abcx123",
831 want: []string{"abcx123", "abc", "123"},
832 },
833 {
834 name: "dot_star_empty",
835 pattern: `^(.*)x(\d+)$`,
836 input: "x123",
837 want: []string{"x123", "", "123"},
838 },
839 // Unanchored patterns
840 {
841 name: "unanchored_dot_plus",
842 pattern: `(.+)-(\d+)`,
843 input: "test-456",
844 want: []string{"test-456", "test", "456"},
845 },
846 {
847 name: "unanchored_with_prefix",
848 pattern: `(.+)-(\d+)`,
849 input: "prefix: foo-789 suffix",
850 want: []string{"prefix: foo-789", "prefix: foo", "789"},

Callers

nothing calls this directly

Calls 2

MustCompileFunction · 0.85
FindStringSubmatchMethod · 0.80

Tested by

no test coverage detected