mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
added tests + alt syntax
This commit is contained in:
parent
912e850db4
commit
612df99c34
@ -86,6 +86,7 @@ Future task2 : des4, after des3, 5d
|
|||||||
```
|
```
|
||||||
classDiagram
|
classDiagram
|
||||||
Class01 <|-- AveryLongClass : Cool
|
Class01 <|-- AveryLongClass : Cool
|
||||||
|
<<interface>> Class01
|
||||||
Class03 *-- Class04
|
Class03 *-- Class04
|
||||||
Class05 o-- Class06
|
Class05 o-- Class06
|
||||||
Class07 .. Class08
|
Class07 .. Class08
|
||||||
@ -98,7 +99,11 @@ Class01 : size()
|
|||||||
Class01 : int chimp
|
Class01 : int chimp
|
||||||
Class01 : int gorilla
|
Class01 : int gorilla
|
||||||
Class08 <--> C2: Cool label
|
Class08 <--> C2: Cool label
|
||||||
<<interface>> Class01
|
class Class10 {
|
||||||
|
<<service>>
|
||||||
|
int id
|
||||||
|
size()
|
||||||
|
}
|
||||||
```
|
```
|
||||||
![Class diagram](./img/class.png)
|
![Class diagram](./img/class.png)
|
||||||
|
|
||||||
|
7
dist/index.html
vendored
7
dist/index.html
vendored
@ -399,6 +399,7 @@ merge newbranch
|
|||||||
<div class="mermaid">
|
<div class="mermaid">
|
||||||
classDiagram
|
classDiagram
|
||||||
Class01 <|-- AveryLongClass : Cool
|
Class01 <|-- AveryLongClass : Cool
|
||||||
|
<<interface>> Class01
|
||||||
Class03 "0" *-- "0..n" Class04
|
Class03 "0" *-- "0..n" Class04
|
||||||
Class05 "1" o-- "many" Class06
|
Class05 "1" o-- "many" Class06
|
||||||
Class07 .. Class08
|
Class07 .. Class08
|
||||||
@ -411,7 +412,11 @@ Class01 : size()
|
|||||||
Class01 : int chimp
|
Class01 : int chimp
|
||||||
Class01 : int gorilla
|
Class01 : int gorilla
|
||||||
Class08 <--> C2: Cool label
|
Class08 <--> C2: Cool label
|
||||||
<<interface>> Class01
|
class Class10 {
|
||||||
|
<<service>>
|
||||||
|
int id
|
||||||
|
size()
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
<script src="./mermaid.js"></script>
|
<script src="./mermaid.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
@ -6,9 +6,6 @@ let classes = {};
|
|||||||
/**
|
/**
|
||||||
* Function called by parser when a node definition has been found.
|
* Function called by parser when a node definition has been found.
|
||||||
* @param id
|
* @param id
|
||||||
* @param text
|
|
||||||
* @param type
|
|
||||||
* @param style
|
|
||||||
*/
|
*/
|
||||||
export const addClass = function(id) {
|
export const addClass = function(id) {
|
||||||
if (typeof classes[id] === 'undefined') {
|
if (typeof classes[id] === 'undefined') {
|
||||||
@ -51,10 +48,13 @@ export const addAnnotation = function(className, annotation) {
|
|||||||
export const addMember = function(className, member) {
|
export const addMember = function(className, member) {
|
||||||
const theClass = classes[className];
|
const theClass = classes[className];
|
||||||
if (typeof member === 'string') {
|
if (typeof member === 'string') {
|
||||||
if (member.substr(-1) === ')') {
|
const memberString = member.trim();
|
||||||
theClass.methods.push(member);
|
if (memberString.startsWith('<<') && memberString.endsWith('>>')) {
|
||||||
|
theClass.annotations.push(memberString.substring(2, memberString.length - 2));
|
||||||
|
} else if (memberString.endsWith(')')) {
|
||||||
|
theClass.methods.push(memberString);
|
||||||
} else {
|
} else {
|
||||||
theClass.members.push(member);
|
theClass.members.push(memberString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -207,5 +207,60 @@ describe('class diagram, ', function() {
|
|||||||
expect(relations[3].relation.type2).toBe('none');
|
expect(relations[3].relation.type2).toBe('none');
|
||||||
expect(relations[3].relation.lineType).toBe(classDb.lineType.DOTTED_LINE);
|
expect(relations[3].relation.lineType).toBe(classDb.lineType.DOTTED_LINE);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle class annotations', function() {
|
||||||
|
const str = 'classDiagram\n' + 'class Class1\n' + '<<interface>> Class1';
|
||||||
|
parser.parse(str);
|
||||||
|
|
||||||
|
const testClass = parser.yy.getClass('Class1');
|
||||||
|
expect(testClass.annotations.length).toBe(1);
|
||||||
|
expect(testClass.members.length).toBe(0);
|
||||||
|
expect(testClass.methods.length).toBe(0);
|
||||||
|
expect(testClass.annotations[0]).toBe('interface');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle class annotations with members and methods', function() {
|
||||||
|
const str =
|
||||||
|
'classDiagram\n' +
|
||||||
|
'class Class1\n' +
|
||||||
|
'Class1 : int test\n' +
|
||||||
|
'Class1 : test()\n' +
|
||||||
|
'<<interface>> Class1';
|
||||||
|
parser.parse(str);
|
||||||
|
|
||||||
|
const testClass = parser.yy.getClass('Class1');
|
||||||
|
expect(testClass.annotations.length).toBe(1);
|
||||||
|
expect(testClass.members.length).toBe(1);
|
||||||
|
expect(testClass.methods.length).toBe(1);
|
||||||
|
expect(testClass.annotations[0]).toBe('interface');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle class annotations in brackets', function() {
|
||||||
|
const str = 'classDiagram\n' + 'class Class1 {\n' + '<<interface>>\n' + '}';
|
||||||
|
parser.parse(str);
|
||||||
|
|
||||||
|
const testClass = parser.yy.getClass('Class1');
|
||||||
|
expect(testClass.annotations.length).toBe(1);
|
||||||
|
expect(testClass.members.length).toBe(0);
|
||||||
|
expect(testClass.methods.length).toBe(0);
|
||||||
|
expect(testClass.annotations[0]).toBe('interface');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle class annotations in brackets with members and methods', function() {
|
||||||
|
const str =
|
||||||
|
'classDiagram\n' +
|
||||||
|
'class Class1 {\n' +
|
||||||
|
'<<interface>>\n' +
|
||||||
|
'int : test\n' +
|
||||||
|
'test()\n' +
|
||||||
|
'}';
|
||||||
|
parser.parse(str);
|
||||||
|
|
||||||
|
const testClass = parser.yy.getClass('Class1');
|
||||||
|
expect(testClass.annotations.length).toBe(1);
|
||||||
|
expect(testClass.members.length).toBe(1);
|
||||||
|
expect(testClass.methods.length).toBe(1);
|
||||||
|
expect(testClass.annotations[0]).toBe('interface');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user