validate position keywords
This commit is contained in:
parent
fcb0678abb
commit
4ffe2409a7
3 changed files with 48 additions and 0 deletions
|
|
@ -90,6 +90,7 @@ func (c *compiler) compileBoard(g *d2graph.Graph, ir *d2ir.Map) *d2graph.Graph {
|
||||||
c.validateLabels(g)
|
c.validateLabels(g)
|
||||||
c.validateNear(g)
|
c.validateNear(g)
|
||||||
c.validateEdges(g)
|
c.validateEdges(g)
|
||||||
|
c.validatePositionsCompatibility(g)
|
||||||
|
|
||||||
c.compileBoardsField(g, ir, "layers")
|
c.compileBoardsField(g, ir, "layers")
|
||||||
c.compileBoardsField(g, ir, "scenarios")
|
c.compileBoardsField(g, ir, "scenarios")
|
||||||
|
|
@ -1130,6 +1131,26 @@ func (c *compiler) validateNear(g *d2graph.Graph) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *compiler) validatePositionsCompatibility(g *d2graph.Graph) {
|
||||||
|
for _, o := range g.Objects {
|
||||||
|
for _, pos := range []*d2graph.Scalar{o.Top, o.Left} {
|
||||||
|
if pos != nil {
|
||||||
|
if o.Parent != nil {
|
||||||
|
if strings.EqualFold(o.Parent.Shape.Value, d2target.ShapeHierarchy) {
|
||||||
|
c.errorf(pos.MapKey, `position keywords cannot be used with shape "hierarchy"`)
|
||||||
|
}
|
||||||
|
if o.OuterSequenceDiagram() != nil {
|
||||||
|
c.errorf(pos.MapKey, `position keywords cannot be used inside shape "sequence_diagram"`)
|
||||||
|
}
|
||||||
|
if o.Parent.GridColumns != nil || o.Parent.GridRows != nil {
|
||||||
|
c.errorf(pos.MapKey, `position keywords cannot be used with grids`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *compiler) validateEdges(g *d2graph.Graph) {
|
func (c *compiler) validateEdges(g *d2graph.Graph) {
|
||||||
for _, edge := range g.Edges {
|
for _, edge := range g.Edges {
|
||||||
// edges from a grid to something outside is ok
|
// edges from a grid to something outside is ok
|
||||||
|
|
|
||||||
|
|
@ -2856,6 +2856,18 @@ d2/testdata/d2compiler/TestCompile/no_arrowheads_in_shape.d2:2:3: "source-arrowh
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "fixed-pos-shape-hierarchy",
|
||||||
|
text: `x: {
|
||||||
|
shape: hierarchy
|
||||||
|
a -> b
|
||||||
|
a.top: 20
|
||||||
|
a.left: 20
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
expErr: `d2/testdata/d2compiler/TestCompile/fixed-pos-shape-hierarchy.d2:4:2: position keywords cannot be used with shape "hierarchy"
|
||||||
|
d2/testdata/d2compiler/TestCompile/fixed-pos-shape-hierarchy.d2:5:2: position keywords cannot be used with shape "hierarchy"`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
|
|
||||||
15
testdata/d2compiler/TestCompile/fixed-pos-shape-hierarchy.exp.json
generated
vendored
Normal file
15
testdata/d2compiler/TestCompile/fixed-pos-shape-hierarchy.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"graph": null,
|
||||||
|
"err": {
|
||||||
|
"errs": [
|
||||||
|
{
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/fixed-pos-shape-hierarchy.d2,3:1:34-3:10:43",
|
||||||
|
"errmsg": "d2/testdata/d2compiler/TestCompile/fixed-pos-shape-hierarchy.d2:4:2: position keywords cannot be used with shape \"hierarchy\""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/fixed-pos-shape-hierarchy.d2,4:1:45-4:11:55",
|
||||||
|
"errmsg": "d2/testdata/d2compiler/TestCompile/fixed-pos-shape-hierarchy.d2:5:2: position keywords cannot be used with shape \"hierarchy\""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue