Merge branch 'master' of git.scode.ovh:timo/graphviz-builder

This commit is contained in:
2020-04-29 22:22:42 +02:00
13 changed files with 167 additions and 43 deletions

View File

@ -4,6 +4,7 @@ import { Color } from '../lib';
test ('serialize', (t) => {
const wh = Color.white;
const tr = Color.transparent;
t.is (wh.toString (), '#ffffff');
t.is (tr.toString (), '#00000000');
});

View File

@ -2,9 +2,21 @@ import test from 'ava';
import { Edge, Color, EdgeStyles } from '../lib';
test ('serialize', (t) => {
const e = new Edge ('foo', 'bar');
const e = new Edge ('foo', 'bar', false);
e.color = Color.white;
e.style = EdgeStyles.dashed;
const serialized = e.toString ();
t.is (serialized, 'foo -- bar [style="dashed",color="#ffffff"]');
});
test ('serialize directional', (t) => {
const e = new Edge ('foo', 'bar', true);
e.color = Color.white;
e.style = EdgeStyles.dashed;
const serialized = e.toString ();
t.is (serialized, 'foo -> bar [style="dashed",color="#ffffff"]');
});

View File

@ -1,5 +1,5 @@
import test from 'ava';
import { Graph, GraphStyles, Color, NodeStyles } from '../lib';
import { Graph, GraphStyles, Color, NodeStyles, GraphLayouts } from '../lib';
const result = `digraph foo {
subgraph cluster_foo_baz {
@ -26,6 +26,27 @@ 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
}`;
const attributes = `digraph attr {
color = #000000
style = bold
overlap = false
splines = true
layout = neato
}`;
test ('serialize', (t) => {
const g = new Graph ('foo');
@ -57,9 +78,44 @@ test ('serialize', (t) => {
const baz = g.add_node ('baz');
const foo = g.add_node ('foo');
g.add_edge (foo, baz);
const serialized = g.toString ();
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);
});
test ('attributes', (t) => {
const g = new Graph ('attr');
g.layout = GraphLayouts.neato;
g.overlap = false;
g.splines = true;
g.color = Color.black;
g.style = GraphStyles.bold;
t.is (g.toString (), attributes);
});

View File

@ -11,16 +11,19 @@ const serialized_table = `bar_foo [label=<<table>
test ('serialize simple', (t) => {
const g = new Node ('foo', 'bar', 'baz');
g.color = Color.green;
g.style = NodeStyles.dashed;
const serialized = g.toString ();
t.is (g.full_name, 'bar_foo');
t.is (serialized, serialized_simple);
});
test ('serialize table', (t) => {
const g = new Node ('foo', 'bar', 'baz');
g.color = Color.green;
g.style = NodeStyles.invisible;
@ -44,6 +47,7 @@ test ('serialize table', (t) => {
g.is_table = true;
const serialized = g.toString ();
t.is (g.full_name, 'bar_foo');
t.is (serialized, serialized_table);
});
@ -55,7 +59,12 @@ test ('adhere to naming convention', (t) => {
test ('throw on invalid name', (t) => {
t.throws (() => {
<<<<<<< HEAD
const n = new Node ('564#+-.,/@', 'parent');
=======
const n = new Node ('invalid.name', 'parent');
>>>>>>> f553396eee29e1e0820624345e5d23dc3471a4a4
return n.toString ();
}, { message: 'invalid name specified' });
});