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

Function TestUpdateMetadata

cel/folding_test.go:2105–2131  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2103}
2104
2105func TestUpdateMetadata(t *testing.T) {
2106 // updateMetadata with nil AST does not panic
2107 updateMetadata(nil, 1, 2)
2108
2109 fac := ast.NewExprFactory()
2110 e1 := fac.NewIdent(1, "x")
2111 info := ast.NewSourceInfo(nil)
2112 a := ast.NewAST(e1, info)
2113 checked := ast.NewCheckedAST(a, map[int64]*types.Type{2: types.IntType}, map[int64]*ast.ReferenceInfo{
2114 2: ast.NewIdentReference("y", nil),
2115 })
2116
2117 // When updatedID has reference and type info
2118 updateMetadata(checked, 1, 2)
2119 if ref, found := checked.ReferenceMap()[1]; !found || ref.Name != "y" {
2120 t.Errorf("expected ref 'y' on target ID 1, got %v", ref)
2121 }
2122 if typ, found := checked.TypeMap()[1]; !found || typ != types.IntType {
2123 t.Errorf("expected type IntType on target ID 1, got %v", typ)
2124 }
2125
2126 // When updatedID is not in ReferenceMap
2127 updateMetadata(checked, 1, 3)
2128 if _, found := checked.ReferenceMap()[1]; found {
2129 t.Errorf("expected target ID 1 to be removed from ReferenceMap")
2130 }
2131}

Callers

nothing calls this directly

Calls 9

NewIdentMethod · 0.95
NewExprFactoryFunction · 0.92
NewSourceInfoFunction · 0.92
NewASTFunction · 0.92
NewCheckedASTFunction · 0.92
NewIdentReferenceFunction · 0.92
updateMetadataFunction · 0.85
ReferenceMapMethod · 0.80
TypeMapMethod · 0.80

Tested by

no test coverage detected