fix constraint keyword

This commit is contained in:
Alexander Wang 2022-12-11 16:46:09 -08:00
parent 2ac363d404
commit 794e864988
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
3 changed files with 188 additions and 0 deletions

View file

@ -363,6 +363,9 @@ func (c *compiler) applyScalar(attrs *d2graph.Attributes, reserved string, box d
}
attrs.Direction.Value = scalar.ScalarString()
return
case "constraint":
// Compilation for shape-specific keywords happens elsewhere
return
}
if _, ok := d2graph.StyleKeywords[reserved]; ok {

View file

@ -1618,6 +1618,17 @@ choo: {
assert.String(t, "left", g.Objects[0].Attributes.Direction.Value)
},
},
{
name: "constraint_label",
text: `foo {
label: bar
constraint: BIZ
}`,
assertions: func(t *testing.T, g *d2graph.Graph) {
assert.String(t, "bar", g.Objects[0].Attributes.Label.Value)
},
},
{
name: "invalid_direction",

View file

@ -0,0 +1,174 @@
{
"graph": {
"ast": {
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,0:0:0-3:1:38",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,0:0:0-3:1:38",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,0:0:0-0:4:4",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,0:0:0-0:3:3",
"value": [
{
"string": "foo",
"raw_string": "foo"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,0:4:4-3:0:37",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,1:2:8-1:12:18",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,1:2:8-1:7:13",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,1:2:8-1:7:13",
"value": [
{
"string": "label",
"raw_string": "label"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,1:9:15-1:12:18",
"value": [
{
"string": "bar",
"raw_string": "bar"
}
]
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,2:2:21-2:17:36",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,2:2:21-2:12:31",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,2:2:21-2:12:31",
"value": [
{
"string": "constraint",
"raw_string": "constraint"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,2:14:33-2:17:36",
"value": [
{
"string": "BIZ",
"raw_string": "BIZ"
}
]
}
}
}
}
]
}
}
}
}
]
},
"root": {
"id": "",
"id_val": "",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": ""
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
}
},
"zIndex": 0
},
"edges": null,
"objects": [
{
"id": "foo",
"id_val": "foo",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,0:0:0-0:4:4",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/constraint_label.d2,0:0:0-0:3:3",
"value": [
{
"string": "foo",
"raw_string": "foo"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": 0
}
],
"attributes": {
"label": {
"value": "bar"
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
}
},
"zIndex": 0
}
]
},
"err": null
}