57 lines
1.3 KiB
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 { NodeStyles, Node, Color } from '../lib';
2020-04-24 12:02:32 +02:00
2020-04-24 17:01:26 +02:00
const serialized_simple
2020-04-27 18:57:23 +02:00
= 'bar_foo [label="baz", style="dashed", color="#00ff00"]';
2020-04-24 12:02:32 +02:00
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>
2020-04-27 18:57:23 +02:00
</table>>, style="invis", color="#00ff00"]`;
2020-04-24 12:02:32 +02:00
test ('serialize simple', (t) => {
const g = new Node ('foo', 'bar', 'baz');
2020-04-24 17:01:26 +02:00
g.color = Color.green;
g.style = NodeStyles.dashed;
2020-04-24 12:02:32 +02:00
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');
2020-04-24 17:01:26 +02:00
g.color = Color.green;
2020-04-25 17:34:05 +02:00
g.style = NodeStyles.invisible;
2020-04-24 12:02:32 +02:00
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);
});
2020-04-27 18:57:23 +02:00
test ('adhere to naming convention', (t) => {
t.throws (() => {
const n = new Node ('invalid.name', 'parent');
return n.toString ();
}, { message: 'invalid name specified' });
});