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

Function Example_cel_Null

examples/example_cel_operators_test.go:100–123  ·  view source on GitHub ↗

Example_cel_Null showcases null literal and null equality checks as documented in https://celbyexample.com/null/

()

Source from the content-addressed store, hash-verified

98// Example_cel_Null showcases null literal and null equality checks
99// as documented in https://celbyexample.com/null/
100func Example_cel_Null() {
101 exprs := []string{
102 `null`,
103 `val == null`,
104 `val != null`,
105 }
106
107 for _, expr := range exprs {
108 prg, err := cel.Compile(expr, cel.Variable("val", cel.DynType))
109 if err != nil {
110 log.Fatalf("cel.Compile() error for %q: %v", expr, err)
111 }
112 out, _, err := prg.Eval(map[string]any{"val": nil})
113 if err != nil {
114 log.Fatalf("prg.Eval() error for %q: %v", expr, err)
115 }
116 fmt.Printf("%s -> %v\n", expr, out)
117 }
118
119 // Output:
120 // null -> 0
121 // val == null -> true
122 // val != null -> false
123}

Callers

nothing calls this directly

Calls 3

CompileFunction · 0.92
VariableFunction · 0.92
EvalMethod · 0.65

Tested by

no test coverage detected