(t *testing.T)
| 119 | } |
| 120 | |
| 121 | func TestSplitReusableCaptures(t *testing.T) { |
| 122 | for _, tc := range []struct { |
| 123 | pattern, input string |
| 124 | count int |
| 125 | want []string |
| 126 | }{ |
| 127 | {`,`, "a,b,c,d", 2, []string{"a", "b", "c,d"}}, |
| 128 | {`(,)|(;)`, "a,b;c", -1, []string{"a", ",", "", "b", "", ";", "c"}}, |
| 129 | {`(?<10>,)|(?<2>;)`, "a,b;c", -1, []string{"a", "", ",", "b", ";", "", "c"}}, |
| 130 | {`(?:(?<x>,)|;)+`, "a,,b;c,,d", -1, []string{"a", ",", "b", "", "c", ",", "d"}}, |
| 131 | {`(?<x>,)+(?<-x>;)+`, "a,,;b,;c", -1, []string{"a", ",", "b", "", "c"}}, |
| 132 | {`(?<=\G..)(?=..)`, "aabbccdd", -1, []string{"aa", "bb", "cc", "dd"}}, |
| 133 | {``, "é界", -1, []string{"", "é", "界", ""}}, |
| 134 | {`(needle)`, "é界needlex\xffneedle😀", -1, []string{"é界", "needle", "x\xff", "needle", "😀"}}, |
| 135 | {`(?<=(é))needle`, "éneedle界éneedle😀", -1, []string{"é", "é", "界é", "é", "😀"}}, |
| 136 | {`aaba|aaca|bada`, strings.Repeat("a", 80) + "ca?bada!", -1, []string{strings.Repeat("a", 78), "?", "!"}}, |
| 137 | {`(?i)ab`, "aX AB!ab?", -1, []string{"aX ", "!", "?"}}, |
| 138 | {`[ACEGIK]{2,4}`, "A!ACE?IK", -1, []string{"A!", "?", ""}}, |
| 139 | {`aa[ \n]$`, "aaa\n", -1, []string{"a", ""}}, |
| 140 | {`aaba|aaca|bada`, strings.Repeat("a", 80), -1, []string{strings.Repeat("a", 80)}}, |
| 141 | } { |
| 142 | t.Run(tc.pattern, func(t *testing.T) { |
| 143 | re := MustCompile(tc.pattern) |
| 144 | // Repeated calls also cover reused capture counts and balancing storage. |
| 145 | for i := 0; i < 3; i++ { |
| 146 | got, err := re.Split(tc.input, tc.count) |
| 147 | if err != nil || !slices.Equal(got, tc.want) { |
| 148 | t.Fatalf("got %#v,%v; want %#v", got, err, tc.want) |
| 149 | } |
| 150 | if _, err := re.Replace(strings.Repeat(tc.input, 2), "changed", -1, -1); err != nil { |
| 151 | t.Fatal(err) |
| 152 | } |
| 153 | if !slices.Equal(got, tc.want) { |
| 154 | t.Fatal("returned strings changed after pooled buffer reuse") |
| 155 | } |
| 156 | } |
| 157 | }) |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | func TestSplitUnicodePrefixByteSpans(t *testing.T) { |
| 162 | for _, prefix := range []string{strings.Repeat("pré界", 512), strings.Repeat("é\xff界", 512)} { |
nothing calls this directly
no test coverage detected