mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Merge pull request #1425 from spopida/bug/1415_erd_empty_label_not_working
Ensure empty quoted relationship labels are accepted in ER diagrams
This commit is contained in:
commit
7a7e8fe741
@ -88,4 +88,17 @@ describe('Entity Relationship Diagram', () => {
|
||||
);
|
||||
cy.get('svg');
|
||||
});
|
||||
|
||||
it('should render an ER diagram with blank or empty labels', () => {
|
||||
imgSnapshotTest(
|
||||
`
|
||||
erDiagram
|
||||
BOOK }|..|{ AUTHOR : ""
|
||||
BOOK }|..|{ GENRE : " "
|
||||
AUTHOR }|..|{ GENRE : " "
|
||||
`,
|
||||
{logLevel : 1}
|
||||
);
|
||||
cy.get('svg');
|
||||
});
|
||||
});
|
||||
|
@ -1,14 +1,11 @@
|
||||
%lex
|
||||
|
||||
%x string
|
||||
%options case-insensitive
|
||||
|
||||
%%
|
||||
\s+ /* skip whitespace */
|
||||
[\s]+ return 'SPACE';
|
||||
["] { this.begin("string");}
|
||||
<string>["] { this.popState(); }
|
||||
<string>[^"]* { return 'STR'; }
|
||||
\"[^"]*\" return 'WORD';
|
||||
"erDiagram" return 'ER_DIAGRAM';
|
||||
\|o return 'ZERO_OR_ONE';
|
||||
\}o return 'ZERO_OR_MORE';
|
||||
@ -73,7 +70,7 @@ relType
|
||||
;
|
||||
|
||||
role
|
||||
: 'STR' { $$ = $1; }
|
||||
: 'WORD' { $$ = $1.replace(/"/g, ''); }
|
||||
| 'ALPHANUM' { $$ = $1; }
|
||||
;
|
||||
%%
|
||||
|
@ -252,4 +252,21 @@ describe('when parsing ER diagram it...', function() {
|
||||
}).toThrowError();
|
||||
});
|
||||
|
||||
it('should allow an empty quoted label', function() {
|
||||
erDiagram.parser.parse('erDiagram\nCUSTOMER ||--|{ ORDER : ""');
|
||||
const rels = erDb.getRelationships();
|
||||
expect(rels[0].roleA).toBe('');
|
||||
});
|
||||
|
||||
it('should allow an non-empty quoted label', function() {
|
||||
erDiagram.parser.parse('erDiagram\nCUSTOMER ||--|{ ORDER : "places"');
|
||||
const rels = erDb.getRelationships();
|
||||
expect(rels[0].roleA).toBe('places');
|
||||
});
|
||||
|
||||
it('should allow an non-empty unquoted label', function() {
|
||||
erDiagram.parser.parse('erDiagram\nCUSTOMER ||--|{ ORDER : places');
|
||||
const rels = erDb.getRelationships();
|
||||
expect(rels[0].roleA).toBe('places');
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user