Merge branch 'develop' into enhancement/4158_Add_primary_key_beginning_with_asterisk

This commit is contained in:
Ibrahim Wassouf
2023-07-11 20:04:20 -03:00
3 changed files with 209 additions and 118 deletions

View File

@@ -264,6 +264,113 @@ class C13["With Città foreign language"]
const str = 'classDiagram\n' + 'note "test"\n'; const str = 'classDiagram\n' + 'note "test"\n';
parser.parse(str); parser.parse(str);
}); });
const keywords = [
'direction',
'classDiagram',
'classDiagram-v2',
'namespace',
'{}',
'{',
'}',
'()',
'(',
')',
'[]',
'[',
']',
'class',
'\n',
'cssClass',
'callback',
'link',
'click',
'note',
'note for',
'<<',
'>>',
'call ',
'~',
'~Generic~',
'_self',
'_blank',
'_parent',
'_top',
'<|',
'|>',
'>',
'<',
'*',
'o',
'\\',
'--',
'..',
'-->',
'--|>',
': label',
':::',
'.',
'+',
'alphaNum',
'!',
'0123',
'function()',
'function(arg1, arg2)',
];
it.each(keywords)('should handle a note with %s in it', function (keyword: string) {
const str = `classDiagram
note "This is a keyword: ${keyword}. It truly is."
`;
parser.parse(str);
expect(classDb.getNotes()[0].text).toEqual(`This is a keyword: ${keyword}. It truly is.`);
});
it.each(keywords)(
'should handle note with %s at beginning of string',
function (keyword: string) {
const str = `classDiagram
note "${keyword}"`;
parser.parse(str);
expect(classDb.getNotes()[0].text).toEqual(`${keyword}`);
}
);
it.each(keywords)('should handle a "note for" with a %s in it', function (keyword: string) {
const str = `classDiagram
class Something {
int id
string name
}
note for Something "This is a keyword: ${keyword}. It truly is."
`;
parser.parse(str);
expect(classDb.getNotes()[0].text).toEqual(`This is a keyword: ${keyword}. It truly is.`);
});
it.each(keywords)(
'should handle a "note for" with a %s at beginning of string',
function (keyword: string) {
const str = `classDiagram
class Something {
int id
string name
}
note for Something "${keyword}"
`;
parser.parse(str);
expect(classDb.getNotes()[0].text).toEqual(`${keyword}`);
}
);
it.each(keywords)('should elicit error for %s after NOTE token', function (keyword: string) {
const str = `classDiagram
note ${keyword}`;
expect(() => parser.parse(str)).toThrowError(/(Expecting\s'STR'|Unrecognized\stext)/);
});
}); });
describe('when parsing class defined in brackets', function () { describe('when parsing class defined in brackets', function () {

View File

@@ -50,6 +50,25 @@ accDescr\s*"{"\s* { this.begin("acc_descr_multili
"classDiagram" return 'CLASS_DIAGRAM'; "classDiagram" return 'CLASS_DIAGRAM';
"[*]" return 'EDGE_STATE'; "[*]" return 'EDGE_STATE';
/*
---interactivity command---
'call' adds a callback to the specified node. 'call' can only be specified when
the line was introduced with 'click'.
'call <callback_name>(<callback_args>)' attaches the function 'callback_name' with the specified
arguments to the node that was specified by 'click'.
Function arguments are optional: 'call <callback_name>()' simply executes 'callback_name' without any arguments.
*/
<INITIAL>"call"[\s]+ this.begin("callback_name");
<callback_name>\([\s]*\) this.popState();
<callback_name>\( this.popState(); this.begin("callback_args");
<callback_name>[^(]* return 'CALLBACK_NAME';
<callback_args>\) this.popState();
<callback_args>[^)]* return 'CALLBACK_ARGS';
<string>["] this.popState();
<string>[^"]* return "STR";
<*>["] this.begin("string");
<INITIAL,namespace>"namespace" { this.begin('namespace'); return 'NAMESPACE'; } <INITIAL,namespace>"namespace" { this.begin('namespace'); return 'NAMESPACE'; }
<namespace>\s*(\r?\n)+ { this.popState(); return 'NEWLINE'; } <namespace>\s*(\r?\n)+ { this.popState(); return 'NEWLINE'; }
<namespace>\s+ /* skip whitespace */ <namespace>\s+ /* skip whitespace */
@@ -87,32 +106,11 @@ accDescr\s*"{"\s* { this.begin("acc_descr_multili
line was introduced with 'click'. line was introduced with 'click'.
'href "<link>"' attaches the specified link to the node that was specified by 'click'. 'href "<link>"' attaches the specified link to the node that was specified by 'click'.
*/ */
<*>"href"[\s]+["] this.begin("href"); <*>"href" return 'HREF';
<href>["] this.popState();
<href>[^"]* return 'HREF';
/*
---interactivity command---
'call' adds a callback to the specified node. 'call' can only be specified when
the line was introduced with 'click'.
'call <callback_name>(<callback_args>)' attaches the function 'callback_name' with the specified
arguments to the node that was specified by 'click'.
Function arguments are optional: 'call <callback_name>()' simply executes 'callback_name' without any arguments.
*/
<*>"call"[\s]+ this.begin("callback_name");
<callback_name>\([\s]*\) this.popState();
<callback_name>\( this.popState(); this.begin("callback_args");
<callback_name>[^(]* return 'CALLBACK_NAME';
<callback_args>\) this.popState();
<callback_args>[^)]* return 'CALLBACK_ARGS';
<generic>[~] this.popState(); <generic>[~] this.popState();
<generic>[^~]* return "GENERICTYPE"; <generic>[^~]* return "GENERICTYPE";
<*>[~] this.begin("generic"); <*>"~" this.begin("generic");
<string>["] this.popState();
<string>[^"]* return "STR";
<*>["] this.begin("string");
<bqstring>[`] this.popState(); <bqstring>[`] this.popState();
<bqstring>[^`]+ return "BQUOTE_STR"; <bqstring>[^`]+ return "BQUOTE_STR";
@@ -391,10 +389,10 @@ clickStatement
| CLICK className CALLBACK_NAME STR {$$ = $1;yy.setClickEvent($2, $3);yy.setTooltip($2, $4);} | CLICK className CALLBACK_NAME STR {$$ = $1;yy.setClickEvent($2, $3);yy.setTooltip($2, $4);}
| CLICK className CALLBACK_NAME CALLBACK_ARGS {$$ = $1;yy.setClickEvent($2, $3, $4);} | CLICK className CALLBACK_NAME CALLBACK_ARGS {$$ = $1;yy.setClickEvent($2, $3, $4);}
| CLICK className CALLBACK_NAME CALLBACK_ARGS STR {$$ = $1;yy.setClickEvent($2, $3, $4);yy.setTooltip($2, $5);} | CLICK className CALLBACK_NAME CALLBACK_ARGS STR {$$ = $1;yy.setClickEvent($2, $3, $4);yy.setTooltip($2, $5);}
| CLICK className HREF {$$ = $1;yy.setLink($2, $3);} | CLICK className HREF STR {$$ = $1;yy.setLink($2, $4);}
| CLICK className HREF LINK_TARGET {$$ = $1;yy.setLink($2, $3, $4);} | CLICK className HREF STR LINK_TARGET {$$ = $1;yy.setLink($2, $4, $5);}
| CLICK className HREF STR {$$ = $1;yy.setLink($2, $3);yy.setTooltip($2, $4);} | CLICK className HREF STR STR {$$ = $1;yy.setLink($2, $4);yy.setTooltip($2, $5);}
| CLICK className HREF STR LINK_TARGET {$$ = $1;yy.setLink($2, $3, $5);yy.setTooltip($2, $4);} | CLICK className HREF STR STR LINK_TARGET {$$ = $1;yy.setLink($2, $4, $6);yy.setTooltip($2, $5);}
; ;
cssClassStatement cssClassStatement

View File

@@ -63,20 +63,6 @@ export const draw = function (text, id, _version, diagObj) {
const diagram = root.select(`[id='${id}']`); const diagram = root.select(`[id='${id}']`);
insertMarkers(diagram); insertMarkers(diagram);
// Layout graph, Create a new directed graph
const graph = new graphlib.Graph({
multigraph: true,
compound: true,
// acyclicer: 'greedy',
rankdir: 'RL',
// ranksep: '20'
});
// Default to assigning a new object as a label for each new edge.
graph.setDefaultEdgeLabel(function () {
return {};
});
const rootDoc = diagObj.db.getRootDoc(); const rootDoc = diagObj.db.getRootDoc();
renderDoc(rootDoc, diagram, undefined, false, root, doc, diagObj); renderDoc(rootDoc, diagram, undefined, false, root, doc, diagObj);