89 lines
2.0 KiB
TypeScript
89 lines
2.0 KiB
TypeScript
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
|
|
}
|
|
|
|
`;
|
|
|
|
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 ();
|
|
stream.create_node ('asd');
|
|
stream.attributes ({ label: 'asd' });
|
|
stream.end_node ();
|
|
stream.create_node ('test');
|
|
stream.attributes ({ style: 'bold', color: Color.gray });
|
|
stream.end_node ();
|
|
stream.end_graph ();
|
|
stream.create_node ('baz');
|
|
stream.attributes ({ label: 'baz' });
|
|
stream.end_node ();
|
|
stream.create_node ('foo');
|
|
stream.attributes ({ label: 'foo' });
|
|
stream.end_node ();
|
|
stream.create_edge (`${stream.path}_foo`, `${stream.path}_baz`);
|
|
stream.end_graph ();
|
|
stream.end ();
|
|
}));
|