restrict near criteria
This commit is contained in:
parent
0cee21ecba
commit
9b409104fb
4 changed files with 63 additions and 0 deletions
|
|
@ -860,6 +860,23 @@ func (c *compiler) validateNear(g *d2graph.Graph) {
|
||||||
c.errorf(obj.Attributes.NearKey.GetRange().Start, obj.Attributes.NearKey.GetRange().End, "constant near keys can only be set on root level shapes")
|
c.errorf(obj.Attributes.NearKey.GetRange().Start, obj.Attributes.NearKey.GetRange().End, "constant near keys can only be set on root level shapes")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if !isKey && isConst && len(obj.ChildrenArray) > 0 {
|
||||||
|
c.errorf(obj.Attributes.NearKey.GetRange().Start, obj.Attributes.NearKey.GetRange().End, "constant near keys cannot be set on shapes with children")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !isKey && isConst {
|
||||||
|
is := false
|
||||||
|
for _, e := range g.Edges {
|
||||||
|
if e.Src == obj || e.Dst == obj {
|
||||||
|
is = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if is {
|
||||||
|
c.errorf(obj.Attributes.NearKey.GetRange().Start, obj.Attributes.NearKey.GetRange().End, "constant near keys cannot be set on connected shapes")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1278,6 +1278,28 @@ x -> y: {
|
||||||
text: `x.near: txop-center
|
text: `x.near: txop-center
|
||||||
`,
|
`,
|
||||||
expErr: `d2/testdata/d2compiler/TestCompile/near_bad_constant.d2:1:1: near key "txop-center" must be the absolute path to a shape or one of the following constants: top-left, top-center, top-right, center-left, center-right, bottom-left, bottom-center, bottom-right
|
expErr: `d2/testdata/d2compiler/TestCompile/near_bad_constant.d2:1:1: near key "txop-center" must be the absolute path to a shape or one of the following constants: top-left, top-center, top-right, center-left, center-right, bottom-left, bottom-center, bottom-right
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "near_bad_container",
|
||||||
|
|
||||||
|
text: `x: {
|
||||||
|
near: top-center
|
||||||
|
y
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
expErr: `d2/testdata/d2compiler/TestCompile/near_bad_container.d2:1:1: constant near keys cannot be set on shapes with children
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "near_bad_connected",
|
||||||
|
|
||||||
|
text: `x: {
|
||||||
|
near: top-center
|
||||||
|
}
|
||||||
|
x -> y
|
||||||
|
`,
|
||||||
|
expErr: `d2/testdata/d2compiler/TestCompile/near_bad_connected.d2:1:1: constant near keys cannot be set on connected shapes
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
12
testdata/d2compiler/TestCompile/near_bad_connected.exp.json
generated
vendored
Normal file
12
testdata/d2compiler/TestCompile/near_bad_connected.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"graph": null,
|
||||||
|
"err": {
|
||||||
|
"ioerr": null,
|
||||||
|
"errs": [
|
||||||
|
{
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/near_bad_connected.d2,0:0:0-0:10:10",
|
||||||
|
"errmsg": "d2/testdata/d2compiler/TestCompile/near_bad_connected.d2:1:1: constant near keys cannot be set on connected shapes"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
12
testdata/d2compiler/TestCompile/near_bad_container.exp.json
generated
vendored
Normal file
12
testdata/d2compiler/TestCompile/near_bad_container.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"graph": null,
|
||||||
|
"err": {
|
||||||
|
"ioerr": null,
|
||||||
|
"errs": [
|
||||||
|
{
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/near_bad_container.d2,0:0:0-0:10:10",
|
||||||
|
"errmsg": "d2/testdata/d2compiler/TestCompile/near_bad_container.d2:1:1: constant near keys cannot be set on shapes with children"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue