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

Function TestHeights

common/ast/ast_test.go:406–429  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

404}
405
406func TestHeights(t *testing.T) {
407 tests := []struct {
408 expr string
409 height int
410 }{
411 {`'a' == 'b'`, 1},
412 {`'a'.size()`, 1},
413 {`[1, 2].size()`, 2},
414 {`size('a')`, 1},
415 {`has({'a': 1}.a)`, 2},
416 {`{'a': 1}`, 1},
417 {`{'a': 1}['a']`, 2},
418 {`[1, 2, 3].exists(i, i % 2 == 1)`, 4},
419 {`google.expr.proto3.test.TestAllTypes{}`, 1},
420 {`google.expr.proto3.test.TestAllTypes{repeated_int32: [1, 2]}`, 2},
421 }
422 for _, tst := range tests {
423 checked := mustTypeCheck(t, tst.expr)
424 maxHeight := ast.Heights(checked)[checked.Expr().ID()]
425 if maxHeight != tst.height {
426 t.Errorf("ast.Heights(%q) got max height %d, wanted %d", tst.expr, maxHeight, tst.height)
427 }
428 }
429}
430
431func TestHasExtension(t *testing.T) {
432 info := ast.NewSourceInfo(common.NewStringSource("true", "test-only"))

Callers

nothing calls this directly

Calls 4

HeightsFunction · 0.92
mustTypeCheckFunction · 0.85
IDMethod · 0.65
ExprMethod · 0.65

Tested by

no test coverage detected