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

Function TestConvertAST

common/ast/conversion_test.go:38–282  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

36)
37
38func TestConvertAST(t *testing.T) {
39 fac := ast.NewExprFactory()
40 tests := []struct {
41 name string
42 goAST *ast.AST
43 pbAST *exprpb.CheckedExpr
44 }{
45 {
46 name: "simple ast",
47 goAST: ast.NewCheckedAST(ast.NewAST(nil, nil),
48 map[int64]*types.Type{
49 1: types.BoolType,
50 2: types.DynType,
51 },
52 map[int64]*ast.ReferenceInfo{
53 1: ast.NewFunctionReference(overloads.LogicalNot),
54 2: ast.NewIdentReference("TRUE", types.True),
55 },
56 ),
57 pbAST: &exprpb.CheckedExpr{
58 Expr: &exprpb.Expr{},
59 SourceInfo: &exprpb.SourceInfo{},
60 TypeMap: map[int64]*exprpb.Type{
61 1: chkdecls.Bool,
62 2: chkdecls.Dyn,
63 },
64 ReferenceMap: map[int64]*exprpb.Reference{
65 1: {OverloadId: []string{overloads.LogicalNot}},
66 2: {
67 Name: "TRUE",
68 Value: &exprpb.Constant{
69 ConstantKind: &exprpb.Constant_BoolValue{BoolValue: true},
70 },
71 },
72 },
73 },
74 },
75 {
76 name: "comprehension ast",
77 goAST: ast.NewAST(
78 fac.NewComprehensionTwoVar(1,
79 fac.NewIdent(2, "data"),
80 "i",
81 "v",
82 "__result__",
83 fac.NewList(3, []ast.Expr{}, []int32{}),
84 fac.NewLiteral(4, types.True),
85 fac.NewCall(8, operators.Add,
86 fac.NewAccuIdent(9),
87 fac.NewCall(5, operators.Add,
88 fac.NewIdent(6, "i"),
89 fac.NewIdent(7, "v"),
90 )),
91 fac.NewAccuIdent(10),
92 ), nil),
93 pbAST: &exprpb.CheckedExpr{
94 Expr: &exprpb.Expr{
95 Id: 1,

Callers

nothing calls this directly

Calls 15

NewIdentMethod · 0.95
NewListMethod · 0.95
NewLiteralMethod · 0.95
NewCallMethod · 0.95
NewAccuIdentMethod · 0.95
NewExprFactoryFunction · 0.92
NewCheckedASTFunction · 0.92
NewASTFunction · 0.92
NewFunctionReferenceFunction · 0.92
NewIdentReferenceFunction · 0.92
NewSourceInfoFunction · 0.92

Tested by

no test coverage detected