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

Function TestExprVisitor

common/ast/navigable_test.go:137–226  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

135}
136
137func TestExprVisitor(t *testing.T) {
138 tests := []struct {
139 expr string
140 preOrderIDs []int64
141 postOrderIDs []int64
142 }{
143 {
144 // [2] ==, [1] 'a', [3] 'b'
145 expr: `'a' == 'b'`,
146 preOrderIDs: []int64{2, 1, 3},
147 postOrderIDs: []int64{1, 3, 2},
148 },
149 {
150 // [2] size(), [1] 'a'
151 expr: `'a'.size()`,
152 preOrderIDs: []int64{2, 1},
153 postOrderIDs: []int64{1, 2},
154 },
155 {
156 // [3] ==, [1] type(), [2] 1, [4] int
157 expr: `type(1) == int`,
158 preOrderIDs: []int64{3, 1, 2, 4},
159 postOrderIDs: []int64{2, 1, 4, 3},
160 },
161 {
162 // [5] .hello, [1] {}, [3] 'hello', [4] 'world'
163 expr: `{'hello': 'world'}.hello`,
164 preOrderIDs: []int64{5, 1, 3, 4},
165 postOrderIDs: []int64{3, 4, 1, 5},
166 },
167 {
168 // [1] TestAllTypes, [3] 1
169 expr: `google.expr.proto3.test.TestAllTypes{single_int32: 1}`,
170 preOrderIDs: []int64{1, 3},
171 postOrderIDs: []int64{3, 1},
172 },
173 {
174 // [13] comprehension
175 // range: [1] [], [2] true
176 // accuInit: [6] result=false
177 // loopCond: [9] @not_strictly_false, [8] !, [7] result
178 // loopStep: [11] ||, [10] result [5] i
179 // result: [12] result
180 expr: `[true].exists(i, i)`,
181 preOrderIDs: []int64{13, 1, 2, 6, 9, 8, 7, 11, 10, 5, 12},
182 postOrderIDs: []int64{2, 1, 6, 7, 8, 9, 10, 5, 11, 12, 13},
183 },
184 }
185
186 for _, tst := range tests {
187 tc := tst
188 t.Run(tc.expr, func(t *testing.T) {
189 checked := mustTypeCheck(t, tc.expr)
190 root := ast.NavigateAST(checked)
191 // Verify pre order visit behavior
192 preOrderExprIDs := []int64{}
193 navVisitor := ast.NewExprVisitor(func(e ast.Expr) {
194 nav := e.(ast.NavigableExpr)

Callers

nothing calls this directly

Calls 7

NavigateASTFunction · 0.92
NewExprVisitorFunction · 0.92
PreOrderVisitFunction · 0.92
PostOrderVisitFunction · 0.92
mustTypeCheckFunction · 0.85
IDMethod · 0.65
ChildrenMethod · 0.65

Tested by

no test coverage detected