mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-20 12:44:18 +01:00
WIP - fixing grammar separating SimpleNode from ComplexNode
This commit is contained in:
7
packages/parser/tests/mindmap-debug.js
Normal file
7
packages/parser/tests/mindmap-debug.js
Normal file
@@ -0,0 +1,7 @@
|
||||
// Debug file to print the structure of a parsed mindmap
|
||||
import { mindMapParse } from './test-util.js';
|
||||
|
||||
const result = mindMapParse('mindmap\nroot\n child1\n child2');
|
||||
|
||||
console.log('Parser result:', result.value);
|
||||
console.log('Statement structure:', JSON.stringify(result.value?.statements[0], null, 2));
|
||||
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { mindMapParse as parse } from './test-util.js';
|
||||
import { mindmapParse as parse } from './test-util.js';
|
||||
import { keys } from '../../mermaid-flowchart-elk/dist/packages/mermaid/src/diagrams/state/id-cache';
|
||||
|
||||
// Tests for mindmap parser with simple root and child nodes
|
||||
describe('MindMap Parser Tests', () => {
|
||||
@@ -30,8 +31,9 @@ describe('MindMap Parser Tests', () => {
|
||||
expect(rootNode.content).toBe('root');
|
||||
});
|
||||
|
||||
it('should parse a mindmap with child nodes', () => {
|
||||
const _result = parse(
|
||||
it.only('should parse a mindmap with child nodes', () => {
|
||||
console.log('BEFORE RESULT:');
|
||||
const result = parse(
|
||||
'mindmap\nroot((Root))\n child1((Child 1))\n child2((Child 2))\n grandchild((Grand Child))'
|
||||
);
|
||||
|
||||
@@ -40,28 +42,49 @@ describe('MindMap Parser Tests', () => {
|
||||
// Statements length: result.value?.statements?.length
|
||||
// If statements exist, they would have properties like id, type, text, depth
|
||||
|
||||
const statements = result.value.statements;
|
||||
const s0 = statements[0];
|
||||
const s1 = statements[1];
|
||||
|
||||
console.debug('Statements:', s0);
|
||||
|
||||
expect(result.value.statements[0].$type).toBe('Statement');
|
||||
// expect(result.value.statements[0].element.$type).toBe('ComplexNode');
|
||||
expect(s0.element.$type).toBe('ComplexNode');
|
||||
expect(Object.keys(s0)).toBe('Root');
|
||||
expect(s0.element.ID).toBe('Root');
|
||||
|
||||
expect(result.value.statements[1].$type).toBe('Statement');
|
||||
expect(result.value.statements[1].element.$type).toBe('ComplexNode');
|
||||
expect(result.value.statements[1].element.ID).toBe('Root');
|
||||
expect(result.value.statements[1].element.desc).toBe('Root');
|
||||
expect(Object.keys(result.value.statements[1].element)).toBe('root');
|
||||
expect(result.value.statements[1].indent).toBe('indent');
|
||||
expect(Object.keys(result.value.statements[1].element)).toBe(true);
|
||||
expect(result.value.statements[1].element.id).toBe('SimpleNode');
|
||||
|
||||
// Temporarily commenting out failing assertions
|
||||
// expect(result.successful).toBe(true);
|
||||
// // Check that there are 4 statements: mindmap, root, child1, child2, grandchild
|
||||
// expect(result.value.statements.length).toBe(5);
|
||||
// // Check that the first statement is the mindmap
|
||||
// expect(result.value.statements[0].type).toBe('mindmap');
|
||||
// // Check that the second statement is the root
|
||||
// expect(result.value.statements[1].type.type).toBe('circle');
|
||||
// expect(result.value.statements[1].text).toBe('Root');
|
||||
// expect(result.value.statements[1].depth).toBe(0);
|
||||
// // Check that the third statement is the first child
|
||||
// expect(result.value.statements[2].type.type).toBe('circle');
|
||||
// expect(result.value.statements[2].text).toBe('Child 1');
|
||||
// expect(result.value.statements[2].depth).toBe(1);
|
||||
// // Check that the fourth statement is the second child
|
||||
// expect(result.value.statements[3].type.type).toBe('circle');
|
||||
// expect(result.value.statements[3].text).toBe('Child 2');
|
||||
// expect(result.value.statements[3].depth).toBe(1);
|
||||
// // Check that the fifth statement is the grandchild
|
||||
// expect(result.value.statements[4].type.type).toBe('circle');
|
||||
// expect(result.value.statements[4].text).toBe('Grand Child');
|
||||
// expect(result.value.statements[4].depth).toBe(2);
|
||||
// Check that there are 4 statements: mindmap, root, child1, child2, grandchild
|
||||
expect(result.value.statements.length).toBe(5);
|
||||
// Check that the first statement is the mindmap
|
||||
expect(result.value.statements[0].type).toBe('mindmap');
|
||||
// Check that the second statement is the root
|
||||
expect(result.value.statements[1].type.type).toBe('circle');
|
||||
expect(result.value.statements[1].text).toBe('Root');
|
||||
expect(result.value.statements[1].depth).toBe(0);
|
||||
// Check that the third statement is the first child
|
||||
expect(result.value.statements[2].type.type).toBe('circle');
|
||||
expect(result.value.statements[2].text).toBe('Child 1');
|
||||
expect(result.value.statements[2].depth).toBe(1);
|
||||
// Check that the fourth statement is the second child
|
||||
expect(result.value.statements[3].type.type).toBe('circle');
|
||||
expect(result.value.statements[3].text).toBe('Child 2');
|
||||
expect(result.value.statements[3].depth).toBe(1);
|
||||
// Check that the fifth statement is the grandchild
|
||||
expect(result.value.statements[4].type.type).toBe('circle');
|
||||
expect(result.value.statements[4].text).toBe('Grand Child');
|
||||
expect(result.value.statements[4].depth).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
24
packages/parser/tests/test-print-esm.js
Normal file
24
packages/parser/tests/test-print-esm.js
Normal file
@@ -0,0 +1,24 @@
|
||||
// Test file to print the parsed structure of a mindmap
|
||||
import { createMindMapServices } from '../src/language/index.js';
|
||||
|
||||
// Create services
|
||||
const mindMapServices = createMindMapServices().MindMap;
|
||||
const mindMapParser = mindMapServices.parser.LangiumParser;
|
||||
|
||||
// Function to parse mindmap
|
||||
function parse(input) {
|
||||
return mindMapParser.parse(input);
|
||||
}
|
||||
|
||||
// Test with a simple mindmap
|
||||
const result = parse('mindmap\nroot\n child1\n child2');
|
||||
|
||||
// Print the result structure
|
||||
console.log('Parse result:');
|
||||
console.log(JSON.stringify(result.value, null, 2));
|
||||
|
||||
// Print the first statement
|
||||
if (result.value?.statements?.[0]) {
|
||||
console.log('\nFirst statement:');
|
||||
console.log(JSON.stringify(result.value.statements[0], null, 2));
|
||||
}
|
||||
27
packages/parser/tests/test-print.js
Normal file
27
packages/parser/tests/test-print.js
Normal file
@@ -0,0 +1,27 @@
|
||||
// Test parsing
|
||||
import { createMindMapServices } from '../lib/language/mindmap/module.js';
|
||||
import { parseDocument } from 'langium';
|
||||
|
||||
// Create services for handling the language
|
||||
const services = createMindMapServices();
|
||||
// Get the service for parsing documents
|
||||
const documentBuilder = services.MindMap.shared.workspace.DocumentBuilder;
|
||||
|
||||
// Sample mindmap text to parse
|
||||
const text = 'mindmap\nroot\n child1\n child2';
|
||||
|
||||
// Parse the document
|
||||
const doc = documentBuilder.buildDocuments([
|
||||
{
|
||||
uri: 'file:///test.mindmap',
|
||||
content: text,
|
||||
version: 1,
|
||||
},
|
||||
]);
|
||||
|
||||
// Get the parsed document
|
||||
const result = Array.isArray(doc) ? doc[0] : undefined;
|
||||
if (result) {
|
||||
console.log('AST:', JSON.stringify(result.parseResult.value, null, 2));
|
||||
console.log('First node:', JSON.stringify(result.parseResult.value.statements?.[0], null, 2));
|
||||
}
|
||||
@@ -13,8 +13,8 @@ import type {
|
||||
PacketServices,
|
||||
GitGraph,
|
||||
GitGraphServices,
|
||||
MindMap,
|
||||
MindMapServices,
|
||||
Mindmap,
|
||||
MindmapServices,
|
||||
} from '../src/language/index.js';
|
||||
import {
|
||||
createArchitectureServices,
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
createRadarServices,
|
||||
createPacketServices,
|
||||
createGitGraphServices,
|
||||
createMindMapServices,
|
||||
createMindmapServices,
|
||||
} from '../src/language/index.js';
|
||||
|
||||
const consoleMock = vi.spyOn(console, 'log').mockImplementation(() => undefined);
|
||||
@@ -108,13 +108,13 @@ export function createGitGraphTestServices() {
|
||||
}
|
||||
export const gitGraphParse = createGitGraphTestServices().parse;
|
||||
|
||||
const mindMapServices: MindMapServices = createMindMapServices().MindMap;
|
||||
const mindMapParser: LangiumParser = mindMapServices.parser.LangiumParser;
|
||||
export function createMindMapTestServices() {
|
||||
const mindmapServices: MindmapServices = createMindmapServices().Mindmap;
|
||||
const mindmapParser: LangiumParser = mindmapServices.parser.LangiumParser;
|
||||
export function createMindmapTestServices() {
|
||||
const parse = (input: string) => {
|
||||
return mindMapParser.parse<MindMap>(input);
|
||||
return mindmapParser.parse<Mindmap>(input);
|
||||
};
|
||||
|
||||
return { services: mindMapServices, parse };
|
||||
return { services: mindmapServices, parse };
|
||||
}
|
||||
export const mindMapParse = createMindMapTestServices().parse;
|
||||
export const mindmapParse = createMindmapTestServices().parse;
|
||||
|
||||
Reference in New Issue
Block a user