mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-18 23:09:49 +02:00
Fix for issue #895
This commit is contained in:
@@ -71,7 +71,7 @@ describe('when parsing subgraphs', function () {
|
||||
const subgraph = subgraphs[0]
|
||||
expect(subgraph.nodes.length).toBe(1)
|
||||
expect(subgraph.nodes[0]).toBe('A')
|
||||
expect(subgraph.id).toBe('1test')
|
||||
expect(subgraph.id).toBe('s1test')
|
||||
});
|
||||
|
||||
it('should handle subgraphs1', function () {
|
||||
@@ -82,6 +82,93 @@ describe('when parsing subgraphs', function () {
|
||||
|
||||
expect(edges[0].type).toBe('arrow')
|
||||
})
|
||||
it('should handle subgraphs with title in quotes', function () {
|
||||
const res = flow.parser.parse('graph TD;A-->B;subgraph "title in quotes";c-->d;end;')
|
||||
|
||||
const vert = flow.parser.yy.getVertices()
|
||||
const edges = flow.parser.yy.getEdges()
|
||||
|
||||
const subgraphs = flow.parser.yy.getSubGraphs()
|
||||
expect(subgraphs.length).toBe(1)
|
||||
const subgraph = subgraphs[0]
|
||||
|
||||
expect(subgraph.title).toBe('title in quotes')
|
||||
|
||||
expect(edges[0].type).toBe('arrow')
|
||||
})
|
||||
it('should handle subgraphs in old style that was broken', function () {
|
||||
const res = flow.parser.parse('graph TD;A-->B;subgraph old style that is broken;c-->d;end;')
|
||||
|
||||
const vert = flow.parser.yy.getVertices()
|
||||
const edges = flow.parser.yy.getEdges()
|
||||
|
||||
const subgraphs = flow.parser.yy.getSubGraphs()
|
||||
expect(subgraphs.length).toBe(1)
|
||||
const subgraph = subgraphs[0]
|
||||
|
||||
expect(subgraph.title).toBe('old style that is broken')
|
||||
|
||||
expect(edges[0].type).toBe('arrow')
|
||||
})
|
||||
it('should handle subgraphs with dashes in the title', function () {
|
||||
const res = flow.parser.parse('graph TD;A-->B;subgraph a-b-c;c-->d;end;')
|
||||
|
||||
const vert = flow.parser.yy.getVertices()
|
||||
const edges = flow.parser.yy.getEdges()
|
||||
|
||||
const subgraphs = flow.parser.yy.getSubGraphs()
|
||||
expect(subgraphs.length).toBe(1)
|
||||
const subgraph = subgraphs[0]
|
||||
|
||||
expect(subgraph.title).toBe('a-b-c')
|
||||
|
||||
expect(edges[0].type).toBe('arrow')
|
||||
})
|
||||
it('should handle subgraphs with id and title in brackets', function () {
|
||||
const res = flow.parser.parse('graph TD;A-->B;subgraph uid1[text of doom];c-->d;end;')
|
||||
|
||||
const vert = flow.parser.yy.getVertices()
|
||||
const edges = flow.parser.yy.getEdges()
|
||||
|
||||
const subgraphs = flow.parser.yy.getSubGraphs()
|
||||
expect(subgraphs.length).toBe(1)
|
||||
const subgraph = subgraphs[0]
|
||||
|
||||
expect(subgraph.title).toBe('text of doom')
|
||||
expect(subgraph.id).toBe('uid1')
|
||||
|
||||
expect(edges[0].type).toBe('arrow')
|
||||
})
|
||||
it('should handle subgraphs with id and title in brackets and quotes', function () {
|
||||
const res = flow.parser.parse('graph TD;A-->B;subgraph uid2["text of doom"];c-->d;end;')
|
||||
|
||||
const vert = flow.parser.yy.getVertices()
|
||||
const edges = flow.parser.yy.getEdges()
|
||||
|
||||
const subgraphs = flow.parser.yy.getSubGraphs()
|
||||
expect(subgraphs.length).toBe(1)
|
||||
const subgraph = subgraphs[0]
|
||||
|
||||
expect(subgraph.title).toBe('text of doom')
|
||||
expect(subgraph.id).toBe('uid2')
|
||||
|
||||
expect(edges[0].type).toBe('arrow')
|
||||
})
|
||||
it('should handle subgraphs with id and title in brackets without spaces', function () {
|
||||
const res = flow.parser.parse('graph TD;A-->B;subgraph uid2[textofdoom];c-->d;end;')
|
||||
|
||||
const vert = flow.parser.yy.getVertices()
|
||||
const edges = flow.parser.yy.getEdges()
|
||||
|
||||
const subgraphs = flow.parser.yy.getSubGraphs()
|
||||
expect(subgraphs.length).toBe(1)
|
||||
const subgraph = subgraphs[0]
|
||||
|
||||
expect(subgraph.title).toBe('textofdoom')
|
||||
expect(subgraph.id).toBe('uid2')
|
||||
|
||||
expect(edges[0].type).toBe('arrow')
|
||||
})
|
||||
|
||||
it('should handle subgraphs2', function () {
|
||||
const res = flow.parser.parse('graph TD\nA-->B\nsubgraph myTitle\n\n c-->d \nend\n')
|
||||
|
Reference in New Issue
Block a user