MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestRegexStaticErrors

Function TestRegexStaticErrors

ext/regex_test.go:127–167  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

125}
126
127func TestRegexStaticErrors(t *testing.T) {
128 tests := []struct {
129 expr string
130 err string
131 }{
132 {
133 expr: "regex.replace('abc', '^', 1)",
134 err: "found no matching overload for 'regex.replace' applied to '(string, string, int)'",
135 },
136 {
137 expr: "regex.replace('abc', '^', '1','')",
138 err: "found no matching overload for 'regex.replace' applied to '(string, string, string, string)'",
139 },
140 {
141 expr: "regex.extract('foo bar', 1)",
142 err: "found no matching overload for 'regex.extract' applied to '(string, int)'",
143 },
144 {
145 expr: "regex.extract('foo bar', 1, 'bar')",
146 err: "found no matching overload for 'regex.extract' applied to '(string, int, string)'",
147 },
148 {
149 expr: "regex.extractAll()",
150 err: "found no matching overload for 'regex.extractAll' applied to '()'",
151 },
152 {
153 expr: "regex.replace('banana', 'a', 'x', 18446744073709551615)",
154 err: `ERROR: <input>:1:35: invalid int literal`,
155 },
156 }
157 env := testRegexEnv(t)
158 for i, tst := range tests {
159 tr := tst
160 t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
161 _, iss := env.Compile(tr.expr)
162 if iss.Err() == nil || !strings.Contains(iss.Err().Error(), tr.err) {
163 t.Errorf("env.Compile(%q) got error %v, wanted %v", tr.expr, iss.Err(), tr.err)
164 }
165 })
166 }
167}
168
169func TestRegexRuntimeErrors(t *testing.T) {
170 tests := []struct {

Callers

nothing calls this directly

Calls 5

testRegexEnvFunction · 0.85
ErrMethod · 0.80
CompileMethod · 0.65
ContainsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected