| 1 | // Copyright 2023 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 ast_testscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/ |
| 16 | |
| 17 | import ( |
| 18 | "reflectscip-go gomod github.com/golang/go/src go1.23.0 reflect/" |
| 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/checkerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/" |
| 24 | "github.com/google/cel-go/commonscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/" |
| 25 | "github.com/google/cel-go/common/astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/" |
| 26 | "github.com/google/cel-go/common/containersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/" |
| 27 | "github.com/google/cel-go/common/declsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/decls`/" |
| 28 | "github.com/google/cel-go/common/stdlibscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/stdlib`/" |
| 29 | "github.com/google/cel-go/common/typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/" |
| 30 | "github.com/google/cel-go/parserscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/" |
| 31 | |
| 32 | proto3pbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto3pb`/ "github.com/google/cel-go/test/proto3pbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto3pb`/" |
| 33 | ) |
| 34 | |
| 35 | func TestNavigateASTscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/TestNavigateAST().(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#) { |
| 36 | tests := []struct { |
| 37 | expr string |
| 38 | descendantCount int |
| 39 | callCount int |
| 40 | maxDepth int |
| 41 | maxID int64 |
| 42 | }{ |
| 43 | { |
| 44 | expr: `'a' == 'b'`, |
| 45 | descendantCount: 3, |
| 46 | callCount: 1, |
| 47 | maxDepth: 1, |
| 48 | maxID: 4, |
| 49 | }, |
| 50 | { |
| 51 | expr: `'a'.size()`, |
| 52 | descendantCount: 2, |
| 53 | callCount: 1, |
| 54 | maxDepth: 1, |
| 55 | maxID: 3, |
| 56 | }, |
| 57 | { |
| 58 | expr: `[1, 2, 3]`, |
| 59 | descendantCount: 4, |
| 60 | callCount: 0, |
| 61 | maxDepth: 1, |
| 62 | maxID: 5, |
| 63 | }, |
| 64 | { |
| 65 | expr: `[1, 2, 3][0]`, |
| 66 | descendantCount: 6, |
| 67 | callCount: 1, |
| 68 | maxDepth: 2, |
| 69 | maxID: 7, |
| 70 | }, |
| 71 | { |
| 72 | expr: `{1u: 'hello'}`, |
| 73 | descendantCount: 3, |
| 74 | callCount: 0, |
| 75 | maxDepth: 1, |
| 76 | maxID: 5, |
| 77 | }, |
| 78 | { |
| 79 | expr: `{'hello': 'world'}.hello`, |
| 80 | descendantCount: 4, |
| 81 | callCount: 0, |
| 82 | maxDepth: 2, |
| 83 | maxID: 6, |
| 84 | }, |
| 85 | { |
| 86 | expr: `type(1) == int`, |
| 87 | descendantCount: 4, |
| 88 | callCount: 2, |
| 89 | maxDepth: 2, |
| 90 | maxID: 5, |
| 91 | }, |
| 92 | { |
| 93 | expr: `google.expr.proto3.test.TestAllTypes{single_int32: 1}`, |
| 94 | descendantCount: 2, |
| 95 | callCount: 0, |
| 96 | maxDepth: 1, |
| 97 | maxID: 4, |
| 98 | }, |
| 99 | { |
| 100 | expr: `[true].exists(i, i)`, |
| 101 | descendantCount: 11, // 2 for iter range, 1 for accu init, 4 for loop condition, 3 for loop step, 1 for result |
| 102 | callCount: 3, // @not_strictly_false(!result), accu_init || i |
| 103 | maxDepth: 3, |
| 104 | maxID: 14, |
| 105 | }, |
| 106 | } |
| 107 | |
| 108 | for _, tst := range tests { |
| 109 | tc := tst |
| 110 | t.Runscip-go gomod github.com/golang/go/src go1.23.0 testing/T#Run().(tc.expr, 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#) { |
| 111 | checked := mustTypeCheckscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/mustTypeCheck().(t, tc.expr) |
| 112 | nav := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigateASTscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigateAST().(checked) |
| 113 | descendants := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.MatchDescendantsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MatchDescendants().(nav, astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.AllMatcherscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/AllMatcher().()) |
| 114 | if len(descendants) != tc.descendantCount { |
| 115 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ast.MatchDescendants(%v) got %d descendants, wanted %d", checked.Exprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/AST#Expr().(), len(descendants), tc.descendantCount) |
| 116 | } |
| 117 | maxDepth := 0 |
| 118 | for _, d := range descendants { |
| 119 | if d.Depthscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#Depth.() > maxDepth { |
| 120 | maxDepth = d.Depthscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#Depth.() |
| 121 | } |
| 122 | } |
| 123 | if maxDepth != tc.maxDepth { |
| 124 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got max NavigableExpr.Depth() of %d, wanted %d", maxDepth, tc.maxDepth) |
| 125 | } |
| 126 | maxID := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.MaxIDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MaxID().(checked) |
| 127 | if maxID != tc.maxID { |
| 128 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got max id %d, wanted %d", maxID, tc.maxID) |
| 129 | } |
| 130 | calls := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.MatchSubsetscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MatchSubset().(descendants, astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.KindMatcherscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/KindMatcher().(astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.CallKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallKind.)) |
| 131 | if len(calls) != tc.callCount { |
| 132 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ast.MatchSubset(%v) got %d calls, wanted %d", checked.Exprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/AST#Expr().(), len(calls), tc.callCount) |
| 133 | } |
| 134 | }) |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | func TestExprVisitorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/TestExprVisitor().(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#) { |
| 139 | tests := []struct { |
| 140 | expr string |
| 141 | preOrderIDs []int64 |
| 142 | postOrderIDs []int64 |
| 143 | }{ |
| 144 | { |
| 145 | // [2] ==, [1] 'a', [3] 'b' |
| 146 | expr: `'a' == 'b'`, |
| 147 | preOrderIDs: []int64{2, 1, 3}, |
| 148 | postOrderIDs: []int64{1, 3, 2}, |
| 149 | }, |
| 150 | { |
| 151 | // [2] size(), [1] 'a' |
| 152 | expr: `'a'.size()`, |
| 153 | preOrderIDs: []int64{2, 1}, |
| 154 | postOrderIDs: []int64{1, 2}, |
| 155 | }, |
| 156 | { |
| 157 | // [3] ==, [1] type(), [2] 1, [4] int |
| 158 | expr: `type(1) == int`, |
| 159 | preOrderIDs: []int64{3, 1, 2, 4}, |
| 160 | postOrderIDs: []int64{2, 1, 4, 3}, |
| 161 | }, |
| 162 | { |
| 163 | // [5] .hello, [1] {}, [3] 'hello', [4] 'world' |
| 164 | expr: `{'hello': 'world'}.hello`, |
| 165 | preOrderIDs: []int64{5, 1, 3, 4}, |
| 166 | postOrderIDs: []int64{3, 4, 1, 5}, |
| 167 | }, |
| 168 | { |
| 169 | // [1] TestAllTypes, [3] 1 |
| 170 | expr: `google.expr.proto3.test.TestAllTypes{single_int32: 1}`, |
| 171 | preOrderIDs: []int64{1, 3}, |
| 172 | postOrderIDs: []int64{3, 1}, |
| 173 | }, |
| 174 | { |
| 175 | // [13] comprehension |
| 176 | // range: [1] [], [2] true |
| 177 | // accuInit: [6] result=false |
| 178 | // loopCond: [9] @not_strictly_false, [8] !, [7] result |
| 179 | // loopStep: [11] ||, [10] result [5] i |
| 180 | // result: [12] result |
| 181 | expr: `[true].exists(i, i)`, |
| 182 | preOrderIDs: []int64{13, 1, 2, 6, 9, 8, 7, 11, 10, 5, 12}, |
| 183 | postOrderIDs: []int64{2, 1, 6, 7, 8, 9, 10, 5, 11, 12, 13}, |
| 184 | }, |
| 185 | } |
| 186 | |
| 187 | for _, tst := range tests { |
| 188 | tc := tst |
| 189 | t.Runscip-go gomod github.com/golang/go/src go1.23.0 testing/T#Run().(tc.expr, 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#) { |
| 190 | checked := mustTypeCheckscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/mustTypeCheck().(t, tc.expr) |
| 191 | root := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigateASTscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigateAST().(checked) |
| 192 | // Verify pre order visit behavior |
| 193 | preOrderExprIDs := []int64{} |
| 194 | navVisitor := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NewExprVisitorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NewExprVisitor().(func(e astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.Exprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#) { |
| 195 | nav := e.(astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigableExprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#) |
| 196 | preOrderExprIDs = append(preOrderExprIDs, nav.IDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#ID.()) |
| 197 | }) |
| 198 | astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.PreOrderVisitscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/PreOrderVisit().(root, navVisitor) |
| 199 | if !reflectscip-go gomod github.com/golang/go/src go1.23.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.23.0 reflect/DeepEqual().(tc.preOrderIDs, preOrderExprIDs) { |
| 200 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("PreOrderVisit() got %v expressions, wanted %v", tc.preOrderIDs, preOrderExprIDs) |
| 201 | } |
| 202 | |
| 203 | // Demonstrate preOrder visit behavior with Children() |
| 204 | preOrderExprIDs = []int64{} |
| 205 | visited := []astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigableExprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#{root} |
| 206 | for len(visited) > 0 { |
| 207 | e := visited[0] |
| 208 | preOrderExprIDs = append(preOrderExprIDs, e.IDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#ID.()) |
| 209 | visited = append(e.Childrenscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#Children.()[:], visited[1:]...) |
| 210 | } |
| 211 | if !reflectscip-go gomod github.com/golang/go/src go1.23.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.23.0 reflect/DeepEqual().(tc.preOrderIDs, preOrderExprIDs) { |
| 212 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("PreOrderVisit() got %v expressions, wanted %v", tc.preOrderIDs, preOrderExprIDs) |
| 213 | } |
| 214 | |
| 215 | // Verify post order visit behavior. |
| 216 | postOrderExprIDs := []int64{} |
| 217 | navVisitor = astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NewExprVisitorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NewExprVisitor().(func(e astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.Exprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#) { |
| 218 | nav := e.(astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigableExprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#) |
| 219 | postOrderExprIDs = append(postOrderExprIDs, nav.IDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#ID.()) |
| 220 | }) |
| 221 | astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.PostOrderVisitscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/PostOrderVisit().(root, navVisitor) |
| 222 | if !reflectscip-go gomod github.com/golang/go/src go1.23.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.23.0 reflect/DeepEqual().(tc.postOrderIDs, postOrderExprIDs) { |
| 223 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("PostOrderVisit() got %v expressions, wanted %v", tc.postOrderIDs, postOrderExprIDs) |
| 224 | } |
| 225 | }) |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | func TestNavigableASTNilSafetyscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/TestNavigableASTNilSafety().(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 | tests := []struct { |
| 231 | name string |
| 232 | e astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigableExprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr# |
| 233 | }{ |
| 234 | { |
| 235 | name: "nil expr", |
| 236 | e: astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigateASTscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigateAST().(astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NewASTscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NewAST().(nil, nil)), |
| 237 | }, |
| 238 | } |
| 239 | for _, tst := range tests { |
| 240 | tc := tst |
| 241 | t.Runscip-go gomod github.com/golang/go/src go1.23.0 testing/T#Run().(tc.name, 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#) { |
| 242 | e := tc.e |
| 243 | if e.IDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#ID.() != 0 { |
| 244 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ID() got %d, wanted 0", e.IDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#ID.()) |
| 245 | } |
| 246 | if e.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.() != astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.UnspecifiedExprKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/UnspecifiedExprKind. { |
| 247 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Kind() got %v, wanted unspecified kind", e.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.()) |
| 248 | } |
| 249 | if e.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#Type.() != typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.DynTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/DynType. { |
| 250 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Type() got %v, wanted types.DynType", e.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#Type.()) |
| 251 | } |
| 252 | if p, found := e.Parentscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#Parent.(); found { |
| 253 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Parent() got %v, wanted not found", p) |
| 254 | } |
| 255 | if len(e.Childrenscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#Children.()) != 0 { |
| 256 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Children() got %v, wanted none", e.Childrenscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#Children.()) |
| 257 | } |
| 258 | if e.AsLiteralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsLiteral.() != nil { |
| 259 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("AsLiteral() got %v, wanted nil", e.AsLiteralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsLiteral.()) |
| 260 | } |
| 261 | if e.AsCallscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsCall.() == nil { |
| 262 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("AsCall() got nil, wanted non-nil for safe traversal") |
| 263 | } |
| 264 | if e.AsComprehensionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsComprehension.() == nil { |
| 265 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("AsComprehension() got nil, wanted non-nil for safe traversal") |
| 266 | } |
| 267 | }) |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | func TestNavigableExprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/TestNavigableExpr().(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#) { |
| 272 | checkedAST := mustTypeCheckscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/mustTypeCheck().(t, `'a' == 'b'`) |
| 273 | navAST := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigateASTscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigateAST().(checkedAST) |
| 274 | literals := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.MatchDescendantsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MatchDescendants().(navAST, func(expr astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigableExprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#) bool { |
| 275 | return expr.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.() == astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.LiteralKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/LiteralKind. && |
| 276 | expr.AsLiteralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsLiteral.().Equalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Equal.(typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Stringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/String#("a")) == 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. |
| 277 | }) |
| 278 | if len(literals) != 1 { |
| 279 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("MatchDescendents('a') got %d results, wanted 1", len(literals)) |
| 280 | } |
| 281 | litA := literals[0] |
| 282 | if litA.Depthscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#Depth.() != 1 { |
| 283 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("litA.Depth() got %d, wanted 1", litA.Depthscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#Depth.()) |
| 284 | } |
| 285 | parent, found := litA.Parentscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#Parent.() |
| 286 | if !found { |
| 287 | t.Fatalscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatal().("litA.Parent() returned nil") |
| 288 | } |
| 289 | if parent.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.() != astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.CallKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallKind. && parent.AsCallscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsCall.().FunctionNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallExpr#FunctionName.() != "==" { |
| 290 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("litA.Parent() got %v, watned '==' function call", parent) |
| 291 | } |
| 292 | litAPrime := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigateExprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigateExpr().(checkedAST, litA) |
| 293 | if litAPrime.Depthscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#Depth.() != litA.Depthscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#Depth.() { |
| 294 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("litAPrime.Depth() != litA.Depth(), got %d, wanted %d", litAPrime.Depthscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#Depth.(), litA.Depthscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#Depth.()) |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | func TestNavigableCallExprMemberscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/TestNavigableCallExprMember().(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#) { |
| 299 | checked := mustTypeCheckscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/mustTypeCheck().(t, `'hello'.size()`) |
| 300 | expr := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigateASTscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigateAST().(checked) |
| 301 | if expr.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.() != astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.CallKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallKind. { |
| 302 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Kind() got %v, wanted CallKind", expr.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.()) |
| 303 | } |
| 304 | call := expr.AsCallscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsCall.() |
| 305 | if call.FunctionNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallExpr#FunctionName.() != "size" { |
| 306 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("FunctionName() got %s, wanted size", call.FunctionNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallExpr#FunctionName.()) |
| 307 | } |
| 308 | if call.Targetscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallExpr#Target.() == nil { |
| 309 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("Target() got nil, wanted non-nil") |
| 310 | } |
| 311 | if len(call.Argsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallExpr#Args.()) != 0 { |
| 312 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Args() got %v, wanted 0", call.Argsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallExpr#Args.()) |
| 313 | } |
| 314 | target := call.Targetscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallExpr#Target.() |
| 315 | if target.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.() != astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.LiteralKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/LiteralKind. { |
| 316 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Kind() got %v, wanted literal", target.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.()) |
| 317 | } |
| 318 | if target.AsLiteralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsLiteral.().Equalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Equal.(typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Stringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/String#("hello")) != 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. { |
| 319 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("AsLiteral() got %v, wanted 'hello'", target.AsLiteralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsLiteral.()) |
| 320 | } |
| 321 | if p, found := target.(astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigableExprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#).Parentscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#Parent.(); !found || p != expr { |
| 322 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Parent() got %v, wanted %v", p, expr) |
| 323 | } |
| 324 | sizeFn := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.MatchDescendantsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MatchDescendants().(expr, astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.FunctionMatcherscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/FunctionMatcher().("size")) |
| 325 | if len(sizeFn) != 1 { |
| 326 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ast.MatchDescendants() size function returned %v, wanted 1", sizeFn) |
| 327 | } |
| 328 | constantValues := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.MatchDescendantsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MatchDescendants().(expr, astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.ConstantValueMatcherscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ConstantValueMatcher().()) |
| 329 | if len(constantValues) != 1 { |
| 330 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("ast.MatchDescendants() constant values returned %v, wanted 1 value", constantValues) |
| 331 | } |
| 332 | if constantValues[0].AsLiteralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsLiteral.().Equalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Equal.(typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Stringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/String#("hello")) != 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. { |
| 333 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("constantValues[0] got %v, wanted 'hello'", constantValues[0]) |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | func TestNavigableCallExprGlobalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/TestNavigableCallExprGlobal().(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#) { |
| 338 | checked := mustTypeCheckscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/mustTypeCheck().(t, `size('hello')`) |
| 339 | expr := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigateASTscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigateAST().(checked) |
| 340 | if expr.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.() != astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.CallKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallKind. { |
| 341 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Kind() got %v, wanted CallKind", expr.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.()) |
| 342 | } |
| 343 | call := expr.AsCallscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsCall.() |
| 344 | if call.FunctionNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallExpr#FunctionName.() != "size" { |
| 345 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("FunctionName() got %s, wanted size", call.FunctionNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallExpr#FunctionName.()) |
| 346 | } |
| 347 | if call.IsMemberFunctionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallExpr#IsMemberFunction.() { |
| 348 | t.Fatalscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatal().("IsMemberFunction() returned true, wanted false") |
| 349 | } |
| 350 | if len(call.Argsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallExpr#Args.()) != 1 { |
| 351 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Args() got %v, wanted 1", call.Argsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallExpr#Args.()) |
| 352 | } |
| 353 | arg := call.Argsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallExpr#Args.()[0] |
| 354 | if arg.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.() != astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.LiteralKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/LiteralKind. { |
| 355 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Kind() got %v, wanted literal", arg.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.()) |
| 356 | } |
| 357 | if arg.AsLiteralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsLiteral.().Equalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Equal.(typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Stringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/String#("hello")) != 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. { |
| 358 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("AsLiteral() got %v, wanted 'hello'", arg.AsLiteralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsLiteral.()) |
| 359 | } |
| 360 | if p, found := arg.(astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigableExprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#).Parentscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#Parent.(); !found || p != expr { |
| 361 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Parent() got %v, wanted %v", p, expr) |
| 362 | } |
| 363 | sizeFn := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.MatchDescendantsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MatchDescendants().(expr, astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.FunctionMatcherscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/FunctionMatcher().("size")) |
| 364 | if len(sizeFn) != 1 { |
| 365 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ast.MatchDescendants() size function returned %v, wanted 1", sizeFn) |
| 366 | } |
| 367 | constantValues := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.MatchDescendantsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MatchDescendants().(expr, astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.ConstantValueMatcherscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ConstantValueMatcher().()) |
| 368 | if len(constantValues) != 1 { |
| 369 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("ast.MatchDescendants() constant values returned %v, wanted 1 value", constantValues) |
| 370 | } |
| 371 | if constantValues[0].AsLiteralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsLiteral.().Equalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Equal.(typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Stringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/String#("hello")) != 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. { |
| 372 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("constantValues[0] got %v, wanted 'hello'", constantValues[0]) |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | func TestNavigableListExprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/TestNavigableListExpr().(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#) { |
| 377 | checked := mustTypeCheckscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/mustTypeCheck().(t, `[[1], [2]]`) |
| 378 | expr := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigateASTscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigateAST().(checked) |
| 379 | if expr.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.() != astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.ListKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ListKind. { |
| 380 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Kind() got %v, wanted ListKind", expr.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.()) |
| 381 | } |
| 382 | list := expr.AsListscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsList.() |
| 383 | if list.Sizescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ListExpr#Size.() != 2 { |
| 384 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Size() got %d, wanted 2", list.Sizescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ListExpr#Size.()) |
| 385 | } |
| 386 | if len(list.OptionalIndicesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ListExpr#OptionalIndices.()) != 0 { |
| 387 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("OptionalIndicies() returned %v, wanted none", list.OptionalIndicesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ListExpr#OptionalIndices.()) |
| 388 | } |
| 389 | if len(list.Elementsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ListExpr#Elements.()) != 2 { |
| 390 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Elements() returned %v, wanted 2", list.Elementsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ListExpr#Elements.()) |
| 391 | } |
| 392 | constantValues := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.MatchDescendantsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MatchDescendants().(expr, astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.ConstantValueMatcherscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ConstantValueMatcher().()) |
| 393 | if len(constantValues) != 5 { |
| 394 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ast.MatchDescendants() constant values returned %v, wanted 5", constantValues) |
| 395 | } |
| 396 | constantLists := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.MatchSubsetscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MatchSubset().(constantValues, astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.KindMatcherscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/KindMatcher().(astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.ListKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ListKind.)) |
| 397 | if len(constantLists) != 3 { |
| 398 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ast.MatchSubset() constant lists returned %v, wanted 3", constantLists) |
| 399 | } |
| 400 | literals := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.MatchSubsetscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MatchSubset().(constantValues, astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.KindMatcherscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/KindMatcher().(astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.LiteralKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/LiteralKind.)) |
| 401 | if len(literals) != 2 { |
| 402 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ast.MatchSubset() literals returned %v, wanted 2", literals) |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | func TestNavigableMapExprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/TestNavigableMapExpr().(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#) { |
| 407 | checked := mustTypeCheckscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/mustTypeCheck().(t, `{'hello': 1}`) |
| 408 | expr := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigateASTscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigateAST().(checked) |
| 409 | if expr.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.() != astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.MapKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MapKind. { |
| 410 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Kind() got %v, wanted MapKind", expr.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.()) |
| 411 | } |
| 412 | m := expr.AsMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsMap.() |
| 413 | if m.Sizescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MapExpr#Size.() != 1 { |
| 414 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Size() got %d, wanted 1", m.Sizescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MapExpr#Size.()) |
| 415 | } |
| 416 | if len(m.Entriesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MapExpr#Entries.()) != 1 { |
| 417 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Entries() returned %v, wanted 1", m.Entriesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MapExpr#Entries.()) |
| 418 | } |
| 419 | e := m.Entriesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MapExpr#Entries.()[0] |
| 420 | entry := e.AsMapEntryscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/EntryExpr#AsMapEntry.() |
| 421 | if entry.IsOptionalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MapEntry#IsOptional.() { |
| 422 | t.Errorscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Error().("IsOptional() returned true, wanted false") |
| 423 | } |
| 424 | if entry.Keyscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MapEntry#Key.().AsLiteralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsLiteral.().Equalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Equal.(typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Stringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/String#("hello")) != 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. { |
| 425 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Key() returned %v, wanted 'hello'", entry.Keyscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MapEntry#Key.().AsLiteralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsLiteral.()) |
| 426 | } |
| 427 | if entry.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MapEntry#Value.().AsLiteralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsLiteral.().Equalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Equal.(typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Intscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Int#(1)) != 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. { |
| 428 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Value() returned %v, wanted 1", entry.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MapEntry#Value.().AsLiteralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsLiteral.()) |
| 429 | } |
| 430 | descendants := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.MatchDescendantsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MatchDescendants().(expr, astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.AllMatcherscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/AllMatcher().()) |
| 431 | if len(descendants) != 3 { |
| 432 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ast.MatchDescendants() returned %v, wanted 3", descendants) |
| 433 | } |
| 434 | literals := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.MatchSubsetscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MatchSubset().(descendants, astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.KindMatcherscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/KindMatcher().(astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.LiteralKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/LiteralKind.)) |
| 435 | if len(literals) != 2 { |
| 436 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ast.MatchSubset() literals returned %v, wanted 2", literals) |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | func TestNavigableStructExprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/TestNavigableStructExpr().(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#) { |
| 441 | checked := mustTypeCheckscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/mustTypeCheck().(t, `google.expr.proto3.test.TestAllTypes{single_int32: 1}`) |
| 442 | expr := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigateASTscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigateAST().(checked) |
| 443 | if expr.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.() != astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.StructKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/StructKind. { |
| 444 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Kind() got %v, wanted StructKind", expr.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.()) |
| 445 | } |
| 446 | s := expr.AsStructscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsStruct.() |
| 447 | if s.TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/StructExpr#TypeName.() != "google.expr.proto3.test.TestAllTypes" { |
| 448 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("TypeName() got %s, wanted TestAllTypes", s.TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/StructExpr#TypeName.()) |
| 449 | } |
| 450 | if len(s.Fieldsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/StructExpr#Fields.()) != 1 { |
| 451 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Fields() returned %v, wanted 1", s.Fieldsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/StructExpr#Fields.()) |
| 452 | } |
| 453 | f := s.Fieldsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/StructExpr#Fields.()[0] |
| 454 | field := f.AsStructFieldscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/EntryExpr#AsStructField.() |
| 455 | if field.IsOptionalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/StructField#IsOptional.() { |
| 456 | t.Errorscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Error().("IsOptional() returned true, wanted false") |
| 457 | } |
| 458 | if field.Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/StructField#Name.() != "single_int32" { |
| 459 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Name() returned %s, wanted 'single_int32'", field.Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/StructField#Name.()) |
| 460 | } |
| 461 | if field.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/StructField#Value.().AsLiteralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsLiteral.().Equalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Equal.(typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Intscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Int#(1)) != 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. { |
| 462 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Value() returned %v, wanted 1", field.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/StructField#Value.().AsLiteralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsLiteral.()) |
| 463 | } |
| 464 | descendants := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.MatchDescendantsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MatchDescendants().(expr, astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.AllMatcherscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/AllMatcher().()) |
| 465 | if len(descendants) != 2 { |
| 466 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ast.MatchDescendants() returned %v, wanted 2", descendants) |
| 467 | } |
| 468 | literals := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.MatchSubsetscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MatchSubset().(descendants, astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.KindMatcherscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/KindMatcher().(astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.LiteralKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/LiteralKind.)) |
| 469 | if len(literals) != 1 { |
| 470 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ast.MatchSubset() literals returned %v, wanted 1", literals) |
| 471 | } |
| 472 | if literals[0].AsLiteralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsLiteral.().Equalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Equal.(typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Intscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Int#(1)) != 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. { |
| 473 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Value().AsLiteral() got %v, wanted 1", literals[0].AsLiteralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsLiteral.()) |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | func TestNavigableComprehensionExprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/TestNavigableComprehensionExpr().(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#) { |
| 478 | checked := mustTypeCheckscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/mustTypeCheck().(t, `[true].exists(i, i)`) |
| 479 | expr := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigateASTscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigateAST().(checked) |
| 480 | if expr.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.() != astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.ComprehensionKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ComprehensionKind. { |
| 481 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Kind() got %v, wanted ComprehensionKind", expr.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.()) |
| 482 | } |
| 483 | comp := expr.AsComprehensionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsComprehension.() |
| 484 | iterRange := comp.IterRangescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ComprehensionExpr#IterRange.() |
| 485 | if len(astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.MatchSubsetscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MatchSubset().([]astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigableExprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#{iterRange.(astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigableExprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#)}, astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.ConstantValueMatcherscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ConstantValueMatcher().())) != 1 { |
| 486 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("IterRange() returned a non-constant list") |
| 487 | } |
| 488 | if comp.IterVarscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ComprehensionExpr#IterVar.() != "i" { |
| 489 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("IterVar() got %s, wanted 'i'", comp.IterVarscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ComprehensionExpr#IterVar.()) |
| 490 | } |
| 491 | if comp.HasIterVar2scip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ComprehensionExpr#HasIterVar2.() { |
| 492 | t.Errorscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Error().("HasIterVar2() returned true, wanted false") |
| 493 | } |
| 494 | if comp.IterVar2scip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ComprehensionExpr#IterVar2.() != "" { |
| 495 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("IterVar2() returned %s, wanted empty string", comp.IterVar2scip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ComprehensionExpr#IterVar2.()) |
| 496 | } |
| 497 | if comp.AccuVarscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ComprehensionExpr#AccuVar.() != "@result" { |
| 498 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("AccuVar() got %s, wanted '@result'", comp.AccuVarscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ComprehensionExpr#AccuVar.()) |
| 499 | } |
| 500 | if comp.AccuInitscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ComprehensionExpr#AccuInit.().AsLiteralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsLiteral.() != typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Falsescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/False. { |
| 501 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("AccuInit() returned %v, wanted false", comp.AccuInitscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ComprehensionExpr#AccuInit.().AsLiteralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsLiteral.()) |
| 502 | } |
| 503 | if comp.Resultscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ComprehensionExpr#Result.().Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.() != astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.IdentKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/IdentKind. { |
| 504 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Result() returned %v, wanted ident", comp.Resultscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ComprehensionExpr#Result.()) |
| 505 | } |
| 506 | if comp.LoopConditionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ComprehensionExpr#LoopCondition.().Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.() != astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.CallKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallKind. { |
| 507 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("LoopCondition() returned %v, wanted call", comp.LoopConditionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ComprehensionExpr#LoopCondition.()) |
| 508 | } |
| 509 | if comp.LoopStepscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ComprehensionExpr#LoopStep.().Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.() != astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.CallKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallKind. { |
| 510 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("LoopStep() returned %v, wanted call", comp.LoopStepscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ComprehensionExpr#LoopStep.()) |
| 511 | } |
| 512 | if comp.Resultscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ComprehensionExpr#Result.().AsIdentscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsIdent.() != "@result" { |
| 513 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("AsIdent() returned %v, wanted @result", comp.Resultscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ComprehensionExpr#Result.().AsIdentscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsIdent.()) |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | func TestNavigableSelectExprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/TestNavigableSelectExpr().(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#) { |
| 518 | checked := mustTypeCheckscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/mustTypeCheck().(t, `msg.single_int32`) |
| 519 | expr := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigateASTscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigateAST().(checked) |
| 520 | if expr.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.() != astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.SelectKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/SelectKind. { |
| 521 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Kind() got %v, wanted SelectKind", expr.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.()) |
| 522 | } |
| 523 | sel := expr.AsSelectscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsSelect.() |
| 524 | if sel.FieldNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/SelectExpr#FieldName.() != "single_int32" { |
| 525 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("FieldName() got %s, wanted single_int32", sel.FieldNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/SelectExpr#FieldName.()) |
| 526 | } |
| 527 | if sel.Operandscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/SelectExpr#Operand.().Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.() != astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.IdentKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/IdentKind. { |
| 528 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("Operand() kind got %v, wanted ident", sel.Operandscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/SelectExpr#Operand.().Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.()) |
| 529 | } |
| 530 | if sel.Operandscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/SelectExpr#Operand.().AsIdentscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsIdent.() != "msg" { |
| 531 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Operand() got %v, wanted ident 'msg'", sel.Operandscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/SelectExpr#Operand.()) |
| 532 | } |
| 533 | if sel.IsTestOnlyscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/SelectExpr#IsTestOnly.() { |
| 534 | t.Errorscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Error().("IsTestOnly() got true, wanted false") |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | func TestNavigableSelectExpr_TestOnlyscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/TestNavigableSelectExpr_TestOnly().(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#) { |
| 539 | checked := mustTypeCheckscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/mustTypeCheck().(t, `has(msg.single_int32)`) |
| 540 | expr := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigateASTscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigateAST().(checked) |
| 541 | if expr.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.() != astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.SelectKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/SelectKind. { |
| 542 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Kind() got %v, wanted SelectKind", expr.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.()) |
| 543 | } |
| 544 | sel := expr.AsSelectscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsSelect.() |
| 545 | if sel.FieldNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/SelectExpr#FieldName.() != "single_int32" { |
| 546 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("FieldName() got %s, wanted single_int32", sel.FieldNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/SelectExpr#FieldName.()) |
| 547 | } |
| 548 | if sel.Operandscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/SelectExpr#Operand.().Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.() != astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.IdentKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/IdentKind. { |
| 549 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("Operand() kind got %v, wanted ident", sel.Operandscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/SelectExpr#Operand.().Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.()) |
| 550 | } |
| 551 | if sel.Operandscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/SelectExpr#Operand.().AsIdentscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsIdent.() != "msg" { |
| 552 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Operand() got %v, wanted ident 'msg'", sel.Operandscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/SelectExpr#Operand.()) |
| 553 | } |
| 554 | if !sel.IsTestOnlyscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/SelectExpr#IsTestOnly.() { |
| 555 | t.Errorscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Error().("IsTestOnly() got false, wanted true") |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | func mustTypeCheckscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/mustTypeCheck().(t testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.TBscip-go gomod github.com/golang/go/src go1.23.0 testing/TB#, expr string) *astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.ASTscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/AST# { |
| 560 | t.Helperscip-go gomod github.com/golang/go/src go1.23.0 testing/TB#Helper().() |
| 561 | p, err := parserscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/.NewParserscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/NewParser().( |
| 562 | parserscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/.Macrosscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Macros().(parserscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/.AllMacrosscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/AllMacros....), |
| 563 | parserscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/.EnableOptionalSyntaxscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/EnableOptionalSyntax().(true), |
| 564 | parserscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/.PopulateMacroCallsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/PopulateMacroCalls().(true)) |
| 565 | if err != nil { |
| 566 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/TB#Fatalf().("parser.NewParser() failed: %v", err) |
| 567 | } |
| 568 | exprSrc := commonscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/.NewTextSourcescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/NewTextSource().(expr) |
| 569 | parsed, iss := p.Parsescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Parser#Parse().(exprSrc) |
| 570 | if len(iss.GetErrorsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/Errors#GetErrors().()) != 0 { |
| 571 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/TB#Fatalf().("Parse(%s) failed: %s", expr, iss.ToDisplayStringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/Errors#ToDisplayString().()) |
| 572 | } |
| 573 | reg := newTestRegistryscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/newTestRegistry().(t, &proto3pbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto3pb`/.TestAllTypesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test/proto3pb`/TestAllTypes#{}) |
| 574 | env := newTestEnvscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/newTestEnv().(t, containersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/.DefaultContainerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/DefaultContainer., reg) |
| 575 | checked, iss := checkerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/.Checkscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/Check().(parsed, exprSrc, env) |
| 576 | if len(iss.GetErrorsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/Errors#GetErrors().()) != 0 { |
| 577 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/TB#Fatalf().("Check(%s) failed: %s", expr, iss.ToDisplayStringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/Errors#ToDisplayString().()) |
| 578 | } |
| 579 | return checked |
| 580 | } |
| 581 | |
| 582 | func newTestRegistryscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/newTestRegistry().(t testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.TBscip-go gomod github.com/golang/go/src go1.23.0 testing/TB#, msgs ...protoscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/.Messagescip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/Message#) *typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Registryscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Registry# { |
| 583 | t.Helperscip-go gomod github.com/golang/go/src go1.23.0 testing/TB#Helper().() |
| 584 | reg, err := typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.NewRegistryscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/NewRegistry().(msgs...) |
| 585 | if err != nil { |
| 586 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/TB#Fatalf().("types.NewRegistry(%v) failed: %v", msgs, err) |
| 587 | } |
| 588 | return reg |
| 589 | } |
| 590 | |
| 591 | func newTestEnvscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast_test`/newTestEnv().(t testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.TBscip-go gomod github.com/golang/go/src go1.23.0 testing/TB#, cont *containersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/.Containerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#, reg *typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Registryscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Registry#) *checkerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/.Envscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/Env# { |
| 592 | t.Helperscip-go gomod github.com/golang/go/src go1.23.0 testing/TB#Helper().() |
| 593 | env, err := checkerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/.NewEnvscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/NewEnv().(cont, reg, checkerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/.CrossTypeNumericComparisonsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/CrossTypeNumericComparisons().(true)) |
| 594 | if err != nil { |
| 595 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/TB#Fatalf().("checker.NewEnv(%v, %v) failed: %v", cont, reg, err) |
| 596 | } |
| 597 | err = env.AddFunctionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/Env#AddFunctions().(stdlibscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/stdlib`/.Functionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/stdlib`/Functions().()...) |
| 598 | if err != nil { |
| 599 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/TB#Fatalf().("env.Add(stdlib.Functions()...) failed: %v", err) |
| 600 | } |
| 601 | env.AddIdentsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/checker`/Env#AddIdents().(declsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/decls`/.NewVariablescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/decls`/NewVariable().("msg", typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.NewObjectTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/NewObjectType().("google.expr.proto3.test.TestAllTypes"))) |
| 602 | return env |
| 603 | } |