diff --git a/cypress/integration/rendering/classDiagram.spec.js b/cypress/integration/rendering/classDiagram.spec.js index 1e45851499..0125a43733 100644 --- a/cypress/integration/rendering/classDiagram.spec.js +++ b/cypress/integration/rendering/classDiagram.spec.js @@ -19,6 +19,9 @@ describe('Class diagram', () => { Class01 : size() Class01 : int chimp Class01 : int gorilla + Class01 : -int privateChimp + Class01 : +int publicGorilla + Class01 : #int protectedMarmoset Class08 <--> C2: Cool label class Class10 { <<service>> @@ -58,6 +61,25 @@ describe('Class diagram', () => { ); cy.get('svg'); }); + + it('should render a simple class diagram with different visibilities', () => { + imgSnapshotTest( + ` + classDiagram + Class01 <|-- AveryLongClass : Cool + <<interface>> Class01 + Class01 : -int privateMethod() + Class01 : +int publicMethod() + Class01 : #int protectedMethod() + Class01 : -int privateChimp + Class01 : +int publicGorilla + Class01 : #int protectedMarmoset + `, + {} + ); + cy.get('svg'); + }); + it('should render multiple class diagrams', () => { imgSnapshotTest( [ diff --git a/dist/index.html b/dist/index.html index 73f6ff1543..2fb6f2ab62 100644 --- a/dist/index.html +++ b/dist/index.html @@ -408,9 +408,9 @@ Class09 --|> Class07 Class07 : equals() Class07 : Object[] elementData -Class01 : size() -Class01 : int chimp -Class01 : int gorilla +Class01 : #size() +Class01 : -int chimp +Class01 : +int gorilla Class08 <--> C2: Cool label class Class10 { <<service>> diff --git a/src/diagrams/class/classDiagram.spec.js b/src/diagrams/class/classDiagram.spec.js index a24a01a882..7c9467be62 100644 --- a/src/diagrams/class/classDiagram.spec.js +++ b/src/diagrams/class/classDiagram.spec.js @@ -40,6 +40,21 @@ describe('class diagram, ', function() { parser.parse(str); }); + + it('should handle visibility for methods and members', function() { + const str = + 'classDiagram\n' + + 'class TestClass\n' + + 'TestClass : -int privateMember\n' + + 'TestClass : +int publicMember\n' + + 'TestClass : #int protectedMember\n' + + 'TestClass : -privateMethod()\n' + + 'TestClass : +publicMethod()\n' + + 'TestClass : #protectedMethod()\n'; + + parser.parse(str); + }); + it('should handle class definitions', function() { const str = 'classDiagram\n' + diff --git a/src/diagrams/class/parser/classDiagram.jison b/src/diagrams/class/parser/classDiagram.jison index 4b0fe97c24..f9e1d22af7 100644 --- a/src/diagrams/class/parser/classDiagram.jison +++ b/src/diagrams/class/parser/classDiagram.jison @@ -36,7 +36,7 @@ \s*o return 'AGGREGATION'; \-\- return 'LINE'; \.\. return 'DOTTED_LINE'; -":"[^#\n;]+ return 'LABEL'; +":"[^\n;]+ return 'LABEL'; \- return 'MINUS'; "." return 'DOT'; \+ return 'PLUS';