2020-06-05 11:46:58 +02:00

96 lines
2.3 KiB
TypeScript

/*
* Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of graphviz-builder which is released under MIT.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, June 2020
*/
import test from 'ava';
import { GraphStream, Color } from '../lib/index';
const simple = `graph foo {
}
`;
const complex = `digraph foo {
subgraph cluster_foo_baz {
color = #ff0000
style = bold
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_foo -> foo_baz
foo_foo -> foo_baz_asd [label = "edge attr"]
}
`;
test ('stream graph', (t) => new Promise ((resolve) => {
let output = '';
const stream = (new GraphStream);
stream.on ('data', (data) => {
output += data;
});
stream.on ('end', () => {
t.is (output, simple);
resolve ();
});
stream.create_graph ('foo', 'u');
stream.end_graph ();
stream.end ();
}));
// eslint-disable-next-line max-statements
test ('complex stream graph', (t) => new Promise ((resolve) => {
let output = '';
const stream = (new GraphStream);
stream.on ('data', (data) => {
output += data;
});
stream.on ('end', () => {
t.is (output, complex);
resolve ();
});
stream.create_graph ('foo', 'd');
stream.create_graph ('baz');
stream.attributes ({ color: Color.red, style: 'bold' });
stream.create_graph ('nested');
stream.attributes ({ color: Color.gray, style: 'dotted' });
stream.create_graph ('unnamed');
stream.attributes ({ color: Color.gray, style: 'dotted' });
stream.end_graph ();
stream.end_graph ();
const asd = stream.create_node ('asd');
stream.attributes ({ label: 'asd' });
stream.end_node ();
stream.create_node ('test');
stream.attributes ({ style: 'bold', color: Color.gray });
stream.end_graph ();
const baz = stream.create_node ('baz');
stream.attributes ({ label: 'baz' });
const foo = stream.create_node ('foo');
stream.attributes ({ label: 'foo' });
stream.create_edge (foo, baz);
stream.create_edge (foo, asd);
stream.attributes ({ label: 'edge attr' });
stream.end_graph ();
stream.end ();
}));