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)
| 791 | // The bug was caused by StateSplit not cloning captures, breaking COW semantics. |
| 792 | // See: docs/dev/BUG_REPORT_CAPTURE_GROUPS.md |
| 793 | func 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"}, |
nothing calls this directly
no test coverage detected