mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-17 06:20:07 +02:00
test: update all parser test cases
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import type { ParseResult } from 'langium';
|
||||
import type { LangiumParser, ParseResult } from 'langium';
|
||||
import { expect, vi } from 'vitest';
|
||||
import type { Info, InfoServices, Pie, PieServices } from '../src/language/index.js';
|
||||
import { createInfoServices, createPieServices } from '../src/language/index.js';
|
||||
|
||||
const consoleMock = vi.spyOn(console, 'log').mockImplementation(() => undefined);
|
||||
|
||||
@@ -9,10 +11,32 @@ const consoleMock = vi.spyOn(console, 'log').mockImplementation(() => undefined)
|
||||
*
|
||||
* @param result - the result `parse` function.
|
||||
*/
|
||||
export function noErrorsOrAlternatives(result: ParseResult) {
|
||||
export function expectNoErrorsOrAlternatives(result: ParseResult) {
|
||||
expect(result.lexerErrors).toHaveLength(0);
|
||||
expect(result.parserErrors).toHaveLength(0);
|
||||
|
||||
expect(consoleMock).not.toHaveBeenCalled();
|
||||
consoleMock.mockReset();
|
||||
}
|
||||
|
||||
const infoServices: InfoServices = createInfoServices().Info;
|
||||
const infoParser: LangiumParser = infoServices.parser.LangiumParser;
|
||||
export function createInfoTestServices() {
|
||||
const parse = (input: string) => {
|
||||
return infoParser.parse<Info>(input);
|
||||
};
|
||||
|
||||
return { services: infoServices, parse };
|
||||
}
|
||||
export const infoParse = createInfoTestServices().parse;
|
||||
|
||||
const pieServices: PieServices = createPieServices().Pie;
|
||||
const pieParser: LangiumParser = pieServices.parser.LangiumParser;
|
||||
export function createPieTestServices() {
|
||||
const parse = (input: string) => {
|
||||
return pieParser.parse<Pie>(input);
|
||||
};
|
||||
|
||||
return { services: pieServices, parse };
|
||||
}
|
||||
export const pieParse = createPieTestServices().parse;
|
||||
|
Reference in New Issue
Block a user