From ecf62e3b7ad31a4c33bc92a7aa9ef3db8faceb8b Mon Sep 17 00:00:00 2001 From: FlorianWoelki Date: Sat, 20 Aug 2022 13:56:39 +0200 Subject: [PATCH] test(parser): add tests for generics and arrays in erDiagram --- src/diagrams/er/parser/erDiagram.spec.js | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/diagrams/er/parser/erDiagram.spec.js b/src/diagrams/er/parser/erDiagram.spec.js index 1e0a40104..409176f78 100644 --- a/src/diagrams/er/parser/erDiagram.spec.js +++ b/src/diagrams/er/parser/erDiagram.spec.js @@ -85,6 +85,31 @@ describe('when parsing ER diagram it...', function () { expect(entities[entity].attributes.length).toBe(3); }); + it('should allow an entity with attribute that has a generic type', function () { + const entity = 'BOOK'; + const attribute1 = 'type~T~ type'; + const attribute2 = 'option~T~ readable "comment"'; + const attribute3 = 'string id PK'; + + erDiagram.parser.parse( + `erDiagram\n${entity} {\n${attribute1}\n${attribute2}\n${attribute3}\n}` + ); + const entities = erDb.getEntities(); + expect(Object.keys(entities).length).toBe(1); + expect(entities[entity].attributes.length).toBe(3); + }); + + it('should allow an entity with attribute that is an array', function () { + const entity = 'BOOK'; + const attribute1 = 'string[] readers FK "comment"'; + const attribute2 = 'string[] authors FK'; + + erDiagram.parser.parse(`erDiagram\n${entity} {\n${attribute1}\n${attribute2}\n}`); + const entities = erDb.getEntities(); + expect(Object.keys(entities).length).toBe(1); + expect(entities[entity].attributes.length).toBe(2); + }); + it('should allow an entity with multiple attributes to be defined', function () { const entity = 'BOOK'; const attribute1 = 'string title';