(t *testing.T)
| 182 | } |
| 183 | |
| 184 | func TestSplitRegisteredEngineCapturesAndErrors(t *testing.T) { |
| 185 | failure := errors.New("engine failure") |
| 186 | re := newEngineRegexp("split-engine", newCompileConfig(nil), RuntimeEngineData{ |
| 187 | CapSize: 2, LeftContextKnown: true, |
| 188 | StringPrefixFilter: stringIndexPrefixFilter(",", false, 1), |
| 189 | FindFirstChar: func(r *Runner) bool { |
| 190 | for r.Runtextpos < r.Runtextend { |
| 191 | if r.Runtext[r.Runtextpos] == ',' || r.Runtext[r.Runtextpos] == '!' { |
| 192 | return true |
| 193 | } |
| 194 | r.Runtextpos++ |
| 195 | } |
| 196 | return false |
| 197 | }, |
| 198 | Execute: func(r *Runner) error { |
| 199 | if r.Runtext[r.Runtextpos] == '!' { |
| 200 | return failure |
| 201 | } |
| 202 | start := r.Runtextpos |
| 203 | r.Runtextpos++ |
| 204 | r.Capture(1, start, r.Runtextpos) |
| 205 | r.Capture(0, start, r.Runtextpos) |
| 206 | return nil |
| 207 | }, |
| 208 | ExecuteQuick: func(r *Runner) error { t.Fatal("Split must retain captures"); return nil }, |
| 209 | }) |
| 210 | got, err := re.Split("é,界,😀", -1) |
| 211 | if err != nil || !slices.Equal(got, []string{"é", ",", "界", ",", "😀"}) { |
| 212 | t.Fatal(got, err) |
| 213 | } |
| 214 | // Preserve error propagation, including the existing look-ahead scan after |
| 215 | // the last processed delimiter when count is exhausted. |
| 216 | for _, count := range []int{-1, 2} { |
| 217 | if got, err := re.Split("a,b,c!", count); got != nil || !errors.Is(err, failure) { |
| 218 | t.Fatal(got, err) |
| 219 | } |
| 220 | } |
| 221 | got, err = re.Split("x,y", -1) |
| 222 | if err != nil || !slices.Equal(got, []string{"x", ",", "y"}) { |
| 223 | t.Fatal(got, err) |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | func TestStringProcessingAllocations(t *testing.T) { |
| 228 | skipIfAllocsUnreliable(t) |
nothing calls this directly
no test coverage detected