update grid edge validation and test
This commit is contained in:
parent
bb79c30fd8
commit
a43aae9d1a
2 changed files with 45 additions and 20 deletions
|
|
@ -1098,29 +1098,42 @@ func (c *compiler) validateEdges(g *d2graph.Graph) {
|
|||
c.errorf(edge.GetAstEdge(), "edges into grid diagrams are not supported yet")
|
||||
continue
|
||||
}
|
||||
|
||||
// edges within a grid cell are ok now
|
||||
// grid.cell.a -> grid.cell.b : ok
|
||||
// grid.cell.a.c -> grid.cell.b.d : ok
|
||||
// edges between grid cells themselves are ok
|
||||
// grid.cell -> grid.cell2 : ok
|
||||
// grid.cell -> grid.cell.inside : not ok
|
||||
// grid.cell -> grid.cell2.inside : not ok
|
||||
srcIsGridCell := edge.Src.Parent.IsGridDiagram()
|
||||
dstIsGridCell := edge.Dst.Parent.IsGridDiagram()
|
||||
// if srcIsGridCell && dstIsGridCell {
|
||||
// if edge.Src.Parent != edge.Dst.Parent {
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
if srcIsGridCell != dstIsGridCell {
|
||||
if srcIsGridCell {
|
||||
c.errorf(edge.GetAstEdge(), "grid cell %#v can only connect to another grid cell", edge.Src.AbsID())
|
||||
} else {
|
||||
c.errorf(edge.GetAstEdge(), "grid cell %#v can only connect to another grid cell", edge.Dst.AbsID())
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// edges within a grid cell are ok now
|
||||
// edges between grid cells are ok now
|
||||
// edges from a grid to something outside is ok
|
||||
// but edges from a grid cell must be to another grid cell
|
||||
|
||||
// TODO
|
||||
// grid -> outside : ok
|
||||
// grid -> grid.cell : not ok
|
||||
// grid.cell -> grid.cell2 : ok
|
||||
// grid.cell -> grid.cell2.inside : not ok
|
||||
|
||||
if edge.Src.IsGridDiagram() {
|
||||
// TODO
|
||||
c.errorf(edge.GetAstEdge(), "edges from grid diagram must be external")
|
||||
continue
|
||||
}
|
||||
if edge.Dst.IsGridDiagram() {
|
||||
// TODO
|
||||
c.errorf(edge.GetAstEdge(), "edges from grid diagram must be external")
|
||||
// grid -> outside : ok
|
||||
// grid -> grid.cell : not ok
|
||||
// grid -> grid.cell.inner : not ok
|
||||
if (edge.Src.IsGridDiagram() && edge.Dst.IsDescendantOf(edge.Src)) ||
|
||||
(edge.Dst.IsGridDiagram() && edge.Src.IsDescendantOf(edge.Dst)) {
|
||||
c.errorf(edge.GetAstEdge(), "edges from grid diagram container must be external")
|
||||
continue
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2495,17 +2495,29 @@ d2/testdata/d2compiler/TestCompile/grid_edge.d2:7:2: edges into grid diagrams ar
|
|||
a -> b: ok
|
||||
b: {
|
||||
c -> d: ok now
|
||||
c.e -> c.f.g: ok
|
||||
c.e -> d.h: ok
|
||||
c -> d.h: ok
|
||||
}
|
||||
a: {
|
||||
grid-columns: 1
|
||||
e -> f: also ok now
|
||||
e: {
|
||||
g -> h: ok
|
||||
g -> h.h: ok
|
||||
}
|
||||
e -> f.i: not ok
|
||||
e.g -> f.i: not ok
|
||||
}
|
||||
a -> b.c: not yet
|
||||
a.e -> b.c: also not yet
|
||||
}
|
||||
`,
|
||||
expErr: `d2/testdata/d2compiler/TestCompile/grid_deeper_edge.d2:11:2: edges from grid diagram must be external
|
||||
d2/testdata/d2compiler/TestCompile/grid_deeper_edge.d2:12:2: edges into grid diagrams are not supported yet`,
|
||||
expErr: `
|
||||
d2/testdata/d2compiler/TestCompile/grid_deeper_edge.d2:17:3: grid cell "hey.a.e" can only connect to another grid cell
|
||||
d2/testdata/d2compiler/TestCompile/grid_deeper_edge.d2:18:2: edge cannot go outside of grid cell "hey.a.e"
|
||||
d2/testdata/d2compiler/TestCompile/grid_deeper_edge.d2:20:2: grid cell "hey.a" can only connect to another grid cell
|
||||
d2/testdata/d2compiler/TestCompile/grid_deeper_edge.d2:21:2: edges into grid diagrams are not supported yet`,
|
||||
},
|
||||
{
|
||||
name: "grid_nested",
|
||||
|
|
|
|||
Loading…
Reference in a new issue