From c37ff47ee39cb48c1d43abc7a6ca697a6bdf5409 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Wed, 24 Aug 2022 12:33:32 +0530 Subject: [PATCH 1/5] Add nested test --- src/diagrams/common/common.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/diagrams/common/common.spec.js b/src/diagrams/common/common.spec.js index 01033d3ce..b9fac5fba 100644 --- a/src/diagrams/common/common.spec.js +++ b/src/diagrams/common/common.spec.js @@ -106,7 +106,7 @@ describe('Sanitize text', function () { describe('generic parser', function () { it('should parse generic types', function () { - const result = parseGenericTypes('test~T~'); - expect(result).toEqual('test'); + expect(parseGenericTypes('test~T~')).toEqual('test'); + expect(parseGenericTypes('test~Array~Array~string~~~')).toEqual('test>>'); }); }); From 5996e1e69d8c0e303414feeb5e846ee785891b50 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Thu, 25 Aug 2022 08:49:20 +0530 Subject: [PATCH 2/5] Fix nested types Co-authored-by: FlorianWoelki --- src/diagrams/common/common.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/diagrams/common/common.js b/src/diagrams/common/common.js index 73ccf1cce..39c4c77ca 100644 --- a/src/diagrams/common/common.js +++ b/src/diagrams/common/common.js @@ -196,8 +196,8 @@ export const parseGenericTypes = function (text) { let cleanedText = text; if (text.indexOf('~') != -1) { - cleanedText = cleanedText.replace('~', '<'); - cleanedText = cleanedText.replace('~', '>'); + cleanedText = cleanedText.replace(/~([^~].*)/, '<$1'); + cleanedText = cleanedText.replace(/~([^~]*)$/, '$1>'); return parseGenericTypes(cleanedText); } else { From 2f7930efb7b151ac076ef5a2c94afea38e93b8bd Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Thu, 25 Aug 2022 11:58:43 +0530 Subject: [PATCH 3/5] Fix nested types Co-authored-by: FlorianWoelki --- src/diagrams/common/common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diagrams/common/common.js b/src/diagrams/common/common.js index 39c4c77ca..6803ce4b9 100644 --- a/src/diagrams/common/common.js +++ b/src/diagrams/common/common.js @@ -197,7 +197,7 @@ export const parseGenericTypes = function (text) { if (text.indexOf('~') != -1) { cleanedText = cleanedText.replace(/~([^~].*)/, '<$1'); - cleanedText = cleanedText.replace(/~([^~]*)$/, '$1>'); + cleanedText = cleanedText.replace(/~([^~]*)$/, '>$1'); return parseGenericTypes(cleanedText); } else { From 39980322bd917e7d8e0a57f74629e751a41f168f Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Thu, 25 Aug 2022 11:59:01 +0530 Subject: [PATCH 4/5] Add more tests --- src/diagrams/class/svgDraw.spec.js | 8 ++++++++ src/diagrams/common/common.spec.js | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/src/diagrams/class/svgDraw.spec.js b/src/diagrams/class/svgDraw.spec.js index d4fd0cb6b..ec8785559 100644 --- a/src/diagrams/class/svgDraw.spec.js +++ b/src/diagrams/class/svgDraw.spec.js @@ -137,6 +137,14 @@ describe('class member Renderer, ', function () { expect(actual.displayText).toBe('+foo(List ids) : List'); expect(actual.cssStyle).toBe('font-style:italic;'); }); + + it('should handle method declaration with nested markup', function () { + const str = '+foo ( List~List~int~~ ids )* List~List~Item~~'; + let actual = svgDraw.parseMember(str); + + expect(actual.displayText).toBe('+foo(List> ids) : List>'); + expect(actual.cssStyle).toBe('font-style:italic;'); + }); }); describe('when parsing text to build field display string', function () { diff --git a/src/diagrams/common/common.spec.js b/src/diagrams/common/common.spec.js index b9fac5fba..19931141d 100644 --- a/src/diagrams/common/common.spec.js +++ b/src/diagrams/common/common.spec.js @@ -108,5 +108,11 @@ describe('generic parser', function () { it('should parse generic types', function () { expect(parseGenericTypes('test~T~')).toEqual('test'); expect(parseGenericTypes('test~Array~Array~string~~~')).toEqual('test>>'); + expect(parseGenericTypes('test~Array~Array~string[]~~~')).toEqual( + 'test>>' + ); + expect(parseGenericTypes('test ~Array~Array~string[]~~~')).toEqual( + 'test >>' + ); }); }); From 15b160c55351e4abfd0af39d68155cea21915bcb Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Thu, 25 Aug 2022 12:41:32 +0530 Subject: [PATCH 5/5] Fix svgDraw return types Co-authored-by: FlorianWoelki --- src/diagrams/class/svgDraw.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/diagrams/class/svgDraw.js b/src/diagrams/class/svgDraw.js index b9d31772a..84649e46e 100644 --- a/src/diagrams/class/svgDraw.js +++ b/src/diagrams/class/svgDraw.js @@ -345,10 +345,9 @@ const buildMethodDisplay = function (parsedText) { }; const buildLegacyDisplay = function (text) { - // if for some reason we dont have any match, use old format to parse text + // if for some reason we don't have any match, use old format to parse text let displayText = ''; let cssStyle = ''; - let memberText = ''; let returnType = ''; let methodStart = text.indexOf('('); let methodEnd = text.indexOf(')'); @@ -368,26 +367,27 @@ const buildLegacyDisplay = function (text) { methodName = text.substring(1, methodStart).trim(); } - let parameters = text.substring(methodStart + 1, methodEnd); - let classifier = text.substring(methodEnd + 1, 1); + const parameters = text.substring(methodStart + 1, methodEnd); + const classifier = text.substring(methodEnd + 1, methodEnd + 2); cssStyle = parseClassifier(classifier); displayText = visibility + methodName + '(' + parseGenericTypes(parameters.trim()) + ')'; - if (methodEnd < memberText.length) { + if (methodEnd <= text.length) { returnType = text.substring(methodEnd + 2).trim(); if (returnType !== '') { returnType = ' : ' + parseGenericTypes(returnType); + displayText += returnType; } + } else { + // finally - if all else fails, just send the text back as written (other than parsing for generic types) + displayText = parseGenericTypes(text); } - } else { - // finally - if all else fails, just send the text back as written (other than parsing for generic types) - displayText = parseGenericTypes(text); } return { - displayText: displayText, - cssStyle: cssStyle, + displayText, + cssStyle, }; };