fix empty file

This commit is contained in:
Alexander Wang 2022-12-05 09:48:38 -08:00
parent de3c0518f5
commit fff6637a03
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
6 changed files with 58 additions and 8 deletions

View file

@ -35,15 +35,17 @@ func Compile(ctx context.Context, input string, opts *CompileOptions) (*d2target
return nil, nil, err
}
err = g.SetDimensions(opts.MeasuredTexts, opts.Ruler)
if err != nil {
return nil, nil, err
}
if len(g.Objects) > 0 {
err = g.SetDimensions(opts.MeasuredTexts, opts.Ruler)
if err != nil {
return nil, nil, err
}
if layout, err := getLayout(opts); err != nil {
return nil, nil, err
} else if err := d2sequence.Layout(ctx, g, layout); err != nil {
return nil, nil, err
if layout, err := getLayout(opts); err != nil {
return nil, nil, err
} else if err := d2sequence.Layout(ctx, g, layout); err != nil {
return nil, nil, err
}
}
diagram, err := d2exporter.Export(ctx, g, opts.ThemeID)

View file

@ -38,6 +38,10 @@ func TestE2E(t *testing.T) {
func testSanity(t *testing.T) {
tcs := []testCase{
{
name: "empty",
script: ``,
},
{
name: "basic",
script: `a -> b

5
e2etests/testdata/sanity/empty/dagre/board.exp.json generated vendored Normal file
View file

@ -0,0 +1,5 @@
{
"name": "",
"shapes": [],
"connections": []
}

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<svg
style="background: white;"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
width="202" height="202" viewBox="9223372036854775707 9223372036854775707 202 202"><style type="text/css">
<![CDATA[
.shape {
shape-rendering: geometricPrecision;
stroke-linejoin: round;
}
.connection {
stroke-linecap: round;
stroke-linejoin: round;
}
]]>
</style><style type="text/css"><![CDATA[]]></style></svg>

After

Width:  |  Height:  |  Size: 471 B

5
e2etests/testdata/sanity/empty/elk/board.exp.json generated vendored Normal file
View file

@ -0,0 +1,5 @@
{
"name": "",
"shapes": [],
"connections": []
}

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<svg
style="background: white;"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
width="202" height="202" viewBox="9223372036854775707 9223372036854775707 202 202"><style type="text/css">
<![CDATA[
.shape {
shape-rendering: geometricPrecision;
stroke-linejoin: round;
}
.connection {
stroke-linecap: round;
stroke-linejoin: round;
}
]]>
</style><style type="text/css"><![CDATA[]]></style></svg>

After

Width:  |  Height:  |  Size: 471 B