diff --git a/test/spec/Stream.ts b/test/spec/Stream.ts index 7bc9f1e..e2f5858 100644 --- a/test/spec/Stream.ts +++ b/test/spec/Stream.ts @@ -96,4 +96,122 @@ describe ('stream', () => { stream.end_graph (); stream.end (); })); + + // eslint-disable-next-line max-lines-per-function + it ('should reject invalid command sequences', () => { + /** + * command valid invalid + * [s] cug, cdg eg, cn, csg, ce, at + * cn eg, cn, csg, ce, at cug, cdg + * cug eg, cn, csg, ce, at cug, cdg + * cdg eg, cn, csg, ce, at cug, cdg + * csg eg, cn, csg, ce, at cug, cdg + * eg eg, cn, csg, ce cug, cdg, at + * at eg, cn, csg, ce cug, cdg, at + * ce eg, cn, csg, ce, at cug, cdg + */ + + const cn = (g:GraphStream) => { + g.create_node ('foo'); + }; + const cug = (g:GraphStream) => { + g.create_graph ('foo', 'u'); + }; + const cdg = (g:GraphStream) => { + g.create_graph ('foo', 'd'); + }; + const csg = (g:GraphStream) => { + g.create_graph ('foo', 's'); + }; + const eg = (g:GraphStream) => { + g.end_graph (); + }; + const at = (g:GraphStream) => { + g.attributes ({ color: 'red' }); + }; + const ce = (g:GraphStream) => { + g.create_edge ('foo', 'bar'); + }; + + const combinations = [ + { + primary: (g:GraphStream) => { + cug (g); + cn (g); + }, + secondary: [ + cug, + cdg + ] + }, + { + primary: cug, + secondary: [ + cug, + cdg + ] + }, + { + primary: cdg, + secondary: [ + cug, + cdg + ] + }, + { + primary: (g:GraphStream) => { + cug (g); + csg (g); + }, + secondary: [ + cug, + cdg + ] + }, + { + primary: (g:GraphStream) => { + cug (g); + csg (g); + eg (g); + }, + secondary: [ + cug, + cdg, + at + ] + }, + { + primary: (g:GraphStream) => { + cug (g); + at (g); + }, + secondary: [ + cug, + cdg, + at + ] + }, + { + primary: (g:GraphStream) => { + cug (g); + ce (g); + }, + secondary: [ + cug, + cdg + ] + } + ]; + + for (const comb of combinations) { + for (const secondary of comb.secondary) { + const g = (new GraphStream); + comb.primary (g); + expect (() => secondary (g)) + .toThrowError ( + /invalid state to execute command.*?expected:.*?actual:/uis + ); + } + } + }); });