complete basic structures
This commit is contained in:
20
test/.eslintrc.js
Normal file
20
test/.eslintrc.js
Normal file
@ -0,0 +1,20 @@
|
||||
module.exports = {
|
||||
env: {
|
||||
commonjs: true,
|
||||
es6: true,
|
||||
node: true
|
||||
},
|
||||
extends: [
|
||||
'@scode/eslint-config-ts'
|
||||
],
|
||||
globals: {
|
||||
Atomics: 'readonly',
|
||||
SharedArrayBuffer: 'readonly'
|
||||
},
|
||||
parserOptions: {
|
||||
ecmaVersion: 2018
|
||||
},
|
||||
rules: {
|
||||
'node/no-unpublished-import': 'off'
|
||||
}
|
||||
}
|
8
test/Edge.ts
Normal file
8
test/Edge.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import test from 'ava';
|
||||
import { Edge } from '../lib';
|
||||
|
||||
test ('serialize', (t) => {
|
||||
const e = new Edge ('foo', 'bar');
|
||||
const serialized = e.toString ();
|
||||
t.is (serialized, 'foo -> bar');
|
||||
});
|
35
test/Graph.ts
Normal file
35
test/Graph.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import fs from 'fs';
|
||||
import test from 'ava';
|
||||
import { Graph, Node } from '../lib';
|
||||
|
||||
const result = `subgraph cluster_bar_foo {
|
||||
subgraph cluster_bar_foo_baz {
|
||||
|
||||
bar_foo_baz_asd
|
||||
|
||||
}
|
||||
|
||||
bar_foo_baz
|
||||
bar_foo_foo
|
||||
|
||||
bar_foo_foo -> bar_foo_baz
|
||||
}`;
|
||||
|
||||
test ('serialize', (t) => {
|
||||
const g = new Graph ('foo', 'bar');
|
||||
|
||||
t.is (g.full_name, 'bar_foo');
|
||||
g.add_graph (() => {
|
||||
const graph = new Graph ('baz');
|
||||
graph.add_node (() => new Node ('asd'));
|
||||
return graph;
|
||||
});
|
||||
|
||||
g.add_node (() => new Node ('baz'));
|
||||
g.add_node (() => new Node ('foo'));
|
||||
g.add_edge ('foo', 'baz');
|
||||
|
||||
const serialized = g.toString ();
|
||||
|
||||
t.is (serialized, result);
|
||||
});
|
44
test/Node.ts
Normal file
44
test/Node.ts
Normal file
@ -0,0 +1,44 @@
|
||||
import test from 'ava';
|
||||
import { Node } from '../lib/Node';
|
||||
|
||||
const serialized_simple = 'bar_foo [label=<baz>]';
|
||||
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>>]`;
|
||||
|
||||
test ('serialize simple', (t) => {
|
||||
const g = new Node ('foo', 'bar', 'baz');
|
||||
|
||||
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.table_contents = [
|
||||
[
|
||||
'foo',
|
||||
'bar',
|
||||
'baz'
|
||||
],
|
||||
[
|
||||
'bar',
|
||||
'baz',
|
||||
'foo'
|
||||
],
|
||||
[
|
||||
'baz',
|
||||
'foo',
|
||||
'bar'
|
||||
]
|
||||
];
|
||||
g.is_table = true;
|
||||
|
||||
const serialized = g.toString ();
|
||||
t.is (g.full_name, 'bar_foo');
|
||||
t.is (serialized, serialized_table);
|
||||
});
|
Reference in New Issue
Block a user