This commit is contained in:
2020-04-27 18:57:23 +02:00
parent 2e34757a1a
commit 73db0afc1f
5 changed files with 117 additions and 47 deletions

View File

@ -1,16 +1,27 @@
import test from 'ava';
import { Graph, GraphStyles, Color } from '../lib';
import { Graph, GraphStyles, Color, NodeStyles } from '../lib';
const result = `digraph foo {
subgraph cluster_foo_baz {
color = #ff0000
style = bold
foo_baz_asd [label=<asd>]
subgraph cluster_foo_baz_nested {
color = #808080
style = dotted
subgraph cluster_foo_baz_nested_unnamed {
color = #808080
style = dotted
}
}
foo_baz_asd [label="asd"]
foo_baz_test [style="bold", color="#808080"]
}
foo_baz [label=<baz>]
foo_foo [label=<foo>]
foo_baz [label="baz"]
foo_foo [label="foo"]
foo_foo -> foo_baz
}`;
@ -22,13 +33,31 @@ test ('serialize', (t) => {
g.add_graph ((graph) => {
graph.name = 'baz';
graph.add_node ('asd');
graph.add_node ((n) => {
n.name = 'test';
n.style = NodeStyles.bold;
n.color = Color.gray;
});
// eslint-disable-next-line no-shadow
graph.add_graph ((g) => {
g.style = GraphStyles.dotted;
g.color = Color.gray;
g.name = 'nested';
// eslint-disable-next-line no-shadow, max-nested-callbacks
g.add_graph ((g) => {
g.style = GraphStyles.dotted;
g.color = Color.gray;
});
});
graph.style = GraphStyles.bold;
graph.color = Color.red;
});
g.add_node ('baz');
g.add_node ('foo');
g.add_edge ('foo', 'baz');
const baz = g.add_node ('baz');
const foo = g.add_node ('foo');
g.add_edge (foo, baz);
const serialized = g.toString ();

View File

@ -2,12 +2,12 @@ import test from 'ava';
import { NodeStyles, Node, Color } from '../lib';
const serialized_simple
= 'bar_foo [label=<baz>,style="dashed",color="#00ff00"]';
= 'bar_foo [label="baz", style="dashed", color="#00ff00"]';
const serialized_table = `bar_foo [label=<<table>
<tr><td>foo</td><td>bar</td><td>baz</td></tr>
<tr><td>bar</td><td>baz</td><td>foo</td></tr>
<tr><td>baz</td><td>foo</td><td>bar</td></tr>
</table>>,style="invis",color="#00ff00"]`;
</table>>, style="invis", color="#00ff00"]`;
test ('serialize simple', (t) => {
const g = new Node ('foo', 'bar', 'baz');
@ -47,3 +47,10 @@ test ('serialize table', (t) => {
t.is (g.full_name, 'bar_foo');
t.is (serialized, serialized_table);
});
test ('adhere to naming convention', (t) => {
t.throws (() => {
const n = new Node ('invalid.name', 'parent');
return n.toString ();
}, { message: 'invalid name specified' });
});