(t *testing.T)
| 93 | } |
| 94 | |
| 95 | func TestProtosNonMatch(t *testing.T) { |
| 96 | var protosTests = []struct { |
| 97 | expr string |
| 98 | }{ |
| 99 | // Even though 'getExt' is the macro, the call is left unexpanded is an identifier |
| 100 | // that's not named 'proto' |
| 101 | { |
| 102 | expr: `msg.getExt("google.expr.proto2.test.int32_ext", 0) == 42`, |
| 103 | }, |
| 104 | // Even though 'getExt' is the macro, the call is left unexpanded as the operand is a call |
| 105 | { |
| 106 | expr: `dyn(msg).getExt("google.expr.proto2.test.int32_ext", 0) == 42`, |
| 107 | }, |
| 108 | // Test for hasExt for completeness |
| 109 | { |
| 110 | expr: `msg.hasExt("google.expr.proto2.test.int32_ext", 0)`, |
| 111 | }, |
| 112 | } |
| 113 | env := testProtosEnv(t, |
| 114 | cel.Function("getExt", |
| 115 | cel.MemberOverload("msg_getExt_field_default", |
| 116 | []*cel.Type{cel.DynType, cel.StringType, cel.DynType}, |
| 117 | cel.DynType), |
| 118 | cel.SingletonFunctionBinding(func(args ...ref.Val) ref.Val { |
| 119 | msg := args[0] |
| 120 | field := args[1] |
| 121 | indexer := msg.(traits.Indexer) |
| 122 | return indexer.Get(field) |
| 123 | })), |
| 124 | cel.Function("hasExt", |
| 125 | cel.MemberOverload("msg_hasExt_field_any", |
| 126 | []*cel.Type{cel.DynType, cel.StringType, cel.DynType}, |
| 127 | cel.BoolType), |
| 128 | cel.SingletonFunctionBinding(func(args ...ref.Val) ref.Val { |
| 129 | return types.True |
| 130 | }))) |
| 131 | for i, tst := range protosTests { |
| 132 | tc := tst |
| 133 | t.Run(fmt.Sprintf("[%d]", i), func(t *testing.T) { |
| 134 | var asts []*cel.Ast |
| 135 | pAst, iss := env.Parse(tc.expr) |
| 136 | if iss.Err() != nil { |
| 137 | t.Fatalf("env.Parse(%v) failed: %v", tc.expr, iss.Err()) |
| 138 | } |
| 139 | asts = append(asts, pAst) |
| 140 | cAst, iss := env.Check(pAst) |
| 141 | if iss.Err() != nil { |
| 142 | t.Fatalf("env.Check(%v) failed: %v", tc.expr, iss.Err()) |
| 143 | } |
| 144 | asts = append(asts, cAst) |
| 145 | |
| 146 | for _, ast := range asts { |
| 147 | prg, err := env.Program(ast) |
| 148 | if err != nil { |
| 149 | t.Fatal(err) |
| 150 | } |
| 151 | out, _, err := prg.Eval(map[string]any{"msg": msgWithExtensions()}) |
| 152 | if err != nil { |
nothing calls this directly
no test coverage detected