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

Function TestASTNilSafety

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

Source from the content-addressed store, hash-verified

134}
135
136func TestASTNilSafety(t *testing.T) {
137 ex, err := ast.ProtoToExpr(nil)
138 if err != nil {
139 t.Fatalf("ast.ProtoToExpr() failed: %v", err)
140 }
141 info, err := ast.ProtoToSourceInfo(nil)
142 if err != nil {
143 t.Fatalf("ast.ProtoToSourceInfo() failed: %v", err)
144 }
145 tests := []*ast.AST{
146 nil,
147 ast.NewAST(nil, nil),
148 ast.NewCheckedAST(nil, nil, nil),
149 ast.NewCheckedAST(ast.NewAST(nil, nil), nil, nil),
150 ast.NewAST(ex, info),
151 ast.NewCheckedAST(ast.NewAST(ex, info), map[int64]*types.Type{}, map[int64]*ast.ReferenceInfo{}),
152 }
153 for _, tst := range tests {
154 a := tst
155 asts := []*ast.AST{a, ast.Copy(a)}
156 for _, testAST := range asts {
157 if testAST.Expr().ID() != 0 {
158 t.Errorf("Expr().ID() got %v, wanted 0", testAST.Expr().ID())
159 }
160 if testAST.SourceInfo().SyntaxVersion() != "" {
161 t.Errorf("SourceInfo().SyntaxVersion() got %s, wanted empty string", testAST.SourceInfo().SyntaxVersion())
162 }
163 if testAST.IsChecked() {
164 t.Error("IsChecked() returned true, wanted false")
165 }
166 if testAST.GetType(testAST.Expr().ID()) != types.DynType {
167 t.Errorf("GetType() got %v, wanted dyn", testAST.GetType(testAST.Expr().ID()))
168 }
169 if len(testAST.GetOverloadIDs(testAST.Expr().ID())) != 0 {
170 t.Errorf("GetOverloadIDs() got %v, wanted empty set", testAST.GetOverloadIDs(testAST.Expr().ID()))
171 }
172 }
173 }
174}
175
176func TestSourceInfo(t *testing.T) {
177 src := common.NewStringSource("a\n? b\n: c", "custom description")

Callers

nothing calls this directly

Calls 13

ProtoToExprFunction · 0.92
ProtoToSourceInfoFunction · 0.92
NewASTFunction · 0.92
NewCheckedASTFunction · 0.92
CopyFunction · 0.92
SyntaxVersionMethod · 0.80
GetOverloadIDsMethod · 0.80
IDMethod · 0.65
ExprMethod · 0.65
SourceInfoMethod · 0.45
IsCheckedMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected