d2oralce handle deleting imported
This commit is contained in:
parent
1e5d8fa380
commit
b5bfb09e51
4 changed files with 589 additions and 18 deletions
|
|
@ -920,34 +920,45 @@ func Delete(g *d2graph.Graph, boardPath []string, key string) (_ *d2graph.Graph,
|
|||
|
||||
prevG, _ := recompile(boardG)
|
||||
|
||||
boardG, err = renameConflictsToParent(boardG, mk.Key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
obj, ok := boardG.Root.HasChild(d2graph.Key(mk.Key))
|
||||
if !ok {
|
||||
return g, nil
|
||||
}
|
||||
|
||||
if len(boardPath) > 0 {
|
||||
writeableRefs := getWriteableRefs(obj, baseAST)
|
||||
if len(writeableRefs) != len(obj.References) {
|
||||
mk.Value = d2ast.MakeValueBox(&d2ast.Null{})
|
||||
}
|
||||
}
|
||||
imported := IsImported(baseAST, obj)
|
||||
|
||||
if _, ok := mk.Value.Unbox().(*d2ast.Null); !ok {
|
||||
boardG, err = deleteObject(boardG, baseAST, mk.Key, obj)
|
||||
if imported {
|
||||
println(d2format.Format(boardG.AST))
|
||||
mk.Value = d2ast.MakeValueBox(&d2ast.Null{})
|
||||
appendMapKey(baseAST, mk)
|
||||
} else {
|
||||
boardG, err = renameConflictsToParent(boardG, mk.Key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := updateNear(prevG, boardG, &key, nil, false); err != nil {
|
||||
return nil, err
|
||||
obj, ok = boardG.Root.HasChild(d2graph.Key(mk.Key))
|
||||
if !ok {
|
||||
return g, nil
|
||||
}
|
||||
if len(boardPath) > 0 {
|
||||
writeableRefs := getWriteableRefs(obj, baseAST)
|
||||
if len(writeableRefs) != len(obj.References) {
|
||||
mk.Value = d2ast.MakeValueBox(&d2ast.Null{})
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := mk.Value.Unbox().(*d2ast.Null); !ok {
|
||||
boardG, err = deleteObject(boardG, baseAST, mk.Key, obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := updateNear(prevG, boardG, &key, nil, false); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
appendMapKey(baseAST, mk)
|
||||
}
|
||||
} else {
|
||||
appendMapKey(baseAST, mk)
|
||||
}
|
||||
|
||||
if len(boardPath) > 0 {
|
||||
|
|
|
|||
|
|
@ -7158,6 +7158,53 @@ scenarios: {
|
|||
(a -> b)[0]: null
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "import/1",
|
||||
|
||||
text: `...@meow
|
||||
y
|
||||
`,
|
||||
fsTexts: map[string]string{
|
||||
"meow.d2": `x: {
|
||||
a
|
||||
}
|
||||
`,
|
||||
},
|
||||
key: `x`,
|
||||
exp: `...@meow
|
||||
y
|
||||
x: null
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "import/2",
|
||||
|
||||
text: `...@meow
|
||||
|
||||
scenarios: {
|
||||
y: {
|
||||
c
|
||||
}
|
||||
}
|
||||
`,
|
||||
fsTexts: map[string]string{
|
||||
"meow.d2": `x: {
|
||||
a
|
||||
}
|
||||
`,
|
||||
},
|
||||
boardPath: []string{"y"},
|
||||
key: `x`,
|
||||
exp: `...@meow
|
||||
|
||||
scenarios: {
|
||||
y: {
|
||||
c
|
||||
x: null
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
153
testdata/d2oracle/TestDelete/import/1.exp.json
generated
vendored
Normal file
153
testdata/d2oracle/TestDelete/import/1.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
{
|
||||
"graph": {
|
||||
"name": "",
|
||||
"isFolderOnly": false,
|
||||
"ast": {
|
||||
"range": "index.d2,0:0:0-3:0:19",
|
||||
"nodes": [
|
||||
{
|
||||
"import": {
|
||||
"range": "index.d2,0:0:0-0:8:8",
|
||||
"spread": true,
|
||||
"pre": "",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "index.d2,0:4:4-0:8:8",
|
||||
"value": [
|
||||
{
|
||||
"string": "meow",
|
||||
"raw_string": "meow"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"map_key": {
|
||||
"range": "index.d2,1:0:9-1:1:10",
|
||||
"key": {
|
||||
"range": "index.d2,1:0:9-1:1:10",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "index.d2,1:0:9-1:1:10",
|
||||
"value": [
|
||||
{
|
||||
"string": "y",
|
||||
"raw_string": "y"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"map_key": {
|
||||
"range": "index.d2,2:0:11-2:7:18",
|
||||
"key": {
|
||||
"range": "index.d2,2:0:11-2:1:12",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "index.d2,2:0:11-2:1:12",
|
||||
"value": [
|
||||
{
|
||||
"string": "x",
|
||||
"raw_string": "x"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {
|
||||
"null": {
|
||||
"range": "index.d2,2:3:14-2:7:18"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"root": {
|
||||
"id": "",
|
||||
"id_val": "",
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": ""
|
||||
},
|
||||
"labelDimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": ""
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": null
|
||||
},
|
||||
"zIndex": 0
|
||||
},
|
||||
"edges": null,
|
||||
"objects": [
|
||||
{
|
||||
"id": "y",
|
||||
"id_val": "y",
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
"range": "index.d2,1:0:9-1:1:10",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "index.d2,1:0:9-1:1:10",
|
||||
"value": [
|
||||
{
|
||||
"string": "y",
|
||||
"raw_string": "y"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path_index": 0,
|
||||
"map_key_edge_index": -1
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "y"
|
||||
},
|
||||
"labelDimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": "rectangle"
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": null
|
||||
},
|
||||
"zIndex": 0
|
||||
}
|
||||
]
|
||||
},
|
||||
"err": "<nil>"
|
||||
}
|
||||
360
testdata/d2oracle/TestDelete/import/2.exp.json
generated
vendored
Normal file
360
testdata/d2oracle/TestDelete/import/2.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,360 @@
|
|||
{
|
||||
"graph": {
|
||||
"name": "",
|
||||
"isFolderOnly": false,
|
||||
"ast": {
|
||||
"range": "index.d2,0:0:0-8:0:54",
|
||||
"nodes": [
|
||||
{
|
||||
"import": {
|
||||
"range": "index.d2,0:0:0-0:8:8",
|
||||
"spread": true,
|
||||
"pre": "",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "index.d2,0:4:4-0:8:8",
|
||||
"value": [
|
||||
{
|
||||
"string": "meow",
|
||||
"raw_string": "meow"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"map_key": {
|
||||
"range": "index.d2,2:0:10-7:1:53",
|
||||
"key": {
|
||||
"range": "index.d2,2:0:10-2:9:19",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "index.d2,2:0:10-2:9:19",
|
||||
"value": [
|
||||
{
|
||||
"string": "scenarios",
|
||||
"raw_string": "scenarios"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {
|
||||
"map": {
|
||||
"range": "index.d2,2:11:21-7:1:53",
|
||||
"nodes": [
|
||||
{
|
||||
"map_key": {
|
||||
"range": "index.d2,3:2:25-6:3:51",
|
||||
"key": {
|
||||
"range": "index.d2,3:2:25-3:3:26",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "index.d2,3:2:25-3:3:26",
|
||||
"value": [
|
||||
{
|
||||
"string": "y",
|
||||
"raw_string": "y"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {
|
||||
"map": {
|
||||
"range": "index.d2,3:5:28-6:3:51",
|
||||
"nodes": [
|
||||
{
|
||||
"map_key": {
|
||||
"range": "index.d2,4:4:34-4:5:35",
|
||||
"key": {
|
||||
"range": "index.d2,4:4:34-4:5:35",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "index.d2,4:4:34-4:5:35",
|
||||
"value": [
|
||||
{
|
||||
"string": "c",
|
||||
"raw_string": "c"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"map_key": {
|
||||
"range": "index.d2,5:4:40-5:11:47",
|
||||
"key": {
|
||||
"range": "index.d2,5:4:40-5:5:41",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "index.d2,5:4:40-5:5:41",
|
||||
"value": [
|
||||
{
|
||||
"string": "x",
|
||||
"raw_string": "x"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {
|
||||
"null": {
|
||||
"range": "index.d2,5:7:43-5:11:47"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"root": {
|
||||
"id": "",
|
||||
"id_val": "",
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": ""
|
||||
},
|
||||
"labelDimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": ""
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": null
|
||||
},
|
||||
"zIndex": 0
|
||||
},
|
||||
"edges": null,
|
||||
"objects": [
|
||||
{
|
||||
"id": "x",
|
||||
"id_val": "x",
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
"range": "meow.d2,0:0:0-0:1:1",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "meow.d2,0:0:0-0:1:1",
|
||||
"value": [
|
||||
{
|
||||
"string": "x",
|
||||
"raw_string": "x"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path_index": 0,
|
||||
"map_key_edge_index": -1
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "x"
|
||||
},
|
||||
"labelDimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": "rectangle"
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": null
|
||||
},
|
||||
"zIndex": 0
|
||||
},
|
||||
{
|
||||
"id": "a",
|
||||
"id_val": "a",
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
"range": "meow.d2,1:2:7-1:3:8",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "meow.d2,1:2:7-1:3:8",
|
||||
"value": [
|
||||
{
|
||||
"string": "a",
|
||||
"raw_string": "a"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path_index": 0,
|
||||
"map_key_edge_index": -1
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "a"
|
||||
},
|
||||
"labelDimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": "rectangle"
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": null
|
||||
},
|
||||
"zIndex": 0
|
||||
}
|
||||
],
|
||||
"scenarios": [
|
||||
{
|
||||
"name": "y",
|
||||
"isFolderOnly": false,
|
||||
"ast": {
|
||||
"range": ",1:0:0-2:0:0",
|
||||
"nodes": [
|
||||
{
|
||||
"map_key": {
|
||||
"range": ",0:0:0-0:0:0",
|
||||
"key": {
|
||||
"range": ",0:0:0-0:0:0",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": ",0:0:0-0:0:0",
|
||||
"value": [
|
||||
{
|
||||
"string": "c"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"root": {
|
||||
"id": "",
|
||||
"id_val": "",
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": ""
|
||||
},
|
||||
"labelDimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": ""
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": null
|
||||
},
|
||||
"zIndex": 0
|
||||
},
|
||||
"edges": null,
|
||||
"objects": [
|
||||
{
|
||||
"id": "c",
|
||||
"id_val": "c",
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
"range": "index.d2,4:4:34-4:5:35",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "index.d2,4:4:34-4:5:35",
|
||||
"value": [
|
||||
{
|
||||
"string": "c",
|
||||
"raw_string": "c"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path_index": 0,
|
||||
"map_key_edge_index": -1
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "c"
|
||||
},
|
||||
"labelDimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": "rectangle"
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": null
|
||||
},
|
||||
"zIndex": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"err": "<nil>"
|
||||
}
|
||||
Loading…
Reference in a new issue