From 1169cb9e85a7120e3377563bcda836ea87077552 Mon Sep 17 00:00:00 2001 From: futzmonitor Date: Mon, 26 Feb 2024 20:59:40 -0500 Subject: [PATCH 1/4] Changes to timeline.jison 1. Removed the semicolon from the regex for titles, sections, periods, and events. Changes to timeline.spec.js 1. Added a test for the changes made in the timeline parser --- .../diagrams/timeline/parser/timeline.jison | 8 +++--- .../src/diagrams/timeline/timeline.spec.js | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/packages/mermaid/src/diagrams/timeline/parser/timeline.jison b/packages/mermaid/src/diagrams/timeline/parser/timeline.jison index 348c31fad8..136654a7f2 100644 --- a/packages/mermaid/src/diagrams/timeline/parser/timeline.jison +++ b/packages/mermaid/src/diagrams/timeline/parser/timeline.jison @@ -18,7 +18,7 @@ \#[^\n]* /* skip comments */ "timeline" return 'timeline'; -"title"\s[^#\n;]+ return 'title'; +"title"\s[^#\n]+ return 'title'; accTitle\s*":"\s* { this.begin("acc_title");return 'acc_title'; } (?!\n|;|#)*[^\n]* { this.popState(); return "acc_title_value"; } accDescr\s*":"\s* { this.begin("acc_descr");return 'acc_descr'; } @@ -26,11 +26,11 @@ accDescr\s*":"\s* { this.begin("ac accDescr\s*"{"\s* { this.begin("acc_descr_multiline");} [\}] { this.popState(); } [^\}]* return "acc_descr_multiline_value"; -"section"\s[^#:\n;]+ return 'section'; +"section"\s[^#:\n]+ return 'section'; // event starting with "==>" keyword -":"\s[^#:\n;]+ return 'event'; -[^#:\n;]+ return 'period'; +":"\s[^#:\n]+ return 'event'; +[^#:\n]+ return 'period'; <> return 'EOF'; diff --git a/packages/mermaid/src/diagrams/timeline/timeline.spec.js b/packages/mermaid/src/diagrams/timeline/timeline.spec.js index 69b9df1bad..186713ce1e 100644 --- a/packages/mermaid/src/diagrams/timeline/timeline.spec.js +++ b/packages/mermaid/src/diagrams/timeline/timeline.spec.js @@ -98,5 +98,30 @@ describe('when parsing a timeline ', function () { } }); }); + + it('TL-6 should handle a section, and task and its multi line events with semicolons', function () { + let str = `timeline + section ;a;bc-123; + ;ta;sk1;: ;ev;ent1; + ;tas;k2;: ;eve;nt2;: ;event;3; + : ;eve;nt4: ;even;t5; + `; + timeline.parse(str); + expect(timelineDB.getSections()[0]).to.deep.equal(';a;bc-123;'); + timelineDB.getTasks().forEach((t) => { + switch (t.task.trim()) { + case ';ta;sk1;': + expect(t.events).to.deep.equal([';ev;ent1;']); + break; + + case ';tas;k2;': + expect(t.events).to.deep.equal([';eve;nt2;', ';event;3;', ';eve;nt4', ';even;t5;']); + break; + + default: + break; + } + }); + }); }); }); From 9e3ebf1648d5920bd8174db3c09a2928a70b809b Mon Sep 17 00:00:00 2001 From: futzmonitor Date: Tue, 27 Feb 2024 09:33:11 -0500 Subject: [PATCH 2/4] Run the pnpm lint:fix command to fix linting problems --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 8544e09800..d368a43499 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,6 @@ C -->|Two| E[Result 2] ### Sequence diagram [docs - live editor] - ``` sequenceDiagram Alice->>John: Hello John, how are you? From cf88f0609d26bac3d4e445ad65c7f70d37e6be10 Mon Sep 17 00:00:00 2001 From: futzmonitor Date: Tue, 19 Mar 2024 10:02:51 -0400 Subject: [PATCH 3/4] Changes to timeline.spec.js 1. Re-organized the new TL-6 test to not use a for-loop with a switch case. 2. Imported the commonDb module to ensure titles are be tested. 3. Use indices to retrieve elements that need to be tested. --- .../src/diagrams/timeline/timeline.spec.js | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/packages/mermaid/src/diagrams/timeline/timeline.spec.js b/packages/mermaid/src/diagrams/timeline/timeline.spec.js index 186713ce1e..0cb227fa6b 100644 --- a/packages/mermaid/src/diagrams/timeline/timeline.spec.js +++ b/packages/mermaid/src/diagrams/timeline/timeline.spec.js @@ -1,5 +1,6 @@ import { parser as timeline } from './parser/timeline.jison'; import * as timelineDB from './timelineDb.js'; +import * as commonDb from '../common/commonDb.js'; import { setLogLevel } from '../../diagram-api/diagramAPI.js'; describe('when parsing a timeline ', function () { @@ -99,29 +100,19 @@ describe('when parsing a timeline ', function () { }); }); - it('TL-6 should handle a section, and task and its multi line events with semicolons', function () { + it('TL-6 should handle a title, section, task, and events with semicolons', function () { let str = `timeline - section ;a;bc-123; - ;ta;sk1;: ;ev;ent1; - ;tas;k2;: ;eve;nt2;: ;event;3; - : ;eve;nt4: ;even;t5; + title ;my;title; + section ;a;bc-123; + ;ta;sk1;: ;ev;ent1; : ;ev;ent2; : ;ev;ent3; `; timeline.parse(str); - expect(timelineDB.getSections()[0]).to.deep.equal(';a;bc-123;'); - timelineDB.getTasks().forEach((t) => { - switch (t.task.trim()) { - case ';ta;sk1;': - expect(t.events).to.deep.equal([';ev;ent1;']); - break; - - case ';tas;k2;': - expect(t.events).to.deep.equal([';eve;nt2;', ';event;3;', ';eve;nt4', ';even;t5;']); - break; - - default: - break; - } - }); + expect(commonDb.getDiagramTitle()).equal(';my;title;'); + expect(timelineDB.getSections()).to.deep.equal([';a;bc-123;']); + expect(timelineDB.getTasks()[0].task).equal(';ta;sk1;'); + expect(timelineDB.getTasks()[0].events[0]).equal(';ev;ent1; '); + expect(timelineDB.getTasks()[0].events[1]).equal(';ev;ent2; '); + expect(timelineDB.getTasks()[0].events[2]).equal(';ev;ent3;'); }); }); }); From 262bf4e2b055868f0a28737637e85380295757ba Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Tue, 20 Aug 2024 14:25:52 +0530 Subject: [PATCH 4/4] chore: Simplify unit test --- .../src/diagrams/timeline/timeline.spec.js | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/mermaid/src/diagrams/timeline/timeline.spec.js b/packages/mermaid/src/diagrams/timeline/timeline.spec.js index 8cc990dcf9..a7005cada9 100644 --- a/packages/mermaid/src/diagrams/timeline/timeline.spec.js +++ b/packages/mermaid/src/diagrams/timeline/timeline.spec.js @@ -109,10 +109,13 @@ describe('when parsing a timeline ', function () { timeline.parse(str); expect(commonDb.getDiagramTitle()).equal(';my;title;'); expect(timelineDB.getSections()).to.deep.equal([';a;bc-123;']); - expect(timelineDB.getTasks()[0].task).equal(';ta;sk1;'); - expect(timelineDB.getTasks()[0].events[0]).equal(';ev;ent1; '); - expect(timelineDB.getTasks()[0].events[1]).equal(';ev;ent2; '); - expect(timelineDB.getTasks()[0].events[2]).equal(';ev;ent3;'); + expect(timelineDB.getTasks()[0].events).toMatchInlineSnapshot(` + [ + ";ev;ent1; ", + ";ev;ent2; ", + ";ev;ent3;", + ] + `); }); it('should handle a title, section, task, and events with hashtags', function () { @@ -125,9 +128,13 @@ describe('when parsing a timeline ', function () { expect(commonDb.getDiagramTitle()).equal('#my#title#'); expect(timelineDB.getSections()).to.deep.equal(['#a#bc-123#']); expect(timelineDB.getTasks()[0].task).equal('task1'); - expect(timelineDB.getTasks()[0].events[0]).equal('#ev#ent1# '); - expect(timelineDB.getTasks()[0].events[1]).equal('#ev#ent2# '); - expect(timelineDB.getTasks()[0].events[2]).equal('#ev#ent3#'); + expect(timelineDB.getTasks()[0].events).toMatchInlineSnapshot(` + [ + "#ev#ent1# ", + "#ev#ent2# ", + "#ev#ent3#", + ] + `); }); }); });