Merge pull request #762 from alixander/sequence-panic-2
todo: fix sequence diagram panic
This commit is contained in:
commit
2af6681c7d
3 changed files with 27 additions and 4 deletions
|
|
@ -476,12 +476,12 @@ func (sd *sequenceDiagram) routeMessages() error {
|
|||
if startCenter := getCenter(message.Src); startCenter != nil {
|
||||
startX = startCenter.X
|
||||
} else {
|
||||
return fmt.Errorf("could not find center of %s", message.Src.AbsID())
|
||||
return fmt.Errorf("could not find center of %s. Is it declared as an actor?", message.Src.ID)
|
||||
}
|
||||
if endCenter := getCenter(message.Dst); endCenter != nil {
|
||||
endX = endCenter.X
|
||||
} else {
|
||||
return fmt.Errorf("could not find center of %s", message.Dst.AbsID())
|
||||
return fmt.Errorf("could not find center of %s. Is it declared as an actor?", message.Dst.ID)
|
||||
}
|
||||
isToDescendant := strings.HasPrefix(message.Dst.AbsID(), message.Src.AbsID()+".")
|
||||
isFromDescendant := strings.HasPrefix(message.Src.AbsID(), message.Dst.AbsID()+".")
|
||||
|
|
@ -526,7 +526,7 @@ func (sd *sequenceDiagram) routeMessages() error {
|
|||
func getCenter(obj *d2graph.Object) *geo.Point {
|
||||
if obj == nil {
|
||||
return nil
|
||||
} else if obj.TopLeft != nil {
|
||||
} else if obj.Box != nil && obj.Box.TopLeft != nil {
|
||||
return obj.Center()
|
||||
}
|
||||
return getCenter(obj.Parent)
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ type testCase struct {
|
|||
mtexts []*d2target.MText
|
||||
assertions func(t *testing.T, diagram *d2target.Diagram)
|
||||
skip bool
|
||||
expErr string
|
||||
}
|
||||
|
||||
func runa(t *testing.T, tcs []testCase) {
|
||||
|
|
@ -148,7 +149,14 @@ func run(t *testing.T, tc testCase) {
|
|||
ThemeID: 0,
|
||||
Layout: layout,
|
||||
})
|
||||
trequire.Nil(t, err)
|
||||
|
||||
if tc.expErr != "" {
|
||||
assert.Error(t, err)
|
||||
assert.ErrorString(t, err, tc.expErr)
|
||||
return
|
||||
} else {
|
||||
assert.Success(t, err)
|
||||
}
|
||||
|
||||
if tc.assertions != nil {
|
||||
t.Run("assertions", func(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -467,6 +467,21 @@ class2: class without rows {
|
|||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "sequence-panic",
|
||||
script: `
|
||||
shape: sequence_diagram
|
||||
|
||||
a
|
||||
|
||||
group: {
|
||||
inner_group: {
|
||||
a -> b
|
||||
}
|
||||
}
|
||||
`,
|
||||
expErr: "could not find center of b. Is it declared as an actor?",
|
||||
},
|
||||
}
|
||||
|
||||
runa(t, tcs)
|
||||
|
|
|
|||
Loading…
Reference in a new issue