37 lines
669 B
TypeScript
Raw Normal View History

2020-04-24 12:02:32 +02:00
import test from 'ava';
2020-04-24 17:01:26 +02:00
import { Graph, GraphStyles, Color } from '../lib';
2020-04-24 12:02:32 +02:00
2020-04-24 12:21:26 +02:00
const result = `digraph foo {
subgraph cluster_foo_baz {
2020-04-24 17:01:26 +02:00
color = #ff0000
style = bold
2020-04-24 14:05:58 +02:00
foo_baz_asd [label=<asd>]
2020-04-24 12:02:32 +02:00
}
2020-04-24 14:05:58 +02:00
foo_baz [label=<baz>]
foo_foo [label=<foo>]
2020-04-24 12:02:32 +02:00
2020-04-24 12:21:26 +02:00
foo_foo -> foo_baz
2020-04-24 12:02:32 +02:00
}`;
test ('serialize', (t) => {
2020-04-24 12:21:26 +02:00
const g = new Graph ('foo');
2020-04-24 12:02:32 +02:00
2020-04-24 12:21:26 +02:00
t.is (g.full_name, 'foo');
2020-04-24 14:05:58 +02:00
g.add_graph ((graph) => {
graph.name = 'baz';
graph.add_node ('asd');
2020-04-24 17:01:26 +02:00
graph.style = GraphStyles.bold;
graph.color = Color.red;
2020-04-24 12:02:32 +02:00
});
2020-04-24 14:05:58 +02:00
g.add_node ('baz');
g.add_node ('foo');
2020-04-24 12:02:32 +02:00
g.add_edge ('foo', 'baz');
const serialized = g.toString ();
t.is (serialized, result);
});