mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-12-12 07:24:22 +01:00
Merge pull request #4597 from ibrahimWassouf/bug/4590_allow_notes_identical_to_keywords
Bug/4590 allow notes identical to keywords
This commit is contained in:
@@ -264,6 +264,113 @@ class C13["With Città foreign language"]
|
||||
const str = 'classDiagram\n' + 'note "test"\n';
|
||||
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 () {
|
||||
|
||||
@@ -50,6 +50,25 @@ accDescr\s*"{"\s* { this.begin("acc_descr_multili
|
||||
"classDiagram" return 'CLASS_DIAGRAM';
|
||||
"[*]" 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'; }
|
||||
<namespace>\s*(\r?\n)+ { this.popState(); return 'NEWLINE'; }
|
||||
<namespace>\s+ /* skip whitespace */
|
||||
@@ -87,32 +106,11 @@ accDescr\s*"{"\s* { this.begin("acc_descr_multili
|
||||
line was introduced with 'click'.
|
||||
'href "<link>"' attaches the specified link to the node that was specified by 'click'.
|
||||
*/
|
||||
<*>"href"[\s]+["] this.begin("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';
|
||||
<*>"href" return 'HREF';
|
||||
|
||||
<generic>[~] this.popState();
|
||||
<generic>[^~]* return "GENERICTYPE";
|
||||
<*>[~] this.begin("generic");
|
||||
|
||||
<string>["] this.popState();
|
||||
<string>[^"]* return "STR";
|
||||
<*>["] this.begin("string");
|
||||
<*>"~" this.begin("generic");
|
||||
|
||||
<bqstring>[`] this.popState();
|
||||
<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 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 HREF {$$ = $1;yy.setLink($2, $3);}
|
||||
| CLICK className HREF LINK_TARGET {$$ = $1;yy.setLink($2, $3, $4);}
|
||||
| CLICK className HREF STR {$$ = $1;yy.setLink($2, $3);yy.setTooltip($2, $4);}
|
||||
| CLICK className HREF STR LINK_TARGET {$$ = $1;yy.setLink($2, $3, $5);yy.setTooltip($2, $4);}
|
||||
| CLICK className HREF STR {$$ = $1;yy.setLink($2, $4);}
|
||||
| CLICK className HREF STR LINK_TARGET {$$ = $1;yy.setLink($2, $4, $5);}
|
||||
| CLICK className HREF STR STR {$$ = $1;yy.setLink($2, $4);yy.setTooltip($2, $5);}
|
||||
| CLICK className HREF STR STR LINK_TARGET {$$ = $1;yy.setLink($2, $4, $6);yy.setTooltip($2, $5);}
|
||||
;
|
||||
|
||||
cssClassStatement
|
||||
|
||||
@@ -30,7 +30,7 @@ accDescr\s*"{"\s* { this.begin("acc_descr_multili
|
||||
<block>\s+ /* skip whitespace in block */
|
||||
<block>\b((?:PK)|(?:FK)|(?:UK))\b return 'ATTRIBUTE_KEY'
|
||||
<block>(.*?)[~](.*?)*[~] return 'ATTRIBUTE_WORD';
|
||||
<block>[A-Za-z_][A-Za-z0-9\-_\[\]\(\)]* return 'ATTRIBUTE_WORD'
|
||||
<block>[\*A-Za-z_][A-Za-z0-9\-_\[\]\(\)]* return 'ATTRIBUTE_WORD'
|
||||
<block>\"[^"]*\" return 'COMMENT';
|
||||
<block>[\n]+ /* nothing */
|
||||
<block>"}" { this.popState(); return 'BLOCK_STOP'; }
|
||||
|
||||
@@ -154,6 +154,16 @@ describe('when parsing ER diagram it...', function () {
|
||||
expect(entities[entity].attributes[2].attributeName).toBe('author-ref[name](1)');
|
||||
});
|
||||
|
||||
it('should allow asterisk at the start of title', function () {
|
||||
const entity = 'BOOK';
|
||||
const attribute = 'string *title';
|
||||
|
||||
erDiagram.parser.parse(`erDiagram\n${entity}{${attribute}}`);
|
||||
const entities = erDb.getEntities();
|
||||
expect(Object.keys(entities).length).toBe(1);
|
||||
expect(entities[entity].attributes.length).toBe(1);
|
||||
});
|
||||
|
||||
it('should not allow leading numbers, dashes or brackets', function () {
|
||||
const entity = 'BOOK';
|
||||
const nonLeadingChars = '0-[]()';
|
||||
|
||||
Reference in New Issue
Block a user