MCPcopy Create free account
hub / github.com/dlclark/regexp2 / TestSplitUnicodePrefixByteSpans

Function TestSplitUnicodePrefixByteSpans

string_processing_test.go:161–182  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

159}
160
161func TestSplitUnicodePrefixByteSpans(t *testing.T) {
162 for _, prefix := range []string{strings.Repeat("pré界", 512), strings.Repeat("é\xff界", 512)} {
163 input := prefix + " needle-é-needle!"
164 for _, pattern := range []string{`needle`, `(needle)`, `\b(needle)\b`} {
165 re := MustCompile(pattern)
166 want := []string{prefix + " ", "-é-", "!"}
167 if pattern != `needle` {
168 want = []string{prefix + " ", "needle", "-é-", "needle", "!"}
169 }
170 got, err := re.Split(input, -1)
171 if err != nil || !slices.Equal(got, want) {
172 t.Fatalf("%q: got %q, %v; want %q", pattern, got, err, want)
173 }
174 }
175 re := MustCompile(`(?<=(界))needle`)
176 got, err := re.Split(prefix+"needle界needle!", -1)
177 want := []string{prefix, "界", "界", "界", "!"}
178 if err != nil || !slices.Equal(got, want) {
179 t.Fatalf("lookbehind: got %q, %v; want %q", got, err, want)
180 }
181 }
182}
183
184func TestSplitRegisteredEngineCapturesAndErrors(t *testing.T) {
185 failure := errors.New("engine failure")

Callers

nothing calls this directly

Calls 2

SplitMethod · 0.80
MustCompileFunction · 0.70

Tested by

no test coverage detected