mermaid/src/diagrams/classDiagram/classDiagram.spec.js

125 lines
2.8 KiB
JavaScript
Raw Normal View History

/**
* 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 () {
var ex, cd;
beforeEach(function () {
cd = require('./parser/classDiagram').parser;
cd.yy = require('./classDb');
2015-10-25 18:09:58 +01:00
});
2015-10-25 18:09:58 +01:00
it('should handle relation definitions', function () {
var str = `classDiagram
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
Class11 <|.. Class12
Class13 --> Class14
Class15 ..> Class16
Class17 ..|> Class18
Class19 <--* Class20`;
2015-10-25 18:09:58 +01:00
cd.parse(str);
});
2015-10-25 18:09:58 +01:00
it('should handle cardinality and labels', function () {
var str = `classDiagram
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
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 18:09:58 +01:00
it('should handle method statements', function () {
var str = `classDiagram
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 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);
});
});
describe('when fetchiing data an classDiagram graph it', function () {
var ex, cd;
beforeEach(function () {
cd = require('./parser/classDiagram').parser;
cd.yy = require('./classDb');
cd.yy.clear();
});
it('should handle relation definitions', function () {
var str = `classDiagram
Class01 <|-- Class02`;
cd.parse(str);
expect(cd.yy.getClass('Class01').id).toBe('Class01');
expect(cd.yy.getClass('Class02').id).toBe('Class02');
});
});
});