This commit is contained in:
Timo Hocker 2020-04-28 09:59:24 +02:00
parent 373285ec46
commit 8af030e54f
2 changed files with 34 additions and 0 deletions

View File

@ -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;

View File

@ -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);
});