2017-04-11 22:57:57 +08:00
|
|
|
/* eslint-env jasmine */
|
2019-09-12 12:58:32 -07:00
|
|
|
import { parser } from './parser/classDiagram';
|
|
|
|
import classDb from './classDb';
|
|
|
|
|
2019-11-25 17:15:57 -08:00
|
|
|
describe('class diagram, ', function () {
|
|
|
|
describe('when parsing an info graph it', function () {
|
|
|
|
beforeEach(function () {
|
2019-09-12 12:58:32 -07:00
|
|
|
parser.yy = classDb;
|
|
|
|
});
|
|
|
|
|
2019-11-25 17:15:57 -08:00
|
|
|
it('should handle relation definitions', function () {
|
2019-09-12 12:58:32 -07:00
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'Class01 <|-- Class02\n' +
|
|
|
|
'Class03 *-- Class04\n' +
|
|
|
|
'Class05 o-- Class06\n' +
|
|
|
|
'Class07 .. Class08\n' +
|
|
|
|
'Class09 -- Class1';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
});
|
2019-11-26 11:18:32 -08:00
|
|
|
|
2019-11-25 17:15:57 -08:00
|
|
|
it('should handle relation definition of different types and directions', function () {
|
2019-09-12 12:58:32 -07:00
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'Class11 <|.. Class12\n' +
|
|
|
|
'Class13 --> Class14\n' +
|
|
|
|
'Class15 ..> Class16\n' +
|
|
|
|
'Class17 ..|> Class18\n' +
|
|
|
|
'Class19 <--* Class20';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
});
|
|
|
|
|
2019-11-25 17:15:57 -08:00
|
|
|
it('should handle cardinality and labels', function () {
|
2019-09-12 12:58:32 -07:00
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'Class01 "1" *-- "many" Class02 : contains\n' +
|
|
|
|
'Class03 o-- Class04 : aggregation\n' +
|
|
|
|
'Class05 --> "1" Class06';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
});
|
2019-11-19 12:18:41 -08:00
|
|
|
|
|
|
|
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' +
|
2019-11-19 13:02:08 -08:00
|
|
|
'TestClass : #protectedMethod()\n';
|
2019-11-19 12:18:41 -08:00
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
});
|
|
|
|
|
2019-12-05 12:55:46 -08:00
|
|
|
it('should handle generic class', function() {
|
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'class Car~T~\n' +
|
|
|
|
'Driver -- Car : drives >\n' +
|
|
|
|
'Car *-- Wheel : have 4 >\n' +
|
|
|
|
'Car -- Person : < owns';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
});
|
|
|
|
|
2020-01-15 20:34:41 +01:00
|
|
|
it('should break when another `{`is encountered before closing the first one while defining generic class with brackets', function() {
|
2019-12-05 12:55:46 -08:00
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'class Dummy_Class~T~ {\n' +
|
|
|
|
'String data\n' +
|
|
|
|
' void methods()\n' +
|
|
|
|
'}\n' +
|
|
|
|
'\n' +
|
2020-01-15 20:33:23 +01:00
|
|
|
'class Dummy_Class {\n' +
|
2019-12-05 12:55:46 -08:00
|
|
|
'class Flight {\n' +
|
|
|
|
' flightNumber : Integer\n' +
|
|
|
|
' departureTime : Date\n' +
|
|
|
|
'}';
|
2020-01-15 20:33:23 +01:00
|
|
|
let testPased =false;
|
|
|
|
try{
|
|
|
|
parser.parse(str);
|
|
|
|
}catch (error){
|
|
|
|
console.log(error.name);
|
|
|
|
testPased = true;
|
|
|
|
}
|
|
|
|
expect(testPased).toBe(true);
|
|
|
|
});
|
2019-12-05 12:55:46 -08:00
|
|
|
|
2020-01-15 20:34:41 +01:00
|
|
|
it('should break when EOF is encountered before closing the first `{` while defining generic class with brackets', function() {
|
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'class Dummy_Class~T~ {\n' +
|
|
|
|
'String data\n' +
|
|
|
|
' void methods()\n' +
|
|
|
|
'}\n' +
|
|
|
|
'\n' +
|
|
|
|
'class Dummy_Class {\n';
|
|
|
|
let testPased =false;
|
|
|
|
try{
|
|
|
|
parser.parse(str);
|
|
|
|
}catch (error){
|
|
|
|
console.log(error.name);
|
|
|
|
testPased = true;
|
|
|
|
}
|
|
|
|
expect(testPased).toBe(true);
|
|
|
|
});
|
|
|
|
|
2020-01-15 20:33:23 +01:00
|
|
|
it('should handle generic class with brackets', function() {
|
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'class Dummy_Class~T~ {\n' +
|
|
|
|
'String data\n' +
|
|
|
|
' void methods()\n' +
|
|
|
|
'}\n' +
|
|
|
|
'\n' +
|
|
|
|
'class Flight {\n' +
|
|
|
|
' flightNumber : Integer\n' +
|
|
|
|
' departureTime : Date\n' +
|
|
|
|
'}';
|
2020-02-03 16:04:54 -08:00
|
|
|
|
|
|
|
parser.parse(str);
|
2019-12-05 12:55:46 -08:00
|
|
|
});
|
|
|
|
|
2019-09-12 12:58:32 -07:00
|
|
|
it('should handle class definitions', function() {
|
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'class Car\n' +
|
|
|
|
'Driver -- Car : drives >\n' +
|
|
|
|
'Car *-- Wheel : have 4 >\n' +
|
|
|
|
'Car -- Person : < owns';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
});
|
|
|
|
|
2019-11-25 17:15:57 -08:00
|
|
|
it('should handle method statements', function () {
|
2019-09-12 12:58:32 -07:00
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'Object <|-- ArrayList\n' +
|
|
|
|
'Object : equals()\n' +
|
|
|
|
'ArrayList : Object[] elementData\n' +
|
|
|
|
'ArrayList : size()';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
});
|
2019-11-26 11:18:32 -08:00
|
|
|
|
2020-01-06 16:21:11 -08:00
|
|
|
it('should handle parsing of method statements grouped by brackets', function () {
|
2019-09-12 12:58:32 -07:00
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
2019-10-29 17:39:15 +01:00
|
|
|
'class Dummy_Class {\n' +
|
2019-09-12 12:58:32 -07:00
|
|
|
'String data\n' +
|
|
|
|
' void methods()\n' +
|
|
|
|
'}\n' +
|
|
|
|
'\n' +
|
|
|
|
'class Flight {\n' +
|
|
|
|
' flightNumber : Integer\n' +
|
|
|
|
' departureTime : Date\n' +
|
|
|
|
'}';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
});
|
|
|
|
|
2020-01-06 16:21:11 -08:00
|
|
|
it('should handle return types on methods', function () {
|
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'Object <|-- ArrayList\n' +
|
|
|
|
'Object : equals()\n' +
|
|
|
|
'Object : -Object[] objects\n' +
|
|
|
|
'Object : +getObjects() Object[]\n' +
|
|
|
|
'ArrayList : Dummy elementData\n' +
|
|
|
|
'ArrayList : getDummy() Dummy';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle return types on methods grouped by brackets', function () {
|
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'class Dummy_Class {\n' +
|
|
|
|
'string data\n' +
|
|
|
|
'getDummy() Dummy\n' +
|
|
|
|
'}\n' +
|
|
|
|
'\n' +
|
|
|
|
'class Flight {\n' +
|
|
|
|
' int flightNumber\n' +
|
|
|
|
' datetime departureTime\n' +
|
|
|
|
' getDepartureTime() datetime\n' +
|
|
|
|
'}';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
});
|
|
|
|
|
2019-11-25 17:15:57 -08:00
|
|
|
it('should handle parsing of separators', function () {
|
2019-09-12 12:58:32 -07:00
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'class Foo1 {\n' +
|
|
|
|
' You can use\n' +
|
|
|
|
' several lines\n' +
|
|
|
|
'..\n' +
|
|
|
|
'as you want\n' +
|
|
|
|
'and group\n' +
|
|
|
|
'==\n' +
|
|
|
|
'things together.\n' +
|
|
|
|
'__\n' +
|
|
|
|
'You can have as many groups\n' +
|
|
|
|
'as you want\n' +
|
|
|
|
'--\n' +
|
|
|
|
'End of class\n' +
|
|
|
|
'}\n' +
|
|
|
|
'\n' +
|
|
|
|
'class User {\n' +
|
|
|
|
'.. Simple Getter ..\n' +
|
|
|
|
'+ getName()\n' +
|
|
|
|
'+ getAddress()\n' +
|
|
|
|
'.. Some setter ..\n' +
|
|
|
|
'+ setName()\n' +
|
|
|
|
'__ private data __\n' +
|
|
|
|
'int age\n' +
|
|
|
|
'-- encrypted --\n' +
|
|
|
|
'String password\n' +
|
|
|
|
'}';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
});
|
2019-11-26 11:18:32 -08:00
|
|
|
|
|
|
|
it('should handle a comment', function () {
|
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'class Class1 {\n' +
|
|
|
|
'%% Comment\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' +
|
|
|
|
'classDiagram\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 =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'class Class1 {\n' +
|
|
|
|
'int : test\n' +
|
|
|
|
'string : foo\n' +
|
|
|
|
'test()\n' +
|
|
|
|
'foo()\n' +
|
|
|
|
'}\n' +
|
|
|
|
'%% Comment';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle a comment with multiple line feeds', 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);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle a comment inside brackets', function () {
|
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'class Class1 {\n' +
|
|
|
|
'%% Comment Class01 <|-- Class02\n' +
|
|
|
|
'int : test\n' +
|
|
|
|
'string : foo\n' +
|
|
|
|
'test()\n' +
|
|
|
|
'foo()\n' +
|
|
|
|
'}';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
});
|
2019-12-30 17:24:19 -08:00
|
|
|
|
|
|
|
it('should handle click statement with link', function () {
|
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'class Class1 {\n' +
|
|
|
|
'%% Comment Class01 <|-- Class02\n' +
|
|
|
|
'int : test\n' +
|
|
|
|
'string : foo\n' +
|
|
|
|
'test()\n' +
|
|
|
|
'foo()\n' +
|
|
|
|
'}\n' +
|
|
|
|
'link Class01 "google.com" ';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle click statement with link and tooltip', function () {
|
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'class Class1 {\n' +
|
|
|
|
'%% Comment Class01 <|-- Class02\n' +
|
|
|
|
'int : test\n' +
|
|
|
|
'string : foo\n' +
|
|
|
|
'test()\n' +
|
|
|
|
'foo()\n' +
|
|
|
|
'}\n' +
|
|
|
|
'link Class01 "google.com" "A Tooltip" ';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle click statement with callback', function () {
|
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'class Class1 {\n' +
|
|
|
|
'%% Comment Class01 <|-- Class02\n' +
|
|
|
|
'int : test\n' +
|
|
|
|
'string : foo\n' +
|
|
|
|
'test()\n' +
|
|
|
|
'foo()\n' +
|
|
|
|
'}\n' +
|
|
|
|
'callback Class01 "functionCall" ';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle click statement with callback and tooltip', function () {
|
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'class Class1 {\n' +
|
|
|
|
'%% Comment Class01 <|-- Class02\n' +
|
|
|
|
'int : test\n' +
|
|
|
|
'string : foo\n' +
|
|
|
|
'test()\n' +
|
|
|
|
'foo()\n' +
|
|
|
|
'}\n' +
|
|
|
|
'callback Class01 "functionCall" "A Tooltip" ';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
});
|
2020-01-13 16:04:26 -08:00
|
|
|
|
2020-01-02 19:51:25 +01:00
|
|
|
it('should handle dashed relation definition of different types and directions', function () {
|
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'Class11 <|.. Class12\n' +
|
|
|
|
'Class13 <.. Class14\n' +
|
|
|
|
'Class15 ..|> Class16\n' +
|
|
|
|
'Class17 ..> Class18\n' +
|
|
|
|
'Class19 .. Class20';
|
|
|
|
parser.parse(str);
|
|
|
|
});
|
2020-01-13 16:04:26 -08:00
|
|
|
|
|
|
|
it('should handle generic types in members', function () {
|
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'class Car~T~\n' +
|
|
|
|
'Car : -List~Wheel~ wheels\n' +
|
|
|
|
'Car : +setWheels(List~Wheel~ wheels)\n' +
|
|
|
|
'Car : +getWheels() List~Wheel~';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle generic types in members in class with brackets', function () {
|
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'class Car {\n' +
|
|
|
|
'List~Wheel~ wheels\n' +
|
|
|
|
'setWheels(List~Wheel~ wheels)\n' +
|
|
|
|
'+getWheels() List~Wheel~\n' +
|
|
|
|
'}';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
});
|
2019-09-12 12:58:32 -07:00
|
|
|
});
|
|
|
|
|
2019-11-26 11:18:32 -08:00
|
|
|
describe('when fetching data from a classDiagram graph it', function () {
|
2019-11-25 17:15:57 -08:00
|
|
|
beforeEach(function () {
|
2019-09-12 12:58:32 -07:00
|
|
|
parser.yy = classDb;
|
|
|
|
parser.yy.clear();
|
|
|
|
});
|
2019-11-25 17:15:57 -08:00
|
|
|
it('should handle relation definitions EXTENSION', function () {
|
2019-09-12 12:58:32 -07:00
|
|
|
const str = 'classDiagram\n' + 'Class01 <|-- Class02';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
|
|
|
|
const relations = parser.yy.getRelations();
|
|
|
|
|
|
|
|
expect(parser.yy.getClass('Class01').id).toBe('Class01');
|
|
|
|
expect(parser.yy.getClass('Class02').id).toBe('Class02');
|
|
|
|
expect(relations[0].relation.type1).toBe(classDb.relationType.EXTENSION);
|
|
|
|
expect(relations[0].relation.type2).toBe('none');
|
|
|
|
expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE);
|
|
|
|
});
|
2019-11-26 11:18:32 -08:00
|
|
|
|
2019-11-25 17:15:57 -08:00
|
|
|
it('should handle relation definitions AGGREGATION and dotted line', function () {
|
2019-09-12 12:58:32 -07:00
|
|
|
const str = 'classDiagram\n' + 'Class01 o.. Class02';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
|
|
|
|
const relations = parser.yy.getRelations();
|
|
|
|
|
|
|
|
expect(parser.yy.getClass('Class01').id).toBe('Class01');
|
|
|
|
expect(parser.yy.getClass('Class02').id).toBe('Class02');
|
|
|
|
expect(relations[0].relation.type1).toBe(classDb.relationType.AGGREGATION);
|
|
|
|
expect(relations[0].relation.type2).toBe('none');
|
|
|
|
expect(relations[0].relation.lineType).toBe(classDb.lineType.DOTTED_LINE);
|
|
|
|
});
|
2019-11-26 11:18:32 -08:00
|
|
|
|
2019-11-25 17:15:57 -08:00
|
|
|
it('should handle relation definitions COMPOSITION on both sides', function () {
|
2019-09-12 12:58:32 -07:00
|
|
|
const str = 'classDiagram\n' + 'Class01 *--* Class02';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
|
|
|
|
const relations = parser.yy.getRelations();
|
|
|
|
|
|
|
|
expect(parser.yy.getClass('Class01').id).toBe('Class01');
|
|
|
|
expect(parser.yy.getClass('Class02').id).toBe('Class02');
|
|
|
|
expect(relations[0].relation.type1).toBe(classDb.relationType.COMPOSITION);
|
|
|
|
expect(relations[0].relation.type2).toBe(classDb.relationType.COMPOSITION);
|
|
|
|
expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE);
|
|
|
|
});
|
2019-11-26 11:18:32 -08:00
|
|
|
|
2019-11-25 17:15:57 -08:00
|
|
|
it('should handle relation definitions no types', function () {
|
2019-09-12 12:58:32 -07:00
|
|
|
const str = 'classDiagram\n' + 'Class01 -- Class02';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
|
|
|
|
const relations = parser.yy.getRelations();
|
|
|
|
|
|
|
|
expect(parser.yy.getClass('Class01').id).toBe('Class01');
|
|
|
|
expect(parser.yy.getClass('Class02').id).toBe('Class02');
|
|
|
|
expect(relations[0].relation.type1).toBe('none');
|
|
|
|
expect(relations[0].relation.type2).toBe('none');
|
|
|
|
expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE);
|
|
|
|
});
|
2019-11-26 11:18:32 -08:00
|
|
|
|
2019-11-25 17:15:57 -08:00
|
|
|
it('should handle relation definitions with type only on right side', function () {
|
2019-09-12 12:58:32 -07:00
|
|
|
const str = 'classDiagram\n' + 'Class01 --|> Class02';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
|
|
|
|
const relations = parser.yy.getRelations();
|
|
|
|
|
|
|
|
expect(parser.yy.getClass('Class01').id).toBe('Class01');
|
|
|
|
expect(parser.yy.getClass('Class02').id).toBe('Class02');
|
|
|
|
expect(relations[0].relation.type1).toBe('none');
|
|
|
|
expect(relations[0].relation.type2).toBe(classDb.relationType.EXTENSION);
|
|
|
|
expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE);
|
|
|
|
});
|
|
|
|
|
2019-11-25 17:15:57 -08:00
|
|
|
it('should handle multiple classes and relation definitions', function () {
|
2019-09-12 12:58:32 -07:00
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'Class01 <|-- Class02\n' +
|
|
|
|
'Class03 *-- Class04\n' +
|
|
|
|
'Class05 o-- Class06\n' +
|
|
|
|
'Class07 .. Class08\n' +
|
|
|
|
'Class09 -- Class10';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
|
|
|
|
const relations = parser.yy.getRelations();
|
|
|
|
|
|
|
|
expect(parser.yy.getClass('Class01').id).toBe('Class01');
|
|
|
|
expect(parser.yy.getClass('Class10').id).toBe('Class10');
|
|
|
|
|
|
|
|
expect(relations.length).toBe(5);
|
|
|
|
|
|
|
|
expect(relations[0].relation.type1).toBe(classDb.relationType.EXTENSION);
|
|
|
|
expect(relations[0].relation.type2).toBe('none');
|
|
|
|
expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE);
|
|
|
|
expect(relations[3].relation.type1).toBe('none');
|
|
|
|
expect(relations[3].relation.type2).toBe('none');
|
|
|
|
expect(relations[3].relation.lineType).toBe(classDb.lineType.DOTTED_LINE);
|
|
|
|
});
|
2019-10-04 23:49:58 +02:00
|
|
|
|
2019-12-05 12:55:46 -08:00
|
|
|
it('should handle generic class with relation definitions', function () {
|
|
|
|
const str = 'classDiagram\n' + 'Class01~T~ <|-- Class02';
|
|
|
|
|
|
|
|
parser.parse(str);
|
|
|
|
|
|
|
|
const relations = parser.yy.getRelations();
|
|
|
|
|
|
|
|
expect(parser.yy.getClass('Class01').id).toBe('Class01');
|
2019-12-10 11:39:25 -08:00
|
|
|
expect(parser.yy.getClass('Class01').type).toBe('T');
|
2019-12-05 12:55:46 -08:00
|
|
|
expect(parser.yy.getClass('Class02').id).toBe('Class02');
|
|
|
|
expect(relations[0].relation.type1).toBe(classDb.relationType.EXTENSION);
|
|
|
|
expect(relations[0].relation.type2).toBe('none');
|
|
|
|
expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE);
|
|
|
|
});
|
|
|
|
|
2019-11-25 17:15:57 -08:00
|
|
|
it('should handle class annotations', function () {
|
2019-10-04 23:49:58 +02:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2019-11-25 17:15:57 -08:00
|
|
|
it('should handle class annotations with members and methods', function () {
|
2019-10-04 23:49:58 +02:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2019-11-25 17:15:57 -08:00
|
|
|
it('should handle class annotations in brackets', function () {
|
2019-10-04 23:49:58 +02:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2019-11-25 17:15:57 -08:00
|
|
|
it('should handle class annotations in brackets with members and methods', function () {
|
2019-10-04 23:49:58 +02:00
|
|
|
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');
|
|
|
|
});
|
2019-10-08 22:57:40 +02:00
|
|
|
|
2019-11-25 17:15:57 -08:00
|
|
|
it('should add bracket members in right order', function () {
|
2019-10-08 22:57:40 +02:00
|
|
|
const str =
|
|
|
|
'classDiagram\n' +
|
|
|
|
'class Class1 {\n' +
|
|
|
|
'int : test\n' +
|
|
|
|
'string : foo\n' +
|
|
|
|
'test()\n' +
|
|
|
|
'foo()\n' +
|
|
|
|
'}';
|
|
|
|
parser.parse(str);
|
|
|
|
|
|
|
|
const testClass = parser.yy.getClass('Class1');
|
|
|
|
expect(testClass.members.length).toBe(2);
|
|
|
|
expect(testClass.methods.length).toBe(2);
|
|
|
|
expect(testClass.members[0]).toBe('int : test');
|
|
|
|
expect(testClass.members[1]).toBe('string : foo');
|
|
|
|
expect(testClass.methods[0]).toBe('test()');
|
|
|
|
expect(testClass.methods[1]).toBe('foo()');
|
|
|
|
});
|
2019-12-09 17:41:26 -08:00
|
|
|
|
|
|
|
it('should handle abstract methods', function () {
|
2019-12-09 18:13:06 -08:00
|
|
|
const str = 'classDiagram\n' + 'class Class1\n' + 'Class1 : someMethod()*';
|
2019-12-09 17:41:26 -08:00
|
|
|
parser.parse(str);
|
|
|
|
|
|
|
|
const testClass = parser.yy.getClass('Class1');
|
|
|
|
expect(testClass.annotations.length).toBe(0);
|
|
|
|
expect(testClass.members.length).toBe(0);
|
|
|
|
expect(testClass.methods.length).toBe(1);
|
2019-12-09 18:13:06 -08:00
|
|
|
expect(testClass.methods[0]).toBe('someMethod()*');
|
2019-12-09 17:41:26 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle static methods', function () {
|
2019-12-09 18:13:06 -08:00
|
|
|
const str = 'classDiagram\n' + 'class Class1\n' + 'Class1 : someMethod()$';
|
2019-12-09 17:41:26 -08:00
|
|
|
parser.parse(str);
|
|
|
|
|
|
|
|
const testClass = parser.yy.getClass('Class1');
|
|
|
|
expect(testClass.annotations.length).toBe(0);
|
|
|
|
expect(testClass.members.length).toBe(0);
|
|
|
|
expect(testClass.methods.length).toBe(1);
|
2019-12-09 18:13:06 -08:00
|
|
|
expect(testClass.methods[0]).toBe('someMethod()$');
|
2019-12-09 17:41:26 -08:00
|
|
|
});
|
2019-12-30 17:24:19 -08:00
|
|
|
|
|
|
|
it('should associate link and css appropriately', function () {
|
|
|
|
const str = 'classDiagram\n' + 'class Class1\n' + 'Class1 : someMethod()\n' + 'link Class1 "google.com"';
|
|
|
|
parser.parse(str);
|
|
|
|
|
|
|
|
const testClass = parser.yy.getClass('Class1');
|
|
|
|
expect(testClass.link).toBe('about:blank');//('google.com'); security needs to be set to 'loose' for this to work right
|
|
|
|
expect(testClass.cssClasses.length).toBe(1);
|
|
|
|
expect(testClass.cssClasses[0]).toBe('clickable');
|
|
|
|
});
|
2020-01-13 16:04:26 -08:00
|
|
|
|
2019-12-30 17:24:19 -08:00
|
|
|
it('should associate link with tooltip', function () {
|
|
|
|
const str = 'classDiagram\n' + 'class Class1\n' + 'Class1 : someMethod()\n' + 'link Class1 "google.com" "A tooltip"';
|
|
|
|
parser.parse(str);
|
|
|
|
|
|
|
|
const testClass = parser.yy.getClass('Class1');
|
|
|
|
expect(testClass.link).toBe('about:blank');//('google.com'); security needs to be set to 'loose' for this to work right
|
|
|
|
expect(testClass.tooltip).toBe('A tooltip');
|
|
|
|
expect(testClass.cssClasses.length).toBe(1);
|
|
|
|
expect(testClass.cssClasses[0]).toBe('clickable');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should associate callback appropriately', function () {
|
|
|
|
spyOn(classDb, 'setClickEvent');
|
|
|
|
const str = 'classDiagram\n' + 'class Class1\n' + 'Class1 : someMethod()\n' + 'callback Class1 "functionCall"';
|
|
|
|
parser.parse(str);
|
|
|
|
|
|
|
|
expect(classDb.setClickEvent).toHaveBeenCalledWith('Class1', 'functionCall', undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should associate callback with tooltip', function () {
|
|
|
|
spyOn(classDb, 'setClickEvent');
|
|
|
|
const str = 'classDiagram\n' + 'class Class1\n' + 'Class1 : someMethod()\n' + 'callback Class1 "functionCall" "A tooltip"';
|
|
|
|
parser.parse(str);
|
|
|
|
|
|
|
|
expect(classDb.setClickEvent).toHaveBeenCalledWith('Class1', 'functionCall', 'A tooltip');
|
|
|
|
});
|
2019-09-12 12:58:32 -07:00
|
|
|
});
|
|
|
|
});
|