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

Function Example_cel_Comparison

examples/example_cel_operators_test.go:63–96  ·  view source on GitHub ↗

Example_cel_Comparison showcases equality and ordering comparison operators as documented in https://celbyexample.com/comparison/

()

Source from the content-addressed store, hash-verified

61// Example_cel_Comparison showcases equality and ordering comparison operators
62// as documented in https://celbyexample.com/comparison/
63func Example_cel_Comparison() {
64 exprs := []string{
65 `10 == 10`,
66 `10 != 20`,
67 `"hello" == "hello"`,
68 `"apple" < "banana"`,
69 `5 < 10`,
70 `10 <= 10`,
71 `15 > 10`,
72 `10 >= 10`,
73 }
74
75 for _, expr := range exprs {
76 prg, err := cel.Compile(expr)
77 if err != nil {
78 log.Fatalf("cel.Compile() error for %q: %v", expr, err)
79 }
80 out, _, err := prg.Eval(cel.NoVars())
81 if err != nil {
82 log.Fatalf("prg.Eval() error for %q: %v", expr, err)
83 }
84 fmt.Printf("%s -> %v\n", expr, out)
85 }
86
87 // Output:
88 // 10 == 10 -> true
89 // 10 != 20 -> true
90 // "hello" == "hello" -> true
91 // "apple" < "banana" -> true
92 // 5 < 10 -> true
93 // 10 <= 10 -> true
94 // 15 > 10 -> true
95 // 10 >= 10 -> true
96}
97
98// Example_cel_Null showcases null literal and null equality checks
99// as documented in https://celbyexample.com/null/

Callers

nothing calls this directly

Calls 3

CompileFunction · 0.92
NoVarsFunction · 0.92
EvalMethod · 0.65

Tested by

no test coverage detected