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

Function TestStringIndexPrefixFilterRuneError

stringprefixfilter_test.go:86–109  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

84}
85
86func TestStringIndexPrefixFilterRuneError(t *testing.T) {
87 filter := stringIndexPrefixFilter("�abc", false, 4)
88 if filter == nil {
89 t.Fatal("expected a filter for valid UTF-8")
90 }
91 for _, tc := range []struct {
92 input string
93 index int
94 ok bool
95 }{
96 {"xx�abc", 2, true},
97 {"xxxxx", 0, false},
98 {"x\xffabc�abc", 0, true}, // invalid input must reach the rune engine
99 } {
100 index, ok := filter(tc.input, 0)
101 if index != tc.index || ok != tc.ok {
102 t.Fatalf("filter(%q) = %d, %v; want %d, %v", tc.input, index, ok, tc.index, tc.ok)
103 }
104 }
105 m, err := MustCompile("�abc").FindStringMatch("x\xffabc�abc")
106 if err != nil || m == nil || m.RuneIndex != 1 {
107 t.Fatalf("expected the invalid-byte match before the valid U+FFFD: %v, %v", m, err)
108 }
109}
110
111func TestStringIndexPrefixFilterASCIIIgnoreCase(t *testing.T) {
112 filter := stringIndexPrefixFilter("abc", true, 3)

Callers

nothing calls this directly

Calls 3

stringIndexPrefixFilterFunction · 0.85
FindStringMatchMethod · 0.80
MustCompileFunction · 0.70

Tested by

no test coverage detected