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

Function Test_ExampleWithBuiltins

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

Source from the content-addressed store, hash-verified

58)
59
60func Test_ExampleWithBuiltins(t *testing.T) {
61 // Variables used within this expression environment.
62 env, err := NewEnv(
63 Variable("i", StringType),
64 Variable("you", StringType),
65 )
66 if err != nil {
67 t.Fatalf("environment creation error: %s\n", err)
68 }
69
70 // Compile the expression.
71 ast, iss := env.Compile(`"Hello " + you + "! I'm " + i + "."`)
72 if iss.Err() != nil {
73 t.Fatal(iss.Err())
74 }
75
76 // Create the program, and evaluate it against some input.
77 prg, err := env.Program(ast)
78 if err != nil {
79 t.Fatalf("program creation error: %s\n", err)
80 }
81
82 // If the Eval() call were provided with cel.EvalOptions(OptTrackState) the details response
83 // (2nd return) would be non-nil.
84 out, _, err := prg.Eval(
85 map[string]any{
86 "i": "CEL",
87 "you": "world",
88 },
89 )
90 if err != nil {
91 t.Fatalf("runtime error: %s\n", err)
92 }
93
94 // Hello world! I'm CEL.
95 if out.Equal(types.String("Hello world! I'm CEL.")) != types.True {
96 t.Errorf(`got '%v', wanted "Hello world! I'm CEL."`, out.Value())
97 }
98}
99
100func TestExtendCheckerParity(t *testing.T) {
101 // Base environment carrying standard library functions

Callers

nothing calls this directly

Calls 9

CompileMethod · 0.95
ProgramMethod · 0.95
StringTypeAlias · 0.92
ErrMethod · 0.80
NewEnvFunction · 0.70
VariableFunction · 0.70
EvalMethod · 0.65
EqualMethod · 0.65
ValueMethod · 0.65

Tested by

no test coverage detected