min/max
This commit is contained in:
parent
77286e20c8
commit
49828667f7
3 changed files with 350 additions and 1 deletions
|
|
@ -1706,7 +1706,7 @@ func move(g *d2graph.Graph, key, newKey string, includeDescendants bool) (*d2gra
|
|||
}
|
||||
|
||||
if includeDescendants {
|
||||
ref.Key.Path = append(ref.Key.Path[:ref.KeyPathIndex-1], append(newPath, ref.Key.Path[ref.KeyPathIndex+len(newPath):]...)...)
|
||||
ref.Key.Path = append(ref.Key.Path[:go2.Max(0, ref.KeyPathIndex-1)], append(newPath, ref.Key.Path[go2.Min(len(ref.Key.Path), ref.KeyPathIndex+len(newPath)):]...)...)
|
||||
} else {
|
||||
ref.Key.Path = newPath
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4101,6 +4101,19 @@ y
|
|||
b
|
||||
y
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "include_descendants_edge_ref_6",
|
||||
text: `x -> y
|
||||
z
|
||||
`,
|
||||
key: `y`,
|
||||
newKey: `z.y`,
|
||||
includeDescendants: true,
|
||||
|
||||
exp: `x -> z.y
|
||||
z
|
||||
`,
|
||||
},
|
||||
{
|
||||
|
|
|
|||
336
testdata/d2oracle/TestMove/include_descendants_edge_ref_6.exp.json
generated
vendored
Normal file
336
testdata/d2oracle/TestMove/include_descendants_edge_ref_6.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,336 @@
|
|||
{
|
||||
"graph": {
|
||||
"name": "",
|
||||
"isFolderOnly": false,
|
||||
"ast": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_6.d2,0:0:0-2:0:11",
|
||||
"nodes": [
|
||||
{
|
||||
"map_key": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_6.d2,0:0:0-0:8:8",
|
||||
"edges": [
|
||||
{
|
||||
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_6.d2,0:0:0-0:8:8",
|
||||
"src": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_6.d2,0:0:0-0:1:1",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_6.d2,0:0:0-0:1:1",
|
||||
"value": [
|
||||
{
|
||||
"string": "x",
|
||||
"raw_string": "x"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"src_arrow": "",
|
||||
"dst": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_6.d2,0:5:5-0:8:8",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_6.d2,0:5:5-0:6:6",
|
||||
"value": [
|
||||
{
|
||||
"string": "z",
|
||||
"raw_string": "z"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_6.d2,0:7:7-0:8:8",
|
||||
"value": [
|
||||
{
|
||||
"string": "y",
|
||||
"raw_string": "y"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"dst_arrow": ">"
|
||||
}
|
||||
],
|
||||
"primary": {},
|
||||
"value": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"map_key": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_6.d2,1:0:9-1:1:10",
|
||||
"key": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_6.d2,1:0:9-1:1:10",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_6.d2,1:0:9-1:1:10",
|
||||
"value": [
|
||||
{
|
||||
"string": "z",
|
||||
"raw_string": "z"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"root": {
|
||||
"id": "",
|
||||
"id_val": "",
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": ""
|
||||
},
|
||||
"labelDimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": ""
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": {
|
||||
"value": ""
|
||||
}
|
||||
},
|
||||
"zIndex": 0
|
||||
},
|
||||
"edges": [
|
||||
{
|
||||
"index": 0,
|
||||
"isCurve": false,
|
||||
"src_arrow": false,
|
||||
"dst_arrow": true,
|
||||
"references": [
|
||||
{
|
||||
"map_key_edge_index": 0
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": ""
|
||||
},
|
||||
"labelDimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": ""
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": {
|
||||
"value": ""
|
||||
}
|
||||
},
|
||||
"zIndex": 0
|
||||
}
|
||||
],
|
||||
"objects": [
|
||||
{
|
||||
"id": "x",
|
||||
"id_val": "x",
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_6.d2,0:0:0-0:1:1",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_6.d2,0:0:0-0:1:1",
|
||||
"value": [
|
||||
{
|
||||
"string": "x",
|
||||
"raw_string": "x"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path_index": 0,
|
||||
"map_key_edge_index": 0
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "x"
|
||||
},
|
||||
"labelDimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": "rectangle"
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": {
|
||||
"value": ""
|
||||
}
|
||||
},
|
||||
"zIndex": 0
|
||||
},
|
||||
{
|
||||
"id": "z",
|
||||
"id_val": "z",
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_6.d2,0:5:5-0:8:8",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_6.d2,0:5:5-0:6:6",
|
||||
"value": [
|
||||
{
|
||||
"string": "z",
|
||||
"raw_string": "z"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_6.d2,0:7:7-0:8:8",
|
||||
"value": [
|
||||
{
|
||||
"string": "y",
|
||||
"raw_string": "y"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path_index": 0,
|
||||
"map_key_edge_index": 0
|
||||
},
|
||||
{
|
||||
"key": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_6.d2,1:0:9-1:1:10",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_6.d2,1:0:9-1:1:10",
|
||||
"value": [
|
||||
{
|
||||
"string": "z",
|
||||
"raw_string": "z"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path_index": 0,
|
||||
"map_key_edge_index": -1
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "z"
|
||||
},
|
||||
"labelDimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": "rectangle"
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": {
|
||||
"value": ""
|
||||
}
|
||||
},
|
||||
"zIndex": 0
|
||||
},
|
||||
{
|
||||
"id": "y",
|
||||
"id_val": "y",
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_6.d2,0:5:5-0:8:8",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_6.d2,0:5:5-0:6:6",
|
||||
"value": [
|
||||
{
|
||||
"string": "z",
|
||||
"raw_string": "z"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/include_descendants_edge_ref_6.d2,0:7:7-0:8:8",
|
||||
"value": [
|
||||
{
|
||||
"string": "y",
|
||||
"raw_string": "y"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path_index": 1,
|
||||
"map_key_edge_index": 0
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "y"
|
||||
},
|
||||
"labelDimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": "rectangle"
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": {
|
||||
"value": ""
|
||||
}
|
||||
},
|
||||
"zIndex": 0
|
||||
}
|
||||
]
|
||||
},
|
||||
"err": "<nil>"
|
||||
}
|
||||
Loading…
Reference in a new issue