save
This commit is contained in:
parent
8e074070d8
commit
5c96ffe6a1
4 changed files with 1147 additions and 10 deletions
|
|
@ -56,7 +56,7 @@ func compileIR(ast *d2ast.Map, m *d2ir.Map) (*d2graph.Graph, error) {
|
||||||
if len(c.err.Errors) > 0 {
|
if len(c.err.Errors) > 0 {
|
||||||
return nil, c.err
|
return nil, c.err
|
||||||
}
|
}
|
||||||
c.compileBoardLink(g, m)
|
c.compileBoardLink(g)
|
||||||
if len(c.err.Errors) > 0 {
|
if len(c.err.Errors) > 0 {
|
||||||
return nil, c.err
|
return nil, c.err
|
||||||
}
|
}
|
||||||
|
|
@ -722,7 +722,7 @@ func (c *compiler) validateNear(g *d2graph.Graph) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *compiler) compileBoardLink(g *d2graph.Graph, ir *d2ir.Map) {
|
func (c *compiler) compileBoardLink(g *d2graph.Graph) {
|
||||||
for _, obj := range g.Objects {
|
for _, obj := range g.Objects {
|
||||||
if obj.Attributes.Link == nil {
|
if obj.Attributes.Link == nil {
|
||||||
continue
|
continue
|
||||||
|
|
@ -735,24 +735,34 @@ func (c *compiler) compileBoardLink(g *d2graph.Graph, ir *d2ir.Map) {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch linkKey.Path[0].Unbox().ScalarString() {
|
switch linkKey.Path[0].Unbox().ScalarString() {
|
||||||
// TODO underscore
|
// Starting a link with one of the following means it is targeting a board
|
||||||
case "layers", "scenarios", "steps":
|
case "layers", "scenarios", "steps", "_":
|
||||||
default:
|
default:
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.LinkedBoard = c.findBoard(g, ir, linkKey.IDA())
|
obj.LinkedBoard = c.findBoard(g, linkKey.IDA())
|
||||||
|
|
||||||
if obj.LinkedBoard == nil {
|
if obj.LinkedBoard == nil {
|
||||||
c.errorf(obj.Attributes.Link.MapKey, "link key %#v to board not found", obj.Attributes.Link.Value)
|
c.errorf(obj.Attributes.Link.MapKey, "link key %#v to board not found", obj.Attributes.Link.Value)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for _, b := range append(append(g.Layers, g.Scenarios...), g.Steps...) {
|
||||||
|
c.compileBoardLink(b)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *compiler) findBoard(g *d2graph.Graph, ir *d2ir.Map, ida []string) *d2graph.Graph {
|
func (c *compiler) findBoard(g *d2graph.Graph, ida []string) *d2graph.Graph {
|
||||||
var currType string
|
var currType string
|
||||||
for _, p := range ida {
|
for _, p := range ida {
|
||||||
|
if g == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if p == "_" {
|
||||||
|
g = g.Parent
|
||||||
|
continue
|
||||||
|
}
|
||||||
switch p {
|
switch p {
|
||||||
case "layers", "scenarios", "steps":
|
case "layers", "scenarios", "steps":
|
||||||
currType = p
|
currType = p
|
||||||
|
|
@ -779,10 +789,6 @@ func (c *compiler) findBoard(g *d2graph.Graph, ir *d2ir.Map, ida []string) *d2gr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if board == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
g = board
|
g = board
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2092,6 +2092,41 @@ layers: {
|
||||||
tassert.Equal(t, ".layers.x.layers.x", g.Objects[0].LinkedBoard.AbsID())
|
tassert.Equal(t, ".layers.x.layers.x", g.Objects[0].LinkedBoard.AbsID())
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "link-board-underscore",
|
||||||
|
text: `x
|
||||||
|
layers: {
|
||||||
|
x: {
|
||||||
|
yo
|
||||||
|
layers: {
|
||||||
|
x: {
|
||||||
|
hello.link: _._.layers.x
|
||||||
|
hey.link: _
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
assertions: func(t *testing.T, g *d2graph.Graph) {
|
||||||
|
tassert.NotNil(t, g.Layers[0].Layers[0].Objects[0].LinkedBoard)
|
||||||
|
tassert.Equal(t, ".layers.x", g.Layers[0].Layers[0].Objects[0].LinkedBoard.AbsID())
|
||||||
|
tassert.Equal(t, ".layers.x", g.Layers[0].Layers[0].Objects[1].LinkedBoard.AbsID())
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "link-board-underscore-not-found",
|
||||||
|
text: `x
|
||||||
|
layers: {
|
||||||
|
x: {
|
||||||
|
yo
|
||||||
|
layers: {
|
||||||
|
x: {
|
||||||
|
hello.link: _._._
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
expErr: `d2/testdata/d2compiler/TestCompile/link-board-underscore-not-found.d2:7:17: link key "_._._" to board not found`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
|
|
||||||
12
testdata/d2compiler/TestCompile/link-board-underscore-not-found.exp.json
generated
vendored
Normal file
12
testdata/d2compiler/TestCompile/link-board-underscore-not-found.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"graph": null,
|
||||||
|
"err": {
|
||||||
|
"ioerr": null,
|
||||||
|
"errs": [
|
||||||
|
{
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore-not-found.d2,6:16:62-6:21:67",
|
||||||
|
"errmsg": "d2/testdata/d2compiler/TestCompile/link-board-underscore-not-found.d2:7:17: link key \"_._._\" to board not found"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
1084
testdata/d2compiler/TestCompile/link-board-underscore.exp.json
generated
vendored
Normal file
1084
testdata/d2compiler/TestCompile/link-board-underscore.exp.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue