Allow underscores in entity names, and entities with no relationships

This commit is contained in:
Adrian Hall
2020-10-23 10:00:17 +01:00
parent 3f60107885
commit 245e25f4b7
4 changed files with 50 additions and 11 deletions

View File

@@ -27,7 +27,7 @@ o\{ return 'ZERO_OR_MORE';
\-\- return 'IDENTIFYING';
\.\- return 'NON_IDENTIFYING';
\-\. return 'NON_IDENTIFYING';
[A-Za-z][A-Za-z0-9\-]* return 'ALPHANUM';
[A-Za-z][A-Za-z0-9\-_]* return 'ALPHANUM';
. return yytext[0];
<<EOF>> return 'EOF';
@@ -67,6 +67,7 @@ statement
yy.addRelationship($1, $5, $3, $2);
/*console.log($1 + $2 + $3 + ':' + $5);*/
}
| entityName { yy.addEntity($1); }
;
entityName

View File

@@ -14,6 +14,25 @@ describe('when parsing ER diagram it...', function() {
erDiagram.parser.yy.clear();
});
it ('should allow stand-alone entities with no relationships', function() {
const line1 = 'ISLAND';
const line2 = 'MAINLAND';
erDiagram.parser.parse(`erDiagram\n${line1}\n${line2}`);
expect(Object.keys(erDb.getEntities()).length).toBe(2);
expect (erDb.getRelationships().length).toBe(0);
});
it ('should allow hyphens and underscores in entity names', function() {
const line1 = 'DUCK-BILLED-PLATYPUS';
const line2 = 'CHARACTER_SET';
erDiagram.parser.parse(`erDiagram\n${line1}\n${line2}`);
const entities = erDb.getEntities();
expect (entities["DUCK-BILLED-PLATYPUS"]).toBe('DUCK-BILLED-PLATYPUS');
expect (entities.CHARACTER_SET).toBe('CHARACTER_SET');
});
it('should associate two entities correctly', function() {
erDiagram.parser.parse('erDiagram\nCAR ||--o{ DRIVER : "insured for"');
const entities = erDb.getEntities();