mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-10 02:49:40 +02:00
create noErrorsOrAlternatives
parser helper function
This commit is contained in:
@@ -3,10 +3,11 @@ import type { LangiumParser, ParseResult } from 'langium';
|
|||||||
|
|
||||||
import type { InfoServices } from '../src/language/index.js';
|
import type { InfoServices } from '../src/language/index.js';
|
||||||
import { Info, createInfoServices } from '../src/language/index.js';
|
import { Info, createInfoServices } from '../src/language/index.js';
|
||||||
|
import { noErrorsOrAlternatives } from './test-util.js';
|
||||||
|
|
||||||
const services: InfoServices = createInfoServices().Info;
|
const services: InfoServices = createInfoServices().Info;
|
||||||
const parser: LangiumParser = services.parser.LangiumParser;
|
const parser: LangiumParser = services.parser.LangiumParser;
|
||||||
export function createInfoTestServices(): {
|
function createInfoTestServices(): {
|
||||||
services: InfoServices;
|
services: InfoServices;
|
||||||
parse: (input: string) => ParseResult<Info>;
|
parse: (input: string) => ParseResult<Info>;
|
||||||
} {
|
} {
|
||||||
@@ -30,11 +31,10 @@ describe('info', () => {
|
|||||||
info
|
info
|
||||||
`,
|
`,
|
||||||
])('should handle empty info', (context: string) => {
|
])('should handle empty info', (context: string) => {
|
||||||
const { parserErrors, lexerErrors, value } = parse(context);
|
const result = parse(context);
|
||||||
expect(parserErrors).toHaveLength(0);
|
noErrorsOrAlternatives(result);
|
||||||
expect(lexerErrors).toHaveLength(0);
|
|
||||||
|
|
||||||
expect(value.$type).toBe(Info);
|
expect(result.value.$type).toBe(Info);
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
@@ -49,10 +49,9 @@ describe('info', () => {
|
|||||||
showInfo
|
showInfo
|
||||||
`,
|
`,
|
||||||
])('should handle showInfo', (context: string) => {
|
])('should handle showInfo', (context: string) => {
|
||||||
const { parserErrors, lexerErrors, value } = parse(context);
|
const result = parse(context);
|
||||||
expect(parserErrors).toHaveLength(0);
|
noErrorsOrAlternatives(result);
|
||||||
expect(lexerErrors).toHaveLength(0);
|
|
||||||
|
|
||||||
expect(value.$type).toBe(Info);
|
expect(result.value.$type).toBe(Info);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
19
packages/parser/tests/test-util.ts
Normal file
19
packages/parser/tests/test-util.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { ParseResult } from 'langium';
|
||||||
|
|
||||||
|
const consoleMock = vi.spyOn(console, 'log').mockImplementation(() => {
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A helper test function that validate that the result doesn't have errors
|
||||||
|
* or any ambiguous alternatives from chevrotain.
|
||||||
|
*
|
||||||
|
* @param result - the result `parse` function.
|
||||||
|
*/
|
||||||
|
export function noErrorsOrAlternatives(result: ParseResult) {
|
||||||
|
expect(result.lexerErrors).toHaveLength(0);
|
||||||
|
expect(result.parserErrors).toHaveLength(0);
|
||||||
|
|
||||||
|
expect(consoleMock).not.toHaveBeenCalled();
|
||||||
|
consoleMock.mockReset();
|
||||||
|
}
|
Reference in New Issue
Block a user