| 1 | // Copyright 2022 Google LLC |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package extscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/ |
| 16 | |
| 17 | import ( |
| 18 | "fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/" |
| 19 | "testingscip-go gomod github.com/golang/go/src go1.23.0 testing/" |
| 20 | |
| 21 | "google.golang.org/protobuf/protoscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/" |
| 22 | |
| 23 | "github.com/google/cel-go/celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/" |
| 24 | "github.com/google/cel-go/common/typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/" |
| 25 | "github.com/google/cel-go/common/types/refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/" |
| 26 | "github.com/google/cel-go/common/types/traitsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/" |
| 27 | "github.com/google/cel-go/testscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/" |
| 28 | |
| 29 | proto2pbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/ "github.com/google/cel-go/test/proto2pbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/" |
| 30 | wrapperspbscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/wrapperspb`/ "google.golang.org/protobuf/types/known/wrapperspbscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/wrapperspb`/" |
| 31 | ) |
| 32 | |
| 33 | func TestProtosscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/TestProtos().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) { |
| 34 | var protosTests = []struct { |
| 35 | expr string |
| 36 | }{ |
| 37 | // Positive test cases. |
| 38 | {expr: `proto.getExt(ExampleType{}, google.expr.proto2.test.int32_ext) == 0`}, |
| 39 | {expr: `!proto.hasExt(ExampleType{}, google.expr.proto2.test.int32_wrapper_ext)`}, |
| 40 | {expr: `proto.getExt(ExampleType{}, google.expr.proto2.test.int32_wrapper_ext) == null`}, |
| 41 | {expr: `!proto.hasExt(ExampleType{}, google.expr.proto2.test.nested_example)`}, |
| 42 | {expr: `proto.getExt(ExampleType{}, google.expr.proto2.test.nested_example) == ExampleType{}`}, |
| 43 | {expr: `proto.getExt(ExampleType{}, google.expr.proto2.test.ExtendedExampleType.extended_examples) == []`}, |
| 44 | {expr: `proto.getExt(ExampleType{}, google.expr.proto2.test.ExtendedExampleType.enum_ext) == GlobalEnum.GOO`}, |
| 45 | {expr: "ExampleType{`in`: 64}.`in` == 64"}, |
| 46 | // TODO(issue/1095): legal parse, but can't assign extension fields without updates to type checker and runtime |
| 47 | // ExampleType{`google.expr.proto2.test.int32_ext`: 42}.`google.expr.proto2.test.int32_ext` == 42 |
| 48 | {expr: `proto.getExt(msg, google.expr.proto2.test.int32_ext) == 42`}, |
| 49 | {expr: "msg.`google.expr.proto2.test.int32_ext` == 42"}, |
| 50 | {expr: `proto.getExt(msg, google.expr.proto2.test.int32_wrapper_ext) == 21`}, |
| 51 | {expr: "msg.`google.expr.proto2.test.int32_wrapper_ext` == 21"}, |
| 52 | {expr: `proto.hasExt(msg, google.expr.proto2.test.nested_example)`}, |
| 53 | {expr: "has(msg.`google.expr.proto2.test.nested_example`)"}, |
| 54 | {expr: `proto.getExt(msg, google.expr.proto2.test.nested_example) == ExampleType{name: 'nested'}`}, |
| 55 | {expr: "msg.`google.expr.proto2.test.nested_example` == ExampleType{name: 'nested'}"}, |
| 56 | {expr: `proto.getExt(msg, google.expr.proto2.test.ExtendedExampleType.extended_examples) == ['example1', 'example2']`}, |
| 57 | {expr: "msg.`google.expr.proto2.test.ExtendedExampleType.extended_examples` == ['example1', 'example2']"}, |
| 58 | {expr: `proto.getExt(msg, google.expr.proto2.test.ExtendedExampleType.enum_ext) == GlobalEnum.GAZ`}, |
| 59 | {expr: "msg.`google.expr.proto2.test.ExtendedExampleType.enum_ext` == GlobalEnum.GAZ"}, |
| 60 | } |
| 61 | |
| 62 | env := testProtosEnvscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/testProtosEnv().(t) |
| 63 | for i, tst := range protosTests { |
| 64 | tc := tst |
| 65 | t.Runscip-go gomod github.com/golang/go/src go1.23.0 testing/T#Run().(fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().("[%d]", i), func(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) { |
| 66 | var asts []*celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.Astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Ast# |
| 67 | pAst, iss := env.Parsescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Env#Parse().(tc.expr) |
| 68 | if iss.Errscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Issues#Err().() != nil { |
| 69 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("env.Parse(%v) failed: %v", tc.expr, iss.Errscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Issues#Err().()) |
| 70 | } |
| 71 | asts = append(asts, pAst) |
| 72 | cAst, iss := env.Checkscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Env#Check().(pAst) |
| 73 | if iss.Errscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Issues#Err().() != nil { |
| 74 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("env.Check(%v) failed: %v", tc.expr, iss.Errscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Issues#Err().()) |
| 75 | } |
| 76 | asts = append(asts, cAst) |
| 77 | |
| 78 | for _, ast := range asts { |
| 79 | prg, err := env.Programscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Env#Program().(ast) |
| 80 | if err != nil { |
| 81 | t.Fatalscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatal().(err) |
| 82 | } |
| 83 | out, _, err := prg.Evalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Program#Eval.(map[string]any{"msg": msgWithExtensionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/msgWithExtensions().()}) |
| 84 | if err != nil { |
| 85 | t.Fatalscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatal().(err) |
| 86 | } |
| 87 | if out.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.() != true { |
| 88 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got %v, wanted true for expr: %s", out.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.(), tc.expr) |
| 89 | } |
| 90 | } |
| 91 | }) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | func TestProtosNonMatchscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/TestProtosNonMatch().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 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 := testProtosEnvscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/testProtosEnv().(t, |
| 114 | celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.Functionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Function().("getExt", |
| 115 | celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.MemberOverloadscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/MemberOverload().("msg_getExt_field_default", |
| 116 | []*celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Type#{celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.DynTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/DynType., celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.StringTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/StringType., celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.DynTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/DynType.}, |
| 117 | celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.DynTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/DynType.), |
| 118 | celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.SingletonFunctionBindingscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/SingletonFunctionBinding().(func(args ...refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#) refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val# { |
| 119 | msg := args[0] |
| 120 | field := args[1] |
| 121 | indexer := msg.(traitsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/.Indexerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/Indexer#) |
| 122 | return indexer.Getscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/Indexer#Get.(field) |
| 123 | })), |
| 124 | celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.Functionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Function().("hasExt", |
| 125 | celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.MemberOverloadscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/MemberOverload().("msg_hasExt_field_any", |
| 126 | []*celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Type#{celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.DynTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/DynType., celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.StringTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/StringType., celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.DynTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/DynType.}, |
| 127 | celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.BoolTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/BoolType.), |
| 128 | celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.SingletonFunctionBindingscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/SingletonFunctionBinding().(func(args ...refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#) refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val# { |
| 129 | return typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Truescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/True. |
| 130 | }))) |
| 131 | for i, tst := range protosTests { |
| 132 | tc := tst |
| 133 | t.Runscip-go gomod github.com/golang/go/src go1.23.0 testing/T#Run().(fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().("[%d]", i), func(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) { |
| 134 | var asts []*celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.Astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Ast# |
| 135 | pAst, iss := env.Parsescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Env#Parse().(tc.expr) |
| 136 | if iss.Errscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Issues#Err().() != nil { |
| 137 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("env.Parse(%v) failed: %v", tc.expr, iss.Errscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Issues#Err().()) |
| 138 | } |
| 139 | asts = append(asts, pAst) |
| 140 | cAst, iss := env.Checkscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Env#Check().(pAst) |
| 141 | if iss.Errscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Issues#Err().() != nil { |
| 142 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("env.Check(%v) failed: %v", tc.expr, iss.Errscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Issues#Err().()) |
| 143 | } |
| 144 | asts = append(asts, cAst) |
| 145 | |
| 146 | for _, ast := range asts { |
| 147 | prg, err := env.Programscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Env#Program().(ast) |
| 148 | if err != nil { |
| 149 | t.Fatalscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatal().(err) |
| 150 | } |
| 151 | out, _, err := prg.Evalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Program#Eval.(map[string]any{"msg": msgWithExtensionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/msgWithExtensions().()}) |
| 152 | if err != nil { |
| 153 | t.Fatalscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatal().(err) |
| 154 | } |
| 155 | if out.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.() != true { |
| 156 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got %v, wanted true for expr: %s", out.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.(), tc.expr) |
| 157 | } |
| 158 | } |
| 159 | }) |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | func TestProtosParseErrorsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/TestProtosParseErrors().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) { |
| 164 | var protosTests = []struct { |
| 165 | expr string |
| 166 | err string |
| 167 | }{ |
| 168 | { |
| 169 | expr: `proto.getExt(ExtendedExampleType{}, enum_ext)`, |
| 170 | err: `ERROR: <input>:1:37: invalid extension field |
| 171 | | proto.getExt(ExtendedExampleType{}, enum_ext) |
| 172 | | ....................................^`, |
| 173 | }, |
| 174 | { |
| 175 | expr: `proto.hasExt(ExtendedExampleType{}, call().enum_ext)`, |
| 176 | err: `ERROR: <input>:1:43: invalid extension field |
| 177 | | proto.hasExt(ExtendedExampleType{}, call().enum_ext) |
| 178 | | ..........................................^`, |
| 179 | }, |
| 180 | { |
| 181 | expr: `proto.getExt(ExtendedExampleType{}, has(google.expr.proto2.test.int32_ext))`, |
| 182 | err: `ERROR: <input>:1:40: invalid extension field |
| 183 | | proto.getExt(ExtendedExampleType{}, has(google.expr.proto2.test.int32_ext)) |
| 184 | | .......................................^`, |
| 185 | }, |
| 186 | { |
| 187 | expr: `ExampleType{}.in`, |
| 188 | err: `ERROR: <input>:1:15: Syntax error: no viable alternative at input '.in' |
| 189 | | ExampleType{}.in |
| 190 | | ..............^ |
| 191 | ERROR: <input>:1:17: Syntax error: mismatched input '<EOF>' expecting {'[', '{', '(', '.', '-', '!', 'true', 'false', 'null', NUM_FLOAT, NUM_INT, NUM_UINT, STRING, BYTES, IDENTIFIER} |
| 192 | | ExampleType{}.in |
| 193 | | ................^`, |
| 194 | }, |
| 195 | } |
| 196 | env := testProtosEnvscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/testProtosEnv().(t) |
| 197 | for i, tst := range protosTests { |
| 198 | tc := tst |
| 199 | t.Runscip-go gomod github.com/golang/go/src go1.23.0 testing/T#Run().(fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().("[%d]", i), func(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) { |
| 200 | ast, iss := env.Parsescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Env#Parse().(tc.expr) |
| 201 | if iss.Errscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Issues#Err().() != nil { |
| 202 | if !testscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/.Comparescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Compare().(iss.Errscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Issues#Err().().Error(), tc.err) { |
| 203 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got parse error %v, wanted error %s for expr: %s", iss.Errscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Issues#Err().(), tc.err, tc.expr) |
| 204 | } |
| 205 | } else { |
| 206 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("got %v, wanted parse error", ast) |
| 207 | } |
| 208 | }) |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | // testProtosEnv initializes the test environment common to all tests. |
| 213 | func testProtosEnvscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/testProtosEnv().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#, opts ...celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.EnvOptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/EnvOption#) *celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.Envscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Env# { |
| 214 | t.Helperscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Helper().() |
| 215 | baseOpts := []celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.EnvOptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/EnvOption#{ |
| 216 | celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.Containerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Container().("google.expr.proto2.test"), |
| 217 | celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.Typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Types().(&proto2pbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/.ExampleTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/ExampleType#{}, &proto2pbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/.ExternalMessageTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/ExternalMessageType#{}), |
| 218 | celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.Variablescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Variable().("msg", celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.ObjectTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/ObjectType.("google.expr.proto2.test.ExampleType")), |
| 219 | celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.EnableIdentifierEscapeSyntaxscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/EnableIdentifierEscapeSyntax().(), |
| 220 | Protosscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/Protos().(), |
| 221 | } |
| 222 | env, err := celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.NewEnvscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/NewEnv().(append(baseOpts, opts...)...) |
| 223 | if err != nil { |
| 224 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("cel.NewEnv(Protos()) failed: %v", err) |
| 225 | } |
| 226 | return env |
| 227 | } |
| 228 | |
| 229 | func TestProtosWithExtensionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/TestProtosWithExtension().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) { |
| 230 | env := testProtosEnvscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/testProtosEnv().(t) |
| 231 | _, err := env.Extendscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Env#Extend().(Protosscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/Protos().()) |
| 232 | if err != nil { |
| 233 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("env.Extend(Protos()) failed: %v", err) |
| 234 | } |
| 235 | _, iss := env.Compilescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Env#Compile().("proto.getExt(ExampleType{}, google.expr.proto2.test.int32_ext) == 0") |
| 236 | if iss.Errscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Issues#Err().() != nil { |
| 237 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("env.Compile() failed: %v", iss.Errscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Issues#Err().()) |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | func TestProtosVersionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/TestProtosVersion().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) { |
| 242 | _, err := celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.NewEnvscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/NewEnv().(Protosscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/Protos().(ProtosVersionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/ProtosVersion().(0))) |
| 243 | if err != nil { |
| 244 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("ProtosVersion(0) failed: %v", err) |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | // msgWithExtensions generates a new example message with all possible extensions set. |
| 249 | func msgWithExtensionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/msgWithExtensions().() *proto2pbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/.ExampleTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/ExampleType# { |
| 250 | msg := &proto2pbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/.ExampleTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/ExampleType#{ |
| 251 | Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/ExampleType#Name.: protoscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/.Stringscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/String().("example0"), |
| 252 | } |
| 253 | protoscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/.SetExtensionscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/SetExtension().(msg, proto2pbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/.E_Int32Extscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/E_Int32Ext., int32(42)) |
| 254 | protoscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/.SetExtensionscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/SetExtension().(msg, proto2pbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/.E_Int32WrapperExtscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/E_Int32WrapperExt., wrapperspbscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/wrapperspb`/.Int32scip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/wrapperspb`/Int32().(21)) |
| 255 | protoscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/.SetExtensionscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/SetExtension().(msg, proto2pbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/.E_NestedExamplescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/E_NestedExample., &proto2pbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/.ExampleTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/ExampleType#{Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/ExampleType#Name.: protoscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/.Stringscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/String().("nested")}) |
| 256 | protoscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/.SetExtensionscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/SetExtension().(msg, proto2pbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/.E_ExtendedExampleType_EnumExtscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/E_ExtendedExampleType_EnumExt., proto2pbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/.GlobalEnum_GAZscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/GlobalEnum_GAZ.) |
| 257 | protoscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/.SetExtensionscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/SetExtension().(msg, proto2pbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/.E_ExtendedExampleType_ExtendedExamplesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto2pb`/E_ExtendedExampleType_ExtendedExamples., []string{"example1", "example2"}) |
| 258 | return msg |
| 259 | } |