From 273496bc9e80fb0dffa3240ac0cef063592773af Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 7 Feb 2023 20:47:12 -0800 Subject: [PATCH] add experr --- d2layouts/d2sequence/sequence_diagram.go | 6 +- e2etests/e2e_test.go | 10 +- e2etests/regression_test.go | 1 + .../sequence-panic/dagre/board.exp.json | 363 +++++++++--------- .../sequence-panic/dagre/sketch.exp.svg | 8 +- .../sequence-panic/elk/board.exp.json | 363 +++++++++--------- .../sequence-panic/elk/sketch.exp.svg | 8 +- 7 files changed, 387 insertions(+), 372 deletions(-) diff --git a/d2layouts/d2sequence/sequence_diagram.go b/d2layouts/d2sequence/sequence_diagram.go index 8a61e9e8b..b2cbc5481 100644 --- a/d2layouts/d2sequence/sequence_diagram.go +++ b/d2layouts/d2sequence/sequence_diagram.go @@ -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) diff --git a/e2etests/e2e_test.go b/e2etests/e2e_test.go index b1ac13cc8..41ad5498d 100644 --- a/e2etests/e2e_test.go +++ b/e2etests/e2e_test.go @@ -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) { diff --git a/e2etests/regression_test.go b/e2etests/regression_test.go index 24e5f52ad..1e8ff5d13 100644 --- a/e2etests/regression_test.go +++ b/e2etests/regression_test.go @@ -486,6 +486,7 @@ group: { } } `, + expErr: "could not find center of b. Is it declared as an actor?", }, } diff --git a/e2etests/testdata/regression/sequence-panic/dagre/board.exp.json b/e2etests/testdata/regression/sequence-panic/dagre/board.exp.json index 8f284a7bd..6501618e9 100644 --- a/e2etests/testdata/regression/sequence-panic/dagre/board.exp.json +++ b/e2etests/testdata/regression/sequence-panic/dagre/board.exp.json @@ -3,13 +3,177 @@ "fontFamily": "SourceSansPro", "shapes": [ { - "id": "handler", + "id": "a", "type": "rectangle", "pos": { "x": 24, "y": 74 }, - "width": 227, + "width": 150, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "a", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 7, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "group", + "type": "rectangle", + "pos": { + "x": 25, + "y": 206 + }, + "width": 0, + "height": 0, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 0, + "borderRadius": 0, + "fill": "#DEE1EB", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": true, + "fields": null, + "methods": null, + "columns": null, + "label": "group", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 40, + "labelHeight": 21, + "labelPosition": "INSIDE_TOP_LEFT", + "zIndex": 3, + "level": 1 + }, + { + "id": "group.inner_group", + "type": "rectangle", + "pos": { + "x": 49, + "y": 230 + }, + "width": 0, + "height": 0, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#E3E9FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "inner_group", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 82, + "labelHeight": 21, + "labelPosition": "INSIDE_TOP_LEFT", + "zIndex": 3, + "level": 2 + }, + { + "id": "group.inner_group.b", + "type": "rectangle", + "pos": { + "x": 9223372036854775807, + "y": 9223372036854775807 + }, + "width": -9223372036854775808, + "height": -9223372036854775808, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "b", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_TOP_LEFT", + "zIndex": 3, + "level": 3 + }, + { + "id": "b", + "type": "rectangle", + "pos": { + "x": 274, + "y": 74 + }, + "width": 150, "height": 66, "opacity": 1, "strokeDash": 0, @@ -29,7 +193,7 @@ "fields": null, "methods": null, "columns": null, - "label": "handlers (handler function)", + "label": "b", "fontSize": 16, "fontFamily": "DEFAULT", "language": "", @@ -37,142 +201,20 @@ "italic": false, "bold": false, "underline": false, - "labelWidth": 182, + "labelWidth": 8, "labelHeight": 21, "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 1 - }, - { - "id": "db", - "type": "rectangle", - "pos": { - "x": 313, - "y": 74 - }, - "width": 150, - "height": 66, - "opacity": 1, - "strokeDash": 0, - "strokeWidth": 2, - "borderRadius": 0, - "fill": "#EDF0FD", - "stroke": "#0D32B2", - "shadow": false, - "3d": false, - "multiple": false, - "double-border": false, - "tooltip": "", - "link": "", - "icon": null, - "iconPosition": "", - "blend": false, - "fields": null, - "methods": null, - "columns": null, - "label": "db", - "fontSize": 16, - "fontFamily": "DEFAULT", - "language": "", - "color": "#0A0F25", - "italic": false, - "bold": false, - "underline": false, - "labelWidth": 18, - "labelHeight": 21, - "labelPosition": "INSIDE_MIDDLE_CENTER", - "zIndex": 0, - "level": 1 - }, - { - "id": "HTTP request", - "type": "rectangle", - "pos": { - "x": 563, - "y": 74 - }, - "width": 150, - "height": 66, - "opacity": 1, - "strokeDash": 0, - "strokeWidth": 2, - "borderRadius": 0, - "fill": "#EDF0FD", - "stroke": "#0D32B2", - "shadow": false, - "3d": false, - "multiple": false, - "double-border": false, - "tooltip": "", - "link": "", - "icon": null, - "iconPosition": "", - "blend": false, - "fields": null, - "methods": null, - "columns": null, - "label": "HTTP request", - "fontSize": 16, - "fontFamily": "DEFAULT", - "language": "", - "color": "#0A0F25", - "italic": false, - "bold": false, - "underline": false, - "labelWidth": 91, - "labelHeight": 21, - "labelPosition": "INSIDE_MIDDLE_CENTER", - "zIndex": 0, - "level": 1 - }, - { - "id": "HTTP request.handlers", - "type": "rectangle", - "pos": { - "x": 632, - "y": 254 - }, - "width": 12, - "height": 80, - "opacity": 1, - "strokeDash": 0, - "strokeWidth": 2, - "borderRadius": 0, - "fill": "#E3E9FD", - "stroke": "#0D32B2", - "shadow": false, - "3d": false, - "multiple": false, - "double-border": false, - "tooltip": "", - "link": "", - "icon": null, - "iconPosition": "", - "blend": false, - "fields": null, - "methods": null, - "columns": null, - "label": "", - "fontSize": 16, - "fontFamily": "DEFAULT", - "language": "", - "color": "#0A0F25", - "italic": false, - "bold": false, - "underline": false, - "labelWidth": 58, - "labelHeight": 21, - "zIndex": 2, - "level": 2 } ], "connections": [ { - "id": "(HTTP request.handlers -> db)[0]", - "src": "HTTP request.handlers", + "id": "(a -> b)[0]", + "src": "a", "srcArrow": "none", "srcLabel": "", - "dst": "db", + "dst": "b", "dstArrow": "triangle", "dstLabel": "", "opacity": 1, @@ -193,11 +235,11 @@ "labelPercentage": 0, "route": [ { - "x": 632, + "x": 99, "y": 270 }, { - "x": 388, + "x": 349, "y": 270 } ], @@ -207,11 +249,11 @@ "zIndex": 4 }, { - "id": "(handler -- )[0]", - "src": "handler", + "id": "(a -- )[0]", + "src": "a", "srcArrow": "none", "srcLabel": "", - "dst": "handler-lifeline-end-2166861706", + "dst": "a-lifeline-end-2251863791", "dstArrow": "none", "dstLabel": "", "opacity": 1, @@ -232,11 +274,11 @@ "labelPercentage": 0, "route": [ { - "x": 137.5, + "x": 99, "y": 140 }, { - "x": 137.5, + "x": 99, "y": 400 } ], @@ -246,11 +288,11 @@ "zIndex": 1 }, { - "id": "(db -- )[0]", - "src": "db", + "id": "(b -- )[0]", + "src": "b", "srcArrow": "none", "srcLabel": "", - "dst": "db-lifeline-end-2675250554", + "dst": "b-lifeline-end-668380428", "dstArrow": "none", "dstLabel": "", "opacity": 1, @@ -271,50 +313,11 @@ "labelPercentage": 0, "route": [ { - "x": 388, + "x": 349, "y": 140 }, { - "x": 388, - "y": 400 - } - ], - "animated": false, - "tooltip": "", - "icon": null, - "zIndex": 1 - }, - { - "id": "(HTTP request -- )[0]", - "src": "HTTP request", - "srcArrow": "none", - "srcLabel": "", - "dst": "HTTP request-lifeline-end-1968028819", - "dstArrow": "none", - "dstLabel": "", - "opacity": 1, - "strokeDash": 6, - "strokeWidth": 2, - "stroke": "#0D32B2", - "label": "", - "fontSize": 16, - "fontFamily": "DEFAULT", - "language": "", - "color": "#676C7E", - "italic": true, - "bold": false, - "underline": false, - "labelWidth": 0, - "labelHeight": 0, - "labelPosition": "", - "labelPercentage": 0, - "route": [ - { - "x": 638, - "y": 140 - }, - { - "x": 638, + "x": 349, "y": 400 } ], diff --git a/e2etests/testdata/regression/sequence-panic/dagre/sketch.exp.svg b/e2etests/testdata/regression/sequence-panic/dagre/sketch.exp.svg index 078c1b080..02d7974b8 100644 --- a/e2etests/testdata/regression/sequence-panic/dagre/sketch.exp.svg +++ b/e2etests/testdata/regression/sequence-panic/dagre/sketch.exp.svg @@ -3,7 +3,7 @@ id="d2-svg" style="background: white;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" -width="893" height="528" viewBox="-78 -28 893 528">