2015-10-25 11:35:26 +01:00
|
|
|
/**
|
|
|
|
* Created by knut on 14-11-18.
|
|
|
|
*/
|
2015-10-25 18:09:58 +01:00
|
|
|
describe('class diagram, ', function () {
|
|
|
|
describe('when parsing an info graph it', function () {
|
2015-10-29 07:49:08 +01:00
|
|
|
var cd, cDDb;
|
2015-10-25 18:09:58 +01:00
|
|
|
beforeEach(function () {
|
|
|
|
cd = require('./parser/classDiagram').parser;
|
2015-10-29 07:49:08 +01:00
|
|
|
cDDb = require('./classDb');
|
|
|
|
cd.yy = cDDb;
|
2015-10-25 18:09:58 +01:00
|
|
|
});
|
2015-10-25 11:35:26 +01:00
|
|
|
|
2015-10-25 18:09:58 +01:00
|
|
|
it('should handle relation definitions', function () {
|
|
|
|
var str = `classDiagram
|
2015-10-25 11:35:26 +01:00
|
|
|
Class01 <|-- Class02
|
|
|
|
Class03 *-- Class04
|
|
|
|
Class05 o-- Class06
|
|
|
|
Class07 .. Class08
|
|
|
|
Class09 -- Class1`;
|
|
|
|
|
2015-10-25 18:09:58 +01:00
|
|
|
cd.parse(str);
|
|
|
|
});
|
|
|
|
it('should handle relation definition of different types and directions', function () {
|
|
|
|
var str = `classDiagram
|
2015-10-25 11:35:26 +01:00
|
|
|
Class11 <|.. Class12
|
|
|
|
Class13 --> Class14
|
|
|
|
Class15 ..> Class16
|
|
|
|
Class17 ..|> Class18
|
|
|
|
Class19 <--* Class20`;
|
|
|
|
|
2015-10-25 18:09:58 +01:00
|
|
|
cd.parse(str);
|
|
|
|
});
|
2015-10-25 11:35:26 +01:00
|
|
|
|
2015-10-25 18:09:58 +01:00
|
|
|
it('should handle cardinality and labels', function () {
|
|
|
|
var str = `classDiagram
|
2015-10-25 11:35:26 +01:00
|
|
|
Class01 "1" *-- "many" Class02 : contains
|
|
|
|
Class03 o-- Class04 : aggregation
|
|
|
|
Class05 --> "1" Class06`;
|
|
|
|
|
2015-10-25 18:09:58 +01:00
|
|
|
cd.parse(str);
|
|
|
|
});
|
|
|
|
it('should handle class definitions', function () {
|
|
|
|
var str = `classDiagram
|
2015-10-25 11:35:26 +01:00
|
|
|
class Car
|
|
|
|
Driver -- Car : drives >
|
|
|
|
Car *-- Wheel : have 4 >
|
|
|
|
Car -- Person : < owns`;
|
|
|
|
|
2015-10-25 18:09:58 +01:00
|
|
|
cd.parse(str);
|
|
|
|
});
|
2015-10-25 11:35:26 +01:00
|
|
|
|
2015-10-25 18:09:58 +01:00
|
|
|
it('should handle method statements', function () {
|
|
|
|
var str = `classDiagram
|
2015-10-25 11:35:26 +01:00
|
|
|
Object <|-- ArrayList
|
|
|
|
Object : equals()
|
|
|
|
ArrayList : Object[] elementData
|
|
|
|
ArrayList : size()`;
|
|
|
|
|
2015-10-25 18:09:58 +01:00
|
|
|
cd.parse(str);
|
|
|
|
});
|
|
|
|
it('should handle parsing of method statements grouped by brackets', function () {
|
|
|
|
var str = `classDiagram
|
|
|
|
class Dummy {
|
|
|
|
String data
|
|
|
|
void methods()
|
|
|
|
}
|
2015-10-25 11:35:26 +01:00
|
|
|
|
2015-10-25 18:09:58 +01:00
|
|
|
class Flight {
|
|
|
|
flightNumber : Integer
|
|
|
|
departureTime : Date
|
|
|
|
}`;
|
|
|
|
|
|
|
|
cd.parse(str);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle parsing of separators', function () {
|
|
|
|
var str = `classDiagram
|
|
|
|
class Foo1 {
|
|
|
|
You can use
|
|
|
|
several lines
|
|
|
|
..
|
|
|
|
as you want
|
|
|
|
and group
|
|
|
|
==
|
|
|
|
things together.
|
|
|
|
__
|
|
|
|
You can have as many groups
|
|
|
|
as you want
|
|
|
|
--
|
|
|
|
End of class
|
|
|
|
}
|
|
|
|
|
|
|
|
class User {
|
|
|
|
.. Simple Getter ..
|
|
|
|
+ getName()
|
|
|
|
+ getAddress()
|
|
|
|
.. Some setter ..
|
|
|
|
+ setName()
|
|
|
|
__ private data __
|
|
|
|
int age
|
|
|
|
-- encrypted --
|
|
|
|
String password
|
|
|
|
}`;
|
|
|
|
|
|
|
|
cd.parse(str);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2015-10-28 08:12:47 +01:00
|
|
|
|
2015-10-29 07:49:08 +01:00
|
|
|
describe('when fetching data from an classDiagram graph it', function () {
|
|
|
|
var cd, cDDb;
|
2015-10-28 08:12:47 +01:00
|
|
|
beforeEach(function () {
|
|
|
|
cd = require('./parser/classDiagram').parser;
|
2015-10-29 07:49:08 +01:00
|
|
|
cDDb = require('./classDb');
|
|
|
|
cd.yy = cDDb;
|
2015-10-28 08:12:47 +01:00
|
|
|
cd.yy.clear();
|
|
|
|
});
|
2015-10-29 07:49:08 +01:00
|
|
|
it('should handle relation definitions EXTENSION', function () {
|
|
|
|
var str = `classDiagram
|
|
|
|
Class01 <|-- Class02`;
|
|
|
|
|
|
|
|
cd.parse(str);
|
|
|
|
|
|
|
|
var relations = cd.yy.getRelations();
|
|
|
|
|
|
|
|
expect(cd.yy.getClass('Class01').id).toBe('Class01');
|
|
|
|
expect(cd.yy.getClass('Class02').id).toBe('Class02');
|
|
|
|
expect(relations[0].relation.type1).toBe(cDDb.relationType.EXTENSION);
|
|
|
|
expect(relations[0].relation.type2).toBe('none');
|
|
|
|
expect(relations[0].relation.lineType).toBe(cDDb.lineType.LINE);
|
|
|
|
});
|
|
|
|
it('should handle relation definitions AGGREGATION and dotted line', function () {
|
2015-10-28 08:12:47 +01:00
|
|
|
var str = `classDiagram
|
2015-10-29 07:49:08 +01:00
|
|
|
Class01 o.. Class02`;
|
2015-10-28 08:12:47 +01:00
|
|
|
|
|
|
|
cd.parse(str);
|
2015-10-29 07:49:08 +01:00
|
|
|
|
|
|
|
var relations = cd.yy.getRelations();
|
|
|
|
|
2015-10-28 08:12:47 +01:00
|
|
|
expect(cd.yy.getClass('Class01').id).toBe('Class01');
|
|
|
|
expect(cd.yy.getClass('Class02').id).toBe('Class02');
|
2015-10-29 07:49:08 +01:00
|
|
|
expect(relations[0].relation.type1).toBe(cDDb.relationType.AGGREGATION);
|
|
|
|
expect(relations[0].relation.type2).toBe('none');
|
|
|
|
expect(relations[0].relation.lineType).toBe(cDDb.lineType.DOTTED_LINE);
|
|
|
|
});
|
|
|
|
it('should handle relation definitions COMPOSITION on both sides', function () {
|
|
|
|
var str = `classDiagram
|
|
|
|
Class01 *--* Class02`;
|
|
|
|
|
|
|
|
cd.parse(str);
|
|
|
|
|
|
|
|
var relations = cd.yy.getRelations();
|
|
|
|
|
|
|
|
expect(cd.yy.getClass('Class01').id).toBe('Class01');
|
|
|
|
expect(cd.yy.getClass('Class02').id).toBe('Class02');
|
|
|
|
expect(relations[0].relation.type1).toBe(cDDb.relationType.COMPOSITION);
|
|
|
|
expect(relations[0].relation.type2).toBe(cDDb.relationType.COMPOSITION);
|
|
|
|
expect(relations[0].relation.lineType).toBe(cDDb.lineType.LINE);
|
|
|
|
});
|
|
|
|
it('should handle relation definitions no types', function () {
|
|
|
|
var str = `classDiagram
|
|
|
|
Class01 -- Class02`;
|
|
|
|
|
|
|
|
cd.parse(str);
|
|
|
|
|
|
|
|
var relations = cd.yy.getRelations();
|
|
|
|
|
|
|
|
expect(cd.yy.getClass('Class01').id).toBe('Class01');
|
|
|
|
expect(cd.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(cDDb.lineType.LINE);
|
|
|
|
});
|
|
|
|
it('should handle relation definitions with type only on right side', function () {
|
|
|
|
var str = `classDiagram
|
|
|
|
Class01 --|> Class02`;
|
|
|
|
|
|
|
|
cd.parse(str);
|
|
|
|
|
|
|
|
var relations = cd.yy.getRelations();
|
|
|
|
|
|
|
|
expect(cd.yy.getClass('Class01').id).toBe('Class01');
|
|
|
|
expect(cd.yy.getClass('Class02').id).toBe('Class02');
|
|
|
|
expect(relations[0].relation.type1).toBe('none');
|
|
|
|
expect(relations[0].relation.type2).toBe(cDDb.relationType.EXTENSION);
|
|
|
|
expect(relations[0].relation.lineType).toBe(cDDb.lineType.LINE);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle multiple classes and relation definitions', function () {
|
|
|
|
var str = `classDiagram
|
|
|
|
Class01 <|-- Class02
|
|
|
|
Class03 *-- Class04
|
|
|
|
Class05 o-- Class06
|
|
|
|
Class07 .. Class08
|
|
|
|
Class09 -- Class10`;
|
|
|
|
|
|
|
|
cd.parse(str);
|
|
|
|
|
|
|
|
var relations = cd.yy.getRelations();
|
|
|
|
|
|
|
|
expect(cd.yy.getClass('Class01').id).toBe('Class01');
|
|
|
|
expect(cd.yy.getClass('Class10').id).toBe('Class10');
|
|
|
|
|
|
|
|
expect(relations.length).toBe(5);
|
|
|
|
|
|
|
|
expect(relations[0].relation.type1).toBe(cDDb.relationType.EXTENSION);
|
|
|
|
expect(relations[0].relation.type2).toBe('none');
|
|
|
|
expect(relations[0].relation.lineType).toBe(cDDb.lineType.LINE);
|
|
|
|
expect(relations[3].relation.type1).toBe('none');
|
|
|
|
expect(relations[3].relation.type2).toBe('none');
|
|
|
|
expect(relations[3].relation.lineType).toBe(cDDb.lineType.DOTTED_LINE);
|
2015-10-28 08:12:47 +01:00
|
|
|
});
|
|
|
|
});
|
2015-10-25 11:35:26 +01:00
|
|
|
});
|