diff --git a/src/diagrams/mindmap/mindmap.spec.js b/src/diagrams/mindmap/mindmap.spec.js index f2658cf65..4c31dc97f 100644 --- a/src/diagrams/mindmap/mindmap.spec.js +++ b/src/diagrams/mindmap/mindmap.spec.js @@ -166,6 +166,22 @@ root `; // ::class1 class2 + mindmap.parse(str); + const mm = mindmap.yy.getMindmap(); + expect(mm.nodeId).toEqual('root'); + expect(mm.descr).toEqual('The root'); + expect(mm.type).toEqual(mindmap.yy.nodeType.RECT); + expect(mm.class).toEqual('m-4 p-8'); + expect(mm.icon).toEqual('bomb'); + }); + it('should be possible to set both classes and icon for the node', function () { + var str = `mindmap + root[The root] + ::icon(bomb) + :::m-4 p-8 + `; + // ::class1 class2 + mindmap.parse(str); const mm = mindmap.yy.getMindmap(); expect(mm.nodeId).toEqual('root'); @@ -230,6 +246,45 @@ root expect(mm.descr).toEqual('Root'); expect(mm.children.length).toEqual(1); + const child = mm.children[0]; + expect(child.nodeId).toEqual('Child'); + expect(child.children[0].nodeId).toEqual('a'); + expect(child.children.length).toEqual(2); + expect(child.children[1].nodeId).toEqual('b'); + }); + it('should be possible to have comments in a mindmap', function () { + var str = `mindmap + root(Root) + Child(Child) + a(a) + + %% This is a comment + b[New Stuff]`; + mindmap.parse(str); + const mm = mindmap.yy.getMindmap(); + expect(mm.nodeId).toEqual('root'); + expect(mm.descr).toEqual('Root'); + expect(mm.children.length).toEqual(1); + + const child = mm.children[0]; + expect(child.nodeId).toEqual('Child'); + expect(child.children[0].nodeId).toEqual('a'); + expect(child.children.length).toEqual(2); + expect(child.children[1].nodeId).toEqual('b'); + }); + + it('should be possible to have comments at the end of a line', function () { + var str = `mindmap + root(Root) + Child(Child) + a(a) %% This is a comment + b[New Stuff]`; + mindmap.parse(str); + const mm = mindmap.yy.getMindmap(); + expect(mm.nodeId).toEqual('root'); + expect(mm.descr).toEqual('Root'); + expect(mm.children.length).toEqual(1); + const child = mm.children[0]; expect(child.nodeId).toEqual('Child'); expect(child.children[0].nodeId).toEqual('a'); diff --git a/src/diagrams/mindmap/parser/mindmap.jison b/src/diagrams/mindmap/parser/mindmap.jison index a31806390..8cafd9a7d 100644 --- a/src/diagrams/mindmap/parser/mindmap.jison +++ b/src/diagrams/mindmap/parser/mindmap.jison @@ -17,7 +17,7 @@ %% -\%\%.*\n {console.log('Found comment',yytext);} /* skip comments */ +\s*\%\%.*\n {console.log('Found comment',yytext);} // \%\%[^\n]*\n /* skip comments */ "mindmap" return 'MINDMAP'; ":::" { this.begin('CLASS'); } @@ -68,7 +68,7 @@ statement : SPACELIST node { yy.addNode($1.length, $2.id, $2.descr, $2.type); } | SPACELIST ICON { yy.decorateNode({icon: $2}); } | SPACELIST EOF - | SPACELIST NL + | SPACELIST NL | node { console.log($1.id);yy.addNode(0, $1.id, $1.descr, $1.type); } | ICON { yy.decorateNode({icon: $1}); } | SPACELIST CLASS { yy.decorateNode({class: $2}); }