(t *testing.T)
| 2103 | } |
| 2104 | |
| 2105 | func 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 | } |
nothing calls this directly
no test coverage detected