mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-20 12:44:18 +01:00
Refactor mindmap grammar to enhance node type support, including BangNode, CloudNode, and HexagonNode. Update value converter for new string handling and improve test coverage for node definitions.
This commit is contained in:
22
packages/parser/tests/mindmap-poc.test.ts
Normal file
22
packages/parser/tests/mindmap-poc.test.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { validatedMindmapParse as validatedParse, mindmapParse as parse } from './test-util.js';
|
||||
import type { CircleNode, SimpleNode, OtherComplex } from '../src/language/generated/ast.js';
|
||||
|
||||
describe('Nodes (ported from mindmap.spec.ts)', () => {
|
||||
it('MMP-21 should be possible to have comments in a mindmap', () => {
|
||||
const result = parse(
|
||||
'mindmap\nroot(Root)\n Child(Child)\n a(a)\n\n %% This is a comment\n b[New Stuff]'
|
||||
);
|
||||
expect(result.lexerErrors).toHaveLength(0);
|
||||
console.debug(result.parserErrors);
|
||||
expect(result.parserErrors).toHaveLength(0);
|
||||
const rootNode = result.value.MindmapRows[0].item as OtherComplex;
|
||||
const childNode = result.value.MindmapRows[1].item as OtherComplex;
|
||||
const aNode = result.value.MindmapRows[2].item as OtherComplex;
|
||||
const bNode = result.value.MindmapRows[3].item as OtherComplex;
|
||||
expect(rootNode.desc).toBe('Root');
|
||||
expect(childNode.desc).toBe('Child');
|
||||
expect(aNode.desc).toBe('a');
|
||||
expect(bNode.desc).toBe('New Stuff');
|
||||
});
|
||||
});
|
||||
@@ -174,7 +174,7 @@ describe('Nodes (ported from mindmap.spec.ts)', () => {
|
||||
expect(childNode.desc).toBe('child1');
|
||||
});
|
||||
|
||||
it.only('MMP-9 should handle an id and type for a node definition', () => {
|
||||
it('MMP-9 should handle an id and type for a node definition', () => {
|
||||
const result = parse('mindmap\nroot\n theId(child1)');
|
||||
expect(result.lexerErrors).toHaveLength(0);
|
||||
expect(result.parserErrors).toHaveLength(0);
|
||||
@@ -256,6 +256,51 @@ describe('Decorations (ported from mindmap.spec.ts)', () => {
|
||||
const rootNode = result.value.MindmapRows[0].item as OtherComplex;
|
||||
expect(rootNode.desc).toBe('The root');
|
||||
});
|
||||
it('MMP-16.2 should handle an id and type for a node definition', () => {
|
||||
const result = parse(`mindmap
|
||||
id1[SquareNode I am]
|
||||
id2["SquareNode I am"]
|
||||
id3("RoundedNode I am")
|
||||
id4(RoundedNode I am)
|
||||
id5(("CircleNode I am"))
|
||||
id6((CircleNode I am))
|
||||
id7))BangNode I am((
|
||||
id8))"BangNode I am"((
|
||||
id9)"CloudNode I am"(
|
||||
id10)CloudNode I am(
|
||||
id11{{"HexagonNode I am"}}
|
||||
id12{{HexagonNode I am}}
|
||||
id13
|
||||
`);
|
||||
|
||||
expect(result.lexerErrors).toHaveLength(0);
|
||||
expect(result.parserErrors).toHaveLength(0);
|
||||
expect(result.value.MindmapRows).toHaveLength(13);
|
||||
expect(result.value.MindmapRows[0].item.$type).toBe('SquareNode');
|
||||
expect(result.value.MindmapRows[1].item.$type).toBe('SquareNode');
|
||||
expect(result.value.MindmapRows[2].item.$type).toBe('RoundedNode');
|
||||
expect(result.value.MindmapRows[3].item.$type).toBe('RoundedNode');
|
||||
expect(result.value.MindmapRows[4].item.$type).toBe('CircleNode');
|
||||
expect(result.value.MindmapRows[5].item.$type).toBe('CircleNode');
|
||||
expect(result.value.MindmapRows[6].item.$type).toBe('BangNode');
|
||||
expect(result.value.MindmapRows[7].item.$type).toBe('BangNode');
|
||||
expect(result.value.MindmapRows[8].item.$type).toBe('CloudNode');
|
||||
expect(result.value.MindmapRows[9].item.$type).toBe('CloudNode');
|
||||
expect(result.value.MindmapRows[10].item.$type).toBe('HexagonNode');
|
||||
expect(result.value.MindmapRows[11].item.$type).toBe('HexagonNode');
|
||||
expect(result.value.MindmapRows[12].item.$type).toBe('SimpleNode');
|
||||
|
||||
let id = 1;
|
||||
for (const row of result.value.MindmapRows as MindmapRow[]) {
|
||||
const item = row.item as Node;
|
||||
expect(item.id).toBeDefined();
|
||||
expect(item?.id).toBe('id' + id);
|
||||
if (item.id !== 'id13') {
|
||||
expect(item.desc).toBe(item.$type + ' I am');
|
||||
}
|
||||
id++;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('Descriptions (ported from mindmap.spec.ts)', () => {
|
||||
|
||||
Reference in New Issue
Block a user