This commit is contained in:
Alexander Wang 2025-02-28 15:28:58 -07:00
parent 6f920731d9
commit 6456f1866e
No known key found for this signature in database
GPG key ID: BE3937D0D52D8927
4 changed files with 705 additions and 7 deletions

View file

@ -1491,8 +1491,6 @@ type ScalarBox struct {
func (sb ScalarBox) Unbox() Scalar { func (sb ScalarBox) Unbox() Scalar {
switch { switch {
case sb.Null != nil:
return sb.Null
case sb.Null != nil: case sb.Null != nil:
return sb.Null return sb.Null
case sb.Suspension != nil: case sb.Suspension != nil:

View file

@ -5472,7 +5472,7 @@ a.width: 339
}, },
}, },
{ {
name: "suspension-restore-edge", name: "suspension-lazy",
run: func(t *testing.T) { run: func(t *testing.T) {
g, _ := assertCompile(t, ` g, _ := assertCompile(t, `
a -> b a -> b
@ -5480,11 +5480,23 @@ c
**: suspend **: suspend
(** -> **)[*]: suspend (** -> **)[*]: suspend
d d
# Also restores the objects connected
(** -> b)[*]: restore
`, ``) `, ``)
assert.Equal(t, 3, len(g.Objects)) assert.Equal(t, 1, len(g.Objects))
},
},
{
name: "suspension-quotes",
run: func(t *testing.T) {
g, _ := assertCompile(t, `
a -> b
c
**: suspend
(** -> **)[*]: suspend
d: "suspend"
d -> d: "suspend"
`, ``)
assert.Equal(t, 1, len(g.Objects))
assert.Equal(t, 1, len(g.Edges))
}, },
}, },
} }

View file

@ -0,0 +1,274 @@
{
"graph": {
"name": "",
"isFolderOnly": false,
"ast": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,0:0:0-6:0:47",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,1:0:1-1:6:7",
"edges": [
{
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,1:0:1-1:6:7",
"src": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,1:0:1-1:1:2",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,1:0:1-1:1:2",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
}
]
},
"src_arrow": "",
"dst": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,1:5:6-1:6:7",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,1:5:6-1:6:7",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"dst_arrow": ">"
}
],
"primary": {},
"value": {}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,2:0:8-2:1:9",
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,2:0:8-2:1:9",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,2:0:8-2:1:9",
"value": [
{
"string": "c",
"raw_string": "c"
}
]
}
}
]
},
"primary": {},
"value": {}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,3:0:10-3:11:21",
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,3:0:10-3:2:12",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,3:0:10-3:2:12",
"value": [
{
"string": "**",
"raw_string": "**"
}
],
"pattern": [
"*",
"",
"*"
]
}
}
]
},
"primary": {},
"value": {
"suspension": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,3:4:14-3:11:21",
"value": true
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,4:0:22-4:22:44",
"edges": [
{
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,4:1:23-4:9:31",
"src": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,4:1:23-4:3:25",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,4:1:23-4:3:25",
"value": [
{
"string": "**",
"raw_string": "**"
}
],
"pattern": [
"*",
"",
"*"
]
}
}
]
},
"src_arrow": "",
"dst": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,4:7:29-4:9:31",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,4:7:29-4:9:31",
"value": [
{
"string": "**",
"raw_string": "**"
}
],
"pattern": [
"*",
"",
"*"
]
}
}
]
},
"dst_arrow": ">"
}
],
"edge_index": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,4:10:32-4:13:35",
"int": null,
"glob": true
},
"primary": {},
"value": {
"suspension": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,4:15:37-4:22:44",
"value": true
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,5:0:45-5:1:46",
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,5:0:45-5:1:46",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,5:0:45-5:1:46",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
}
]
},
"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": "d",
"id_val": "d",
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,5:0:45-5:1:46",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-lazy.d2,5:0:45-5:1:46",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "d"
},
"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,414 @@
{
"graph": {
"name": "",
"isFolderOnly": false,
"ast": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,0:0:0-7:0:76",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,1:0:1-1:6:7",
"edges": [
{
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,1:0:1-1:6:7",
"src": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,1:0:1-1:1:2",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,1:0:1-1:1:2",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
}
]
},
"src_arrow": "",
"dst": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,1:5:6-1:6:7",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,1:5:6-1:6:7",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"dst_arrow": ">"
}
],
"primary": {},
"value": {}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,2:0:8-2:1:9",
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,2:0:8-2:1:9",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,2:0:8-2:1:9",
"value": [
{
"string": "c",
"raw_string": "c"
}
]
}
}
]
},
"primary": {},
"value": {}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,3:0:10-3:11:21",
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,3:0:10-3:2:12",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,3:0:10-3:2:12",
"value": [
{
"string": "**",
"raw_string": "**"
}
],
"pattern": [
"*",
"",
"*"
]
}
}
]
},
"primary": {},
"value": {
"suspension": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,3:4:14-3:11:21",
"value": true
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,4:0:22-4:22:44",
"edges": [
{
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,4:1:23-4:9:31",
"src": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,4:1:23-4:3:25",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,4:1:23-4:3:25",
"value": [
{
"string": "**",
"raw_string": "**"
}
],
"pattern": [
"*",
"",
"*"
]
}
}
]
},
"src_arrow": "",
"dst": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,4:7:29-4:9:31",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,4:7:29-4:9:31",
"value": [
{
"string": "**",
"raw_string": "**"
}
],
"pattern": [
"*",
"",
"*"
]
}
}
]
},
"dst_arrow": ">"
}
],
"edge_index": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,4:10:32-4:13:35",
"int": null,
"glob": true
},
"primary": {},
"value": {
"suspension": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,4:15:37-4:22:44",
"value": true
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,5:0:45-5:12:57",
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,5:0:45-5:1:46",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,5:0:45-5:1:46",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
}
]
},
"primary": {},
"value": {
"double_quoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,5:3:48-5:12:57",
"value": [
{
"string": "suspend",
"raw_string": "suspend"
}
]
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,6:0:58-6:17:75",
"edges": [
{
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,6:0:58-6:6:64",
"src": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,6:0:58-6:1:59",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,6:0:58-6:1:59",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
}
]
},
"src_arrow": "",
"dst": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,6:5:63-6:6:64",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,6:5:63-6:6:64",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
}
]
},
"dst_arrow": ">"
}
],
"primary": {},
"value": {
"double_quoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,6:8:66-6:17:75",
"value": [
{
"string": "suspend",
"raw_string": "suspend"
}
]
}
}
}
}
]
},
"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
},
{
"map_key_edge_index": 0
}
],
"attributes": {
"label": {
"value": "suspend"
},
"labelDimensions": {
"width": 0,
"height": 0
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": null
},
"zIndex": 0
}
],
"objects": [
{
"id": "d",
"id_val": "d",
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,5:0:45-5:1:46",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,5:0:45-5:1:46",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
},
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,6:0:58-6:1:59",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,6:0:58-6:1:59",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": 0
},
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,6:5:63-6:6:64",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-quotes.d2,6:5:63-6:6:64",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": 0
}
],
"attributes": {
"label": {
"value": "suspend"
},
"labelDimensions": {
"width": 0,
"height": 0
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": null
},
"zIndex": 0
}
]
},
"err": null
}