diff --git a/d2oracle/edit.go b/d2oracle/edit.go index dd2c882c9..d189f4d0a 100644 --- a/d2oracle/edit.go +++ b/d2oracle/edit.go @@ -895,6 +895,7 @@ func deleteObject(g *d2graph.Graph, key *d2ast.KeyPath, obj *d2graph.Object) (*d }) if obj.Attributes.Shape.Value == d2target.ShapeSQLTable || obj.Attributes.Shape.Value == d2target.ShapeClass { ref.MapKey.Value.Map = nil + ref.MapKey.Primary = ref.MapKey.Value.ScalarBox() } else if len(withoutSpecial) == 0 { hoistRefChildren(g, key, ref) deleteFromMap(ref.Scope, ref.MapKey) diff --git a/d2oracle/edit_test.go b/d2oracle/edit_test.go index 0fc9f7892..f4c3d0ce4 100644 --- a/d2oracle/edit_test.go +++ b/d2oracle/edit_test.go @@ -4799,6 +4799,40 @@ A -> B key: `x.left`, exp: `x +`, + }, + { + name: "chaos_1", + + text: `cm: {shape: cylinder} +cm <-> cm: {source-arrowhead.shape: cf-one-required} +mt: z +cdpdxz + +bymdyk: hdzuj {shape: class} + +bymdyk <-> bymdyk +cm + +cm <-> bymdyk: { + source-arrowhead.shape: cf-many-required + target-arrowhead.shape: arrow +} +bymdyk <-> cdpdxz + +bymdyk -> cm: nk { + target-arrowhead.shape: diamond + target-arrowhead.label: 1 +} +`, + key: `bymdyk`, + + exp: `cm: {shape: cylinder} +cm <-> cm: {source-arrowhead.shape: cf-one-required} +mt: z +cdpdxz + +cm `, }, } diff --git a/testdata/d2oracle/TestDelete/chaos_1.exp.json b/testdata/d2oracle/TestDelete/chaos_1.exp.json new file mode 100644 index 000000000..8c4a7ec9f --- /dev/null +++ b/testdata/d2oracle/TestDelete/chaos_1.exp.json @@ -0,0 +1,528 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,0:0:0-8:0:94", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,0:0:0-0:21:21", + "key": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,0:0:0-0:2:2", + "value": [ + { + "string": "cm", + "raw_string": "cm" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,0:4:4-0:20:20", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,0:5:5-0:20:20", + "key": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,0:5:5-0:10:10", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,0:5:5-0:10:10", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,0:12:12-0:20:20", + "value": [ + { + "string": "cylinder", + "raw_string": "cylinder" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,1:0:22-1:52:74", + "edges": [ + { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,1:0:22-1:9:31", + "src": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,1:0:22-1:3:25", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,1:0:22-1:2:24", + "value": [ + { + "string": "cm", + "raw_string": "cm" + } + ] + } + } + ] + }, + "src_arrow": "<", + "dst": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,1:6:28-1:9:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,1:7:29-1:9:31", + "value": [ + { + "string": "cm", + "raw_string": "cm" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,1:11:33-1:51:73", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,1:12:34-1:51:73", + "key": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,1:12:34-1:34:56", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,1:12:34-1:28:50", + "value": [ + { + "string": "source-arrowhead", + "raw_string": "source-arrowhead" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,1:29:51-1:34:56", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,1:36:58-1:51:73", + "value": [ + { + "string": "cf-one-required", + "raw_string": "cf-one-required" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,2:0:75-2:5:80", + "key": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,2:0:75-2:2:77", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,2:0:75-2:2:77", + "value": [ + { + "string": "mt", + "raw_string": "mt" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,2:4:79-2:5:80", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,3:0:81-3:6:87", + "key": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,3:0:81-3:6:87", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,3:0:81-3:6:87", + "value": [ + { + "string": "cdpdxz", + "raw_string": "cdpdxz" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,7:0:91-7:2:93", + "key": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,7:0:91-7:2:93", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,7:0:91-7:2:93", + "value": [ + { + "string": "cm", + "raw_string": "cm" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + "edges": [ + { + "index": 0, + "minWidth": 0, + "minHeight": 0, + "label_dimensions": { + "width": 0, + "height": 0 + }, + "isCurve": false, + "src_arrow": true, + "srcArrowhead": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "cf-one-required" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "dst_arrow": true, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "cm", + "id_val": "cm", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,0:0:0-0:2:2", + "value": [ + { + "string": "cm", + "raw_string": "cm" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,1:0:22-1:3:25", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,1:0:22-1:2:24", + "value": [ + { + "string": "cm", + "raw_string": "cm" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + }, + { + "key": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,1:6:28-1:9:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,1:7:29-1:9:31", + "value": [ + { + "string": "cm", + "raw_string": "cm" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + }, + { + "key": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,7:0:91-7:2:93", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,7:0:91-7:2:93", + "value": [ + { + "string": "cm", + "raw_string": "cm" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "cm" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "cylinder" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "mt", + "id_val": "mt", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,2:0:75-2:2:77", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,2:0:75-2:2:77", + "value": [ + { + "string": "mt", + "raw_string": "mt" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "z" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "cdpdxz", + "id_val": "cdpdxz", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,3:0:81-3:6:87", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,3:0:81-3:6:87", + "value": [ + { + "string": "cdpdxz", + "raw_string": "cdpdxz" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "cdpdxz" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +}