From b57492c1c6ba67b44f0d2c5eb8ddaf1b39a7a1dd Mon Sep 17 00:00:00 2001 From: Justin Greywolf Date: Mon, 25 Nov 2019 17:15:57 -0800 Subject: [PATCH] Initial checkin --- .vscode/settings.json | 8 - .../integration/rendering/flowchart.spec.js | 4 +- src/diagrams/class/classDiagram.spec.js | 139 +++++++++++++++--- .../flowchart/parser/flow-comments.spec.js | 2 +- src/diagrams/flowchart/parser/flow.jison | 11 -- 5 files changed, 120 insertions(+), 44 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index ee8fae482..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "typescript.format.enable": false, - "typescript.reportStyleChecksAsWarnings": false, - "typescript.validate.enable": false, - "javascript.validate.enable": false, - "editor.formatOnSave": false, - "editor.snippetSuggestions": "top" -} diff --git a/cypress/integration/rendering/flowchart.spec.js b/cypress/integration/rendering/flowchart.spec.js index 5cf75f53e..565083520 100644 --- a/cypress/integration/rendering/flowchart.spec.js +++ b/cypress/integration/rendering/flowchart.spec.js @@ -190,7 +190,7 @@ describe('Flowcart', () => { ); }); - it('9: should render subgraphs with a title startign with a digit', () => { + it('9: should render subgraphs with a title starting with a digit', () => { imgSnapshotTest( ` graph TB @@ -237,7 +237,7 @@ describe('Flowcart', () => { ); }); - it('11: should render a flowchart with ling sames and class definitoins', () => { + it('11: should render a flowchart with long names and class definitions', () => { imgSnapshotTest( `graph LR sid-B3655226-6C29-4D00-B685-3D5C734DC7E1[" diff --git a/src/diagrams/class/classDiagram.spec.js b/src/diagrams/class/classDiagram.spec.js index 7c9467be6..2c83e6675 100644 --- a/src/diagrams/class/classDiagram.spec.js +++ b/src/diagrams/class/classDiagram.spec.js @@ -2,13 +2,13 @@ import { parser } from './parser/classDiagram'; import classDb from './classDb'; -describe('class diagram, ', function() { - describe('when parsing an info graph it', function() { - beforeEach(function() { +describe('class diagram, ', function () { + describe('when parsing an info graph it', function () { + beforeEach(function () { parser.yy = classDb; }); - it('should handle relation definitions', function() { + it('should handle relation definitions', function () { const str = 'classDiagram\n' + 'Class01 <|-- Class02\n' + @@ -19,7 +19,7 @@ describe('class diagram, ', function() { parser.parse(str); }); - it('should handle relation definition of different types and directions', function() { + it('should handle relation definition of different types and directions', function () { const str = 'classDiagram\n' + 'Class11 <|.. Class12\n' + @@ -31,7 +31,7 @@ describe('class diagram, ', function() { parser.parse(str); }); - it('should handle cardinality and labels', function() { + it('should handle cardinality and labels', function () { const str = 'classDiagram\n' + 'Class01 "1" *-- "many" Class02 : contains\n' + @@ -66,7 +66,7 @@ describe('class diagram, ', function() { parser.parse(str); }); - it('should handle method statements', function() { + it('should handle method statements', function () { const str = 'classDiagram\n' + 'Object <|-- ArrayList\n' + @@ -76,7 +76,7 @@ describe('class diagram, ', function() { parser.parse(str); }); - it('should handle parsing of method statements grouped by brackets', function() { + it('should handle parsing of method statements grouped by brackets', function () { const str = 'classDiagram\n' + 'class Dummy_Class {\n' + @@ -92,7 +92,7 @@ describe('class diagram, ', function() { parser.parse(str); }); - it('should handle parsing of separators', function() { + it('should handle parsing of separators', function () { const str = 'classDiagram\n' + 'class Foo1 {\n' + @@ -126,12 +126,12 @@ describe('class diagram, ', function() { }); }); - describe('when fetching data from an classDiagram graph it', function() { - beforeEach(function() { + describe('when fetching data from an classDiagram graph it', function () { + beforeEach(function () { parser.yy = classDb; parser.yy.clear(); }); - it('should handle relation definitions EXTENSION', function() { + it('should handle relation definitions EXTENSION', function () { const str = 'classDiagram\n' + 'Class01 <|-- Class02'; parser.parse(str); @@ -144,7 +144,7 @@ describe('class diagram, ', function() { expect(relations[0].relation.type2).toBe('none'); expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE); }); - it('should handle relation definitions AGGREGATION and dotted line', function() { + it('should handle relation definitions AGGREGATION and dotted line', function () { const str = 'classDiagram\n' + 'Class01 o.. Class02'; parser.parse(str); @@ -157,7 +157,7 @@ describe('class diagram, ', function() { expect(relations[0].relation.type2).toBe('none'); expect(relations[0].relation.lineType).toBe(classDb.lineType.DOTTED_LINE); }); - it('should handle relation definitions COMPOSITION on both sides', function() { + it('should handle relation definitions COMPOSITION on both sides', function () { const str = 'classDiagram\n' + 'Class01 *--* Class02'; parser.parse(str); @@ -170,7 +170,7 @@ describe('class diagram, ', function() { expect(relations[0].relation.type2).toBe(classDb.relationType.COMPOSITION); expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE); }); - it('should handle relation definitions no types', function() { + it('should handle relation definitions no types', function () { const str = 'classDiagram\n' + 'Class01 -- Class02'; parser.parse(str); @@ -183,7 +183,7 @@ describe('class diagram, ', function() { expect(relations[0].relation.type2).toBe('none'); expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE); }); - it('should handle relation definitions with type only on right side', function() { + it('should handle relation definitions with type only on right side', function () { const str = 'classDiagram\n' + 'Class01 --|> Class02'; parser.parse(str); @@ -197,7 +197,7 @@ describe('class diagram, ', function() { expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE); }); - it('should handle multiple classes and relation definitions', function() { + it('should handle multiple classes and relation definitions', function () { const str = 'classDiagram\n' + 'Class01 <|-- Class02\n' + @@ -223,7 +223,7 @@ describe('class diagram, ', function() { expect(relations[3].relation.lineType).toBe(classDb.lineType.DOTTED_LINE); }); - it('should handle class annotations', function() { + it('should handle class annotations', function () { const str = 'classDiagram\n' + 'class Class1\n' + '<> Class1'; parser.parse(str); @@ -234,7 +234,7 @@ describe('class diagram, ', function() { expect(testClass.annotations[0]).toBe('interface'); }); - it('should handle class annotations with members and methods', function() { + it('should handle class annotations with members and methods', function () { const str = 'classDiagram\n' + 'class Class1\n' + @@ -250,7 +250,7 @@ describe('class diagram, ', function() { expect(testClass.annotations[0]).toBe('interface'); }); - it('should handle class annotations in brackets', function() { + it('should handle class annotations in brackets', function () { const str = 'classDiagram\n' + 'class Class1 {\n' + '<>\n' + '}'; parser.parse(str); @@ -261,7 +261,7 @@ describe('class diagram, ', function() { expect(testClass.annotations[0]).toBe('interface'); }); - it('should handle class annotations in brackets with members and methods', function() { + it('should handle class annotations in brackets with members and methods', function () { const str = 'classDiagram\n' + 'class Class1 {\n' + @@ -278,7 +278,7 @@ describe('class diagram, ', function() { expect(testClass.annotations[0]).toBe('interface'); }); - it('should add bracket members in right order', function() { + it('should add bracket members in right order', function () { const str = 'classDiagram\n' + 'class Class1 {\n' + @@ -297,5 +297,100 @@ describe('class diagram, ', function() { expect(testClass.methods[0]).toBe('test()'); expect(testClass.methods[1]).toBe('foo()'); }); + + it('should handle a comment', function () { + const str = + 'classDiagram\n' + + '%% Comment \n' + + 'class Class1 {\n' + + 'int : test\n' + + 'string : foo\n' + + 'test()\n' + + 'foo()\n' + + '}'; + + parser.parse(str); + }); + + // it('should handle comments at the start', function () { + // const str = + // '%% Comment\n' + + // 'class Class1 {\n' + + // 'int : test\n' + + // 'string : foo\n' + + // 'test()\n' + + // 'foo()\n' + + // '}'; + // parser.parse(str); + // }); + + // it('should handle comments at the end', function () { + // const str = + // 'classDiagram\n' + + // 'class Class1 {\n' + + // 'int : test\n' + + // 'string : foo\n' + + // 'test()\n' + + // 'foo()\n' + + // '\n}' + + // '%% Comment\n'; + + // parser.parse(str); + // }); + + // it('should handle comments at the end no trailing newline', function () { + // const str = + // 'class Class1 {\n' + + // 'int : test\n' + + // 'string : foo\n' + + // 'test()\n' + + // 'foo()\n' + + // '}\n' + + // '%% Comment'; + + // parser.parse(str); + // }); + + // it('should handle comments at the end many trailing newlines', function () { + // const str = + // 'classDiagram\n' + + // '%% Comment\n\n\n\n\n' + + // 'class Class1 {\n' + + // 'int : test\n' + + // 'string : foo\n' + + // 'test()\n' + + // 'foo()\n' + + // '}'; + + // parser.parse(str); + // }); + + // it('should handle a comment with blank rows in-between', function () { + // const str = + // 'classDiagram\n\n\n' + + // '%% Comment\n\n' + + // 'class Class1 {\n' + + // 'int : test\n' + + // 'string : foo\n' + + // 'test()\n' + + // 'foo()\n' + + // '}'; + + // parser.parse(str); + // }); + + // it('should handle a comment with mermaid class diagram code in them', function () { + // const str = + // 'classDiagram\n' + + // '%% Comment Class01 <|-- Class02\n' + + // 'class Class1 {\n' + + // 'int : test\n' + + // 'string : foo\n' + + // 'test()\n' + + // 'foo()\n' + + // '}'; + + // parser.parse(str); + //}); }); }); diff --git a/src/diagrams/flowchart/parser/flow-comments.spec.js b/src/diagrams/flowchart/parser/flow-comments.spec.js index 32452e3ae..5ef91c874 100644 --- a/src/diagrams/flowchart/parser/flow-comments.spec.js +++ b/src/diagrams/flowchart/parser/flow-comments.spec.js @@ -27,7 +27,7 @@ describe('[Comments] when parsing', () => { expect(edges[0].text).toBe(''); }); - it('should handle comments a at the start', function() { + it('should handle comments at the start', function() { const res = flow.parser.parse('%% Comment\ngraph TD;\n A-->B;'); const vert = flow.parser.yy.getVertices(); diff --git a/src/diagrams/flowchart/parser/flow.jison b/src/diagrams/flowchart/parser/flow.jison index da86b50f8..309d83c94 100644 --- a/src/diagrams/flowchart/parser/flow.jison +++ b/src/diagrams/flowchart/parser/flow.jison @@ -460,13 +460,6 @@ text: textToken -commentText: commentToken - {$$=$1;} - | commentText commentToken - {$$=$1+''+$2;} - ; - - keywords : STYLE | LINKSTYLE | CLASSDEF | CLASS | CLICK | GRAPH | DIR | subgraph | end | DOWN | UP; @@ -516,8 +509,6 @@ linkStyleStatement {$$ = $1;yy.updateLinkInterpolate($3,$7);} ; -commentStatement: PCT PCT commentText; - numList: NUM {$$ = [$1]} | numList COMMA NUM @@ -539,8 +530,6 @@ styleComponent: ALPHA | COLON | MINUS | NUM | UNIT | SPACE | HEX | BRKT | DOT | /* Token lists */ -commentToken : textToken | graphCodeTokens ; - textToken : textNoTagsToken | TAGSTART | TAGEND | '==' | '--' | PCT | DEFAULT; textNoTagsToken: alphaNumToken | SPACE | MINUS | keywords ;