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

Function TestWhitespaceHanlding

policy/compiler_test.go:180–246  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

178}
179
180func TestWhitespaceHanlding(t *testing.T) {
181
182 testCases := []struct {
183 matchID string
184 want string
185 }{
186 {
187 matchID: "folded_unambiguous",
188 want: "a string expression that is folded",
189 },
190 {
191 matchID: "folded_line_break",
192 // 8 spaces (4 indents)
193 want: "a string expression that\n is folded",
194 },
195 {
196 matchID: "folded_line_break_indent",
197 // 10 spaces (5 indents)
198 want: "a string expression that\n is folded",
199 },
200 {
201 matchID: "literal_unambiguous",
202 want: "a string expression that is a literal block",
203 },
204 {
205 matchID: "literal_line_break",
206 // 8 spaces (4 indents)
207 want: "a string expression that\n is a literal block",
208 },
209 {
210 matchID: "literal_line_break_indent",
211 // 10 spaces (5 indents)
212 want: "a string expression that\n is a literal block",
213 },
214 }
215
216 policy := parsePolicy(t, "yaml_parsing", []ParserOption{})
217 env, ast, iss := compile(t, "yaml_parsing", policy, []cel.EnvOption{}, []CompilerOption{})
218 if iss.Err() != nil {
219 t.Fatalf("compile('yaml_parsing') failed, %s", iss.Err().Error())
220 }
221
222 p, err := env.PlanProgram(ast.NativeRep())
223
224 if err != nil {
225 t.Fatalf("env.PlanProgram() failed, %s", err.Error())
226 }
227
228 for _, tst := range testCases {
229 t.Run(tst.matchID, func(t *testing.T) {
230
231 in := map[string]any{"match_id": types.String(tst.matchID)}
232
233 result, _, err := p.Eval(in)
234 if err != nil {
235 t.Fatalf("p.Eval(match_id: '%s') failed, %s", tst.matchID, err.Error())
236 }
237 s, ok := result.(types.String)

Callers

nothing calls this directly

Calls 9

StringTypeAlias · 0.92
parsePolicyFunction · 0.85
ErrMethod · 0.80
PlanProgramMethod · 0.80
NativeRepMethod · 0.80
compileFunction · 0.70
EvalMethod · 0.65
ValueMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected