mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-17 11:14:12 +01:00
feat: #2685 Support class member initialization by member definition
This commit is contained in:
@@ -174,6 +174,8 @@ export const addAnnotation = function (className: string, annotation: string) {
|
|||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export const addMember = function (className: string, member: string) {
|
export const addMember = function (className: string, member: string) {
|
||||||
|
addClass(className);
|
||||||
|
|
||||||
const validatedClassName = splitClassNameAndType(className).className;
|
const validatedClassName = splitClassNameAndType(className).className;
|
||||||
const theClass = classes[validatedClassName];
|
const theClass = classes[validatedClassName];
|
||||||
|
|
||||||
|
|||||||
@@ -742,6 +742,22 @@ describe('given a class diagram with members and methods ', function () {
|
|||||||
parser.parse(str);
|
parser.parse(str);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle direct member declaration', function () {
|
||||||
|
const str = 'classDiagram\n' + 'Car : wheels';
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
expect(classDb.getClasses()).toHaveProperty('Car');
|
||||||
|
expect(classDb.getClasses()['Car']['members']).toContain('wheels');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle direct member declaration with type', function () {
|
||||||
|
const str = 'classDiagram\n' + 'Car : int wheels';
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
expect(classDb.getClasses()).toHaveProperty('Car');
|
||||||
|
expect(classDb.getClasses()['Car']['members']).toContain('int wheels');
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle simple member declaration with type', function () {
|
it('should handle simple member declaration with type', function () {
|
||||||
const str = 'classDiagram\n' + 'class Car\n' + 'Car : int wheels';
|
const str = 'classDiagram\n' + 'class Car\n' + 'Car : int wheels';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user