Merge pull request #334 from alixander/sequence-safety
prevent illegal sequence diagram connection
This commit is contained in:
commit
9108ce8418
3 changed files with 38 additions and 0 deletions
|
|
@ -1520,6 +1520,18 @@ dst.id <-> src.dst_id
|
||||||
assert.String(t, "sequence_diagram", g.Root.Attributes.Shape.Value)
|
assert.String(t, "sequence_diagram", g.Root.Attributes.Shape.Value)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "leaky_sequence",
|
||||||
|
|
||||||
|
text: `x: {
|
||||||
|
shape: sequence_diagram
|
||||||
|
a
|
||||||
|
}
|
||||||
|
b -> x.a
|
||||||
|
`,
|
||||||
|
expErr: `d2/testdata/d2compiler/TestCompile/leaky_sequence.d2:5:1: connections within sequence diagrams can connect only to other objects within the same sequence diagram
|
||||||
|
`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "root_direction",
|
name: "root_direction",
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -711,6 +711,16 @@ func (e *Edge) AbsID() string {
|
||||||
return fmt.Sprintf("%s(%s %s %s)[%d]", commonKey, strings.Join(srcIDA, "."), e.ArrowString(), strings.Join(dstIDA, "."), e.Index)
|
return fmt.Sprintf("%s(%s %s %s)[%d]", commonKey, strings.Join(srcIDA, "."), e.ArrowString(), strings.Join(dstIDA, "."), e.Index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (obj *Object) outerSequenceDiagram() *Object {
|
||||||
|
for obj != nil {
|
||||||
|
obj = obj.Parent
|
||||||
|
if obj.IsSequenceDiagram() {
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (obj *Object) Connect(srcID, dstID []string, srcArrow, dstArrow bool, label string) (*Edge, error) {
|
func (obj *Object) Connect(srcID, dstID []string, srcArrow, dstArrow bool, label string) (*Edge, error) {
|
||||||
srcObj, srcID, err := ResolveUnderscoreKey(srcID, obj)
|
srcObj, srcID, err := ResolveUnderscoreKey(srcID, obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -732,6 +742,10 @@ func (obj *Object) Connect(srcID, dstID []string, srcArrow, dstArrow bool, label
|
||||||
src := srcObj.EnsureChild(srcID)
|
src := srcObj.EnsureChild(srcID)
|
||||||
dst := dstObj.EnsureChild(dstID)
|
dst := dstObj.EnsureChild(dstID)
|
||||||
|
|
||||||
|
if src.outerSequenceDiagram() != dst.outerSequenceDiagram() {
|
||||||
|
return nil, errors.New("connections within sequence diagrams can connect only to other objects within the same sequence diagram")
|
||||||
|
}
|
||||||
|
|
||||||
edge := &Edge{
|
edge := &Edge{
|
||||||
Attributes: Attributes{
|
Attributes: Attributes{
|
||||||
Label: Scalar{
|
Label: Scalar{
|
||||||
|
|
|
||||||
12
testdata/d2compiler/TestCompile/leaky_sequence.exp.json
generated
vendored
Normal file
12
testdata/d2compiler/TestCompile/leaky_sequence.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"graph": null,
|
||||||
|
"err": {
|
||||||
|
"ioerr": null,
|
||||||
|
"errs": [
|
||||||
|
{
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/leaky_sequence.d2,4:0:36-4:8:44",
|
||||||
|
"errmsg": "d2/testdata/d2compiler/TestCompile/leaky_sequence.d2:5:1: connections within sequence diagrams can only connect to other objects within the same sequence diagram"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue