mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-23 16:04:12 +02:00
Updating grammar to catch additional scenarios
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { parser } from './flow.jison';
|
||||
import { FlowDB } from '../flowDb.js';
|
||||
|
||||
describe('Flowchart arrow parsing - Issue #2492', () => {
|
||||
let flowDb: FlowDB;
|
||||
|
||||
beforeEach(() => {
|
||||
flowDb = new FlowDB();
|
||||
parser.yy = flowDb;
|
||||
flowDb.clear();
|
||||
});
|
||||
|
||||
describe('Solid arrows with markers', () => {
|
||||
it('should parse --> followed by uppercase node', () => {
|
||||
const diagram = 'graph TD\nA-->B';
|
||||
expect(() => parser.parse(diagram)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should parse --> followed by lowercase node', () => {
|
||||
const diagram = 'graph TD\nA-->b';
|
||||
expect(() => parser.parse(diagram)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should parse --> followed by space', () => {
|
||||
const diagram = 'graph TD\nA--> B';
|
||||
expect(() => parser.parse(diagram)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should parse --- followed by uppercase node (issue #2492)', () => {
|
||||
const diagram = 'graph TD\ndev---Ops';
|
||||
expect(() => parser.parse(diagram)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should parse --- followed by lowercase node (issue #2492)', () => {
|
||||
const diagram = 'graph TD\ndev---ops';
|
||||
expect(() => parser.parse(diagram)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should parse --o followed by uppercase node', () => {
|
||||
const diagram = 'graph TD\nA--oB';
|
||||
expect(() => parser.parse(diagram)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should parse --o followed by lowercase node', () => {
|
||||
const diagram = 'graph TD\nA--ob';
|
||||
expect(() => parser.parse(diagram)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should parse --x followed by uppercase node', () => {
|
||||
const diagram = 'graph TD\nA--xBar';
|
||||
expect(() => parser.parse(diagram)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should parse --x followed by lowercase node', () => {
|
||||
const diagram = 'graph TD\nA--xbar';
|
||||
expect(() => parser.parse(diagram)).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Thick arrows with markers', () => {
|
||||
it('should parse ==> followed by uppercase node', () => {
|
||||
const diagram = 'graph TD\nA==>B';
|
||||
expect(() => parser.parse(diagram)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should parse ==> followed by lowercase node', () => {
|
||||
const diagram = 'graph TD\nA==>b';
|
||||
expect(() => parser.parse(diagram)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should parse === followed by lowercase node', () => {
|
||||
const diagram = 'graph TD\nA===b';
|
||||
expect(() => parser.parse(diagram)).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Dotted arrows with markers', () => {
|
||||
it('should parse -.-> followed by uppercase node', () => {
|
||||
const diagram = 'graph TD\nA-.->B';
|
||||
expect(() => parser.parse(diagram)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should parse -.-> followed by lowercase node', () => {
|
||||
const diagram = 'graph TD\nA-.->b';
|
||||
expect(() => parser.parse(diagram)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should parse -.- followed by lowercase node', () => {
|
||||
const diagram = 'graph TD\nA-.-b';
|
||||
expect(() => parser.parse(diagram)).not.toThrow();
|
||||
});
|
||||
});
|
||||
});
|
@@ -154,19 +154,28 @@ that id.
|
||||
|
||||
<INITIAL,edgeText>\s*[xo<]?\-\-+[xo>]\s+ { this.popState(); return 'LINK'; }
|
||||
<INITIAL,edgeText>\s*[xo<]?\-\-+[xo>](?=[A-Z]) { this.popState(); return 'LINK'; }
|
||||
<INITIAL,edgeText>\s*[xo<]?\-\-+[-]\s* { this.popState(); return 'LINK'; }
|
||||
<INITIAL,edgeText>\s*[xo<]?\-\-+[xo>](?=[a-z]) { this.popState(); return 'LINK'; }
|
||||
<INITIAL,edgeText>\s*[xo<]?\-\-+[-](?=[A-Z]) { this.popState(); return 'LINK'; }
|
||||
<INITIAL,edgeText>\s*[xo<]?\-\-+[-]\s+ { this.popState(); return 'LINK'; }
|
||||
<INITIAL,edgeText>\s*[xo<]?\-\-+[-](?=[a-z]) { this.popState(); return 'LINK'; }
|
||||
<INITIAL>\s*[xo<]?\-\-\s* { this.pushState("edgeText"); return 'START_LINK'; }
|
||||
<edgeText>[^-]|\-(?!\-)+ return 'EDGE_TEXT';
|
||||
|
||||
<INITIAL,thickEdgeText>\s*[xo<]?\=\=+[xo>]\s+ { this.popState(); return 'LINK'; }
|
||||
<INITIAL,thickEdgeText>\s*[xo<]?\=\=+[xo>](?=[A-Z]) { this.popState(); return 'LINK'; }
|
||||
<INITIAL,thickEdgeText>\s*[xo<]?\=\=+[=]\s* { this.popState(); return 'LINK'; }
|
||||
<INITIAL,thickEdgeText>\s*[xo<]?\=\=+[xo>](?=[a-z]) { this.popState(); return 'LINK'; }
|
||||
<INITIAL,thickEdgeText>\s*[xo<]?\=\=+[=](?=[A-Z]) { this.popState(); return 'LINK'; }
|
||||
<INITIAL,thickEdgeText>\s*[xo<]?\=\=+[=]\s+ { this.popState(); return 'LINK'; }
|
||||
<INITIAL,thickEdgeText>\s*[xo<]?\=\=+[=](?=[a-z]) { this.popState(); return 'LINK'; }
|
||||
<INITIAL>\s*[xo<]?\=\=\s* { this.pushState("thickEdgeText"); return 'START_LINK'; }
|
||||
<thickEdgeText>[^=]|\=(?!=) return 'EDGE_TEXT';
|
||||
|
||||
<INITIAL,dottedEdgeText>\s*[xo<]?\-?\.+\-[xo>]\s+ { this.popState(); return 'LINK'; }
|
||||
<INITIAL,dottedEdgeText>\s*[xo<]?\-?\.+\-[xo>](?=[A-Z]) { this.popState(); return 'LINK'; }
|
||||
<INITIAL,dottedEdgeText>\s*[xo<]?\-?\.+\-\s* { this.popState(); return 'LINK'; }
|
||||
<INITIAL,dottedEdgeText>\s*[xo<]?\-?\.+\-[xo>](?=[a-z]) { this.popState(); return 'LINK'; }
|
||||
<INITIAL,dottedEdgeText>\s*[xo<]?\-?\.+\-(?=[A-Z]) { this.popState(); return 'LINK'; }
|
||||
<INITIAL,dottedEdgeText>\s*[xo<]?\-?\.+\-\s+ { this.popState(); return 'LINK'; }
|
||||
<INITIAL,dottedEdgeText>\s*[xo<]?\-?\.+\-(?=[a-z]) { this.popState(); return 'LINK'; }
|
||||
<INITIAL>\s*[xo<]?\-\.\s* { this.pushState("dottedEdgeText"); return 'START_LINK'; }
|
||||
<dottedEdgeText>[^\.]|\.(?!-) return 'EDGE_TEXT';
|
||||
|
||||
|
Reference in New Issue
Block a user