e2e test with serialization
This commit is contained in:
parent
74904a4729
commit
bd16b04244
3 changed files with 42 additions and 2 deletions
|
|
@ -79,6 +79,7 @@ type testCase struct {
|
||||||
name string
|
name string
|
||||||
// if the test is just testing a render/style thing, no need to exercise both engines
|
// if the test is just testing a render/style thing, no need to exercise both engines
|
||||||
justDagre bool
|
justDagre bool
|
||||||
|
testSerialization bool
|
||||||
script string
|
script string
|
||||||
mtexts []*d2target.MText
|
mtexts []*d2target.MText
|
||||||
assertions func(t *testing.T, diagram *d2target.Diagram)
|
assertions func(t *testing.T, diagram *d2target.Diagram)
|
||||||
|
|
@ -142,10 +143,32 @@ func run(t *testing.T, tc testCase) {
|
||||||
}
|
}
|
||||||
|
|
||||||
layoutResolver := func(engine string) (d2graph.LayoutGraph, error) {
|
layoutResolver := func(engine string) (d2graph.LayoutGraph, error) {
|
||||||
|
layout := d2dagrelayout.DefaultLayout
|
||||||
if strings.EqualFold(engine, "elk") {
|
if strings.EqualFold(engine, "elk") {
|
||||||
return d2elklayout.DefaultLayout, nil
|
layout = d2elklayout.DefaultLayout
|
||||||
}
|
}
|
||||||
return d2dagrelayout.DefaultLayout, nil
|
if tc.testSerialization {
|
||||||
|
return func(ctx context.Context, g *d2graph.Graph) error {
|
||||||
|
bytes, err := d2graph.SerializeGraph(g)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = d2graph.DeserializeGraph(bytes, g)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = layout(ctx, g)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
bytes, err = d2graph.SerializeGraph(g)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return d2graph.DeserializeGraph(bytes, g)
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
return layout, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, layoutName := range layoutsTested {
|
for _, layoutName := range layoutsTested {
|
||||||
|
|
@ -268,3 +291,10 @@ func loadFromFile(t *testing.T, name string) testCase {
|
||||||
script: string(d2Text),
|
script: string(d2Text),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func loadFromFileWithOptions(t *testing.T, name string, options testCase) testCase {
|
||||||
|
tc := options
|
||||||
|
tc.name = name
|
||||||
|
tc.script = loadFromFile(t, name).script
|
||||||
|
return tc
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1052,6 +1052,7 @@ cf many required: {
|
||||||
loadFromFile(t, "glob_dimensions"),
|
loadFromFile(t, "glob_dimensions"),
|
||||||
loadFromFile(t, "shaped_grid_positioning"),
|
loadFromFile(t, "shaped_grid_positioning"),
|
||||||
loadFromFile(t, "cloud_shaped_grid"),
|
loadFromFile(t, "cloud_shaped_grid"),
|
||||||
|
loadFromFileWithOptions(t, "nested_layout_bug", testCase{testSerialization: true}),
|
||||||
}
|
}
|
||||||
|
|
||||||
runa(t, tcs)
|
runa(t, tcs)
|
||||||
|
|
|
||||||
9
e2etests/testdata/files/nested_layout_bug.d2
vendored
Normal file
9
e2etests/testdata/files/nested_layout_bug.d2
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
grid-rows: 1
|
||||||
|
grid-columns: 2
|
||||||
|
a
|
||||||
|
b: {
|
||||||
|
grid-rows: 1
|
||||||
|
grid-columns: 1
|
||||||
|
AA.BB
|
||||||
|
}
|
||||||
|
a -> b.AA
|
||||||
Loading…
Reference in a new issue