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

Function TestCompile

cel/cel_test.go:183–201  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

181}
182
183func TestCompile(t *testing.T) {
184 prg, err := Compile(`"hello " + name`, Variable("name", StringType))
185 if err != nil {
186 t.Fatalf("Compile() unexpected error: %v", err)
187 }
188 out, _, err := prg.Eval(map[string]any{"name": "world"})
189 if err != nil {
190 t.Fatalf("prg.Eval() unexpected error: %v", err)
191 }
192 if out.Equal(types.String("hello world")) != types.True {
193 t.Errorf(`got '%v', wanted "hello world"`, out.Value())
194 }
195
196 // Test compilation error
197 _, err = Compile(`1 + "invalid"`)
198 if err == nil {
199 t.Errorf("Compile() expected error for type mismatch, got nil")
200 }
201}
202
203func TestEval(t *testing.T) {
204 env, err := NewEnv(

Callers

nothing calls this directly

Calls 6

StringTypeAlias · 0.92
CompileFunction · 0.70
VariableFunction · 0.70
EvalMethod · 0.65
EqualMethod · 0.65
ValueMethod · 0.65

Tested by

no test coverage detected