This commit is contained in:
Alexander Wang 2023-06-26 10:36:12 -07:00
parent e1eecf7c7b
commit 02fa36d598
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
5 changed files with 1111 additions and 0 deletions

View file

@ -2952,6 +2952,7 @@ a: null
a -> b
(a -> b)[0]: null
`, "")
assert.Equal(t, 2, len(g.Objects))
assert.Equal(t, 0, len(g.Edges))
},
},
@ -2988,6 +2989,18 @@ a
assert.Equal(t, 1, len(g.Objects))
},
},
{
name: "edge",
run: func(t *testing.T) {
g := assertCompile(t, `
a -> b
(a -> b)[0]: null
a -> b
`, "")
assert.Equal(t, 2, len(g.Objects))
assert.Equal(t, 1, len(g.Edges))
},
},
}
for _, tc := range tca {
@ -3032,6 +3045,19 @@ x -> y
assert.Equal(t, 1, len(g.Edges))
},
},
{
name: "delete-children",
run: func(t *testing.T) {
g := assertCompile(t, `
x.y.z
a.b.c
x: null
a.b: null
`, "")
assert.Equal(t, 1, len(g.Objects))
},
},
}
for _, tc := range tca {

View file

@ -0,0 +1,291 @@
{
"graph": {
"name": "",
"isFolderOnly": false,
"ast": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,0:0:0-6:0:32",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,1:0:1-1:5:6",
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,1:0:1-1:5:6",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,1:0:1-1:1:2",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,1:2:3-1:3:4",
"value": [
{
"string": "y",
"raw_string": "y"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,1:4:5-1:5:6",
"value": [
{
"string": "z",
"raw_string": "z"
}
]
}
}
]
},
"primary": {},
"value": {}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,2:0:7-2:5:12",
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,2:0:7-2:5:12",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,2:0:7-2:1:8",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,2:2:9-2:3:10",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,2:4:11-2:5:12",
"value": [
{
"string": "c",
"raw_string": "c"
}
]
}
}
]
},
"primary": {},
"value": {}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,4:0:14-4:7:21",
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,4:0:14-4:1:15",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,4:0:14-4:1:15",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"primary": {},
"value": {
"null": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,4:3:17-4:7:21"
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,5:0:22-5:9:31",
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,5:0:22-5:3:25",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,5:0:22-5:1:23",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,5:2:24-5:3:25",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"primary": {},
"value": {
"null": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,5:5:27-5:9:31"
}
}
}
}
]
},
"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": "a",
"id_val": "a",
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,2:0:7-2:5:12",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,2:0:7-2:1:8",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,2:2:9-2:3:10",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,2:4:11-2:5:12",
"value": [
{
"string": "c",
"raw_string": "c"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
},
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,5:0:22-5:3:25",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,5:0:22-5:1:23",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,5:2:24-5:3:25",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"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
}
]
},
"err": null
}

View file

@ -0,0 +1,156 @@
{
"graph": {
"name": "",
"isFolderOnly": false,
"ast": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-connection.d2,0:0:0-3:0:16",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-connection.d2,1:0:1-1:6:7",
"edges": [
{
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-connection.d2,1:0:1-1:6:7",
"src": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-connection.d2,1:0:1-1:1:2",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-connection.d2,1:0:1-1:1:2",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"src_arrow": "",
"dst": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-connection.d2,1:5:6-1:6:7",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-connection.d2,1:5:6-1:6:7",
"value": [
{
"string": "y",
"raw_string": "y"
}
]
}
}
]
},
"dst_arrow": ">"
}
],
"primary": {},
"value": {}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-connection.d2,2:0:8-2:7:15",
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-connection.d2,2:0:8-2:1:9",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-connection.d2,2:0:8-2:1:9",
"value": [
{
"string": "y",
"raw_string": "y"
}
]
}
}
]
},
"primary": {},
"value": {
"null": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-connection.d2,2:3:11-2:7:15"
}
}
}
}
]
},
"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": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-connection.d2,1:0:1-1:1:2",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-connection.d2,1:0:1-1:1:2",
"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": null
},
"zIndex": 0
}
]
},
"err": null
}

View file

@ -0,0 +1,252 @@
{
"graph": {
"name": "",
"isFolderOnly": false,
"ast": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,0:0:0-3:0:16",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,1:0:1-1:7:8",
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,1:0:1-1:1:2",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,1:0:1-1:1:2",
"value": [
{
"string": "y",
"raw_string": "y"
}
]
}
}
]
},
"primary": {},
"value": {
"null": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,1:3:4-1:7:8"
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,2:0:9-2:6:15",
"edges": [
{
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,2:0:9-2:6:15",
"src": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,2:0:9-2:1:10",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,2:0:9-2:1:10",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"src_arrow": "",
"dst": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,2:5:14-2:6:15",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,2:5:14-2:6:15",
"value": [
{
"string": "y",
"raw_string": "y"
}
]
}
}
]
},
"dst_arrow": ">"
}
],
"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": [
{
"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": null
},
"zIndex": 0
}
],
"objects": [
{
"id": "y",
"id_val": "y",
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,1:0:1-1:1:2",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,1:0:1-1:1:2",
"value": [
{
"string": "y",
"raw_string": "y"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
},
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,2:5:14-2:6:15",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,2:5:14-2:6:15",
"value": [
{
"string": "y",
"raw_string": "y"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": 0
}
],
"attributes": {
"label": {
"value": ""
},
"labelDimensions": {
"width": 0,
"height": 0
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": null
},
"zIndex": 0
},
{
"id": "x",
"id_val": "x",
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,2:0:9-2:1:10",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,2:0:9-2:1:10",
"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": null
},
"zIndex": 0
}
]
},
"err": null
}

View file

@ -0,0 +1,386 @@
{
"graph": {
"name": "",
"isFolderOnly": false,
"ast": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,0:0:0-4:0:33",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,1:0:1-1:6:7",
"edges": [
{
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,1:0:1-1:6:7",
"src": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,1:0:1-1:1:2",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,1:0:1-1:1:2",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
}
]
},
"src_arrow": "",
"dst": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,1:5:6-1:6:7",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,1:5:6-1:6:7",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"dst_arrow": ">"
}
],
"primary": {},
"value": {}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,2:0:8-2:17:25",
"edges": [
{
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,2:1:9-2:7:15",
"src": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,2:1:9-2:2:10",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,2:1:9-2:2:10",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
}
]
},
"src_arrow": "",
"dst": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,2:6:14-2:7:15",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,2:6:14-2:7:15",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"dst_arrow": ">"
}
],
"edge_index": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,2:8:16-2:11:19",
"int": 0,
"glob": false
},
"primary": {},
"value": {
"null": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,2:13:21-2:17:25"
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,3:0:26-3:6:32",
"edges": [
{
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,3:0:26-3:6:32",
"src": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,3:0:26-3:1:27",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,3:0:26-3:1:27",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
}
]
},
"src_arrow": "",
"dst": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,3:5:31-3:6:32",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,3:5:31-3:6:32",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"dst_arrow": ">"
}
],
"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": [
{
"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": null
},
"zIndex": 0
}
],
"objects": [
{
"id": "a",
"id_val": "a",
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,1:0:1-1:1:2",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,1:0:1-1:1:2",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": 0
},
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,2:1:9-2:2:10",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,2:1:9-2:2:10",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": 0
},
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,3:0:26-3:1:27",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,3:0:26-3:1:27",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": 0
}
],
"attributes": {
"label": {
"value": "a"
},
"labelDimensions": {
"width": 0,
"height": 0
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": null
},
"zIndex": 0
},
{
"id": "b",
"id_val": "b",
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,1:5:6-1:6:7",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,1:5:6-1:6:7",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": 0
},
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,2:6:14-2:7:15",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,2:6:14-2:7:15",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": 0
},
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,3:5:31-3:6:32",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,3:5:31-3:6:32",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": 0
}
],
"attributes": {
"label": {
"value": "b"
},
"labelDimensions": {
"width": 0,
"height": 0
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": null
},
"zIndex": 0
}
]
},
"err": null
}