Merge pull request #428 from alixander/constraint
fix constraint keyword acting as label
This commit is contained in:
commit
427ecd6ad6
4 changed files with 191 additions and 1 deletions
|
|
@ -4,7 +4,9 @@
|
||||||
|
|
||||||
#### Bugfixes ⛑️
|
#### Bugfixes ⛑️
|
||||||
|
|
||||||
- Fixed crash when sequence diagrams had no messages
|
- Fixed crash when sequence diagrams had no messages.
|
||||||
[https://github.com/terrastruct/d2/pull/427](https://github.com/terrastruct/d2/pull/427)
|
[https://github.com/terrastruct/d2/pull/427](https://github.com/terrastruct/d2/pull/427)
|
||||||
|
- Fixed `constraint` keyword setting label.
|
||||||
|
[https://github.com/terrastruct/d2/issues/415](https://github.com/terrastruct/d2/issues/415)
|
||||||
- Fixed serialization affecting binary plugins (TALA).
|
- Fixed serialization affecting binary plugins (TALA).
|
||||||
[https://github.com/terrastruct/d2/pull/426](https://github.com/terrastruct/d2/pull/426)
|
[https://github.com/terrastruct/d2/pull/426](https://github.com/terrastruct/d2/pull/426)
|
||||||
|
|
|
||||||
|
|
@ -363,6 +363,9 @@ func (c *compiler) applyScalar(attrs *d2graph.Attributes, reserved string, box d
|
||||||
}
|
}
|
||||||
attrs.Direction.Value = scalar.ScalarString()
|
attrs.Direction.Value = scalar.ScalarString()
|
||||||
return
|
return
|
||||||
|
case "constraint":
|
||||||
|
// Compilation for shape-specific keywords happens elsewhere
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := d2graph.StyleKeywords[reserved]; ok {
|
if _, ok := d2graph.StyleKeywords[reserved]; ok {
|
||||||
|
|
|
||||||
|
|
@ -1618,6 +1618,17 @@ choo: {
|
||||||
assert.String(t, "left", g.Objects[0].Attributes.Direction.Value)
|
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",
|
name: "invalid_direction",
|
||||||
|
|
||||||
|
|
|
||||||
174
testdata/d2compiler/TestCompile/constraint_label.exp.json
generated
vendored
Normal file
174
testdata/d2compiler/TestCompile/constraint_label.exp.json
generated
vendored
Normal 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
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue