diff --git a/lib/Graph.ts b/lib/Graph.ts index 43707e8..5b53124 100644 --- a/lib/Graph.ts +++ b/lib/Graph.ts @@ -75,6 +75,7 @@ export class Graph extends Element { public add_graph (constructor: ((g: Graph) => void) | string): string { const graph = new Graph ('unnamed', this.full_name); + graph.directional = this.directional; if (typeof constructor === 'string') graph.name = constructor; diff --git a/test/Graph.ts b/test/Graph.ts index e591755..2826a56 100644 --- a/test/Graph.ts +++ b/test/Graph.ts @@ -26,6 +26,19 @@ const result = `digraph foo { foo_foo -> foo_baz }`; +const non_directional = `graph foo { + subgraph cluster_foo_bar { + foo_bar_baz [label="baz"] + foo_bar_asd [label="asd"] + + foo_bar_baz -- foo_bar_asd + } + + foo_foo [label="foo"] + + foo_bar_baz -- foo_foo +}`; + test ('serialize', (t) => { const g = new Graph ('foo'); @@ -63,3 +76,23 @@ test ('serialize', (t) => { t.is (serialized, result); }); + +test ('non directional', (t) => { + const g = new Graph ('foo'); + g.directional = false; + + let n = ''; + + g.add_graph ((sub) => { + sub.name = 'bar'; + n = sub.add_node ('baz'); + const n2 = sub.add_node ('asd'); + + sub.add_edge (n, n2); + }); + + const f = g.add_node ('foo'); + g.add_edge (n, f); + + t.is (g.toString (), non_directional); +});