2023-11-03 22:35:01 +03:00
|
|
|
import type { LangiumParser, ParseResult } from 'langium';
|
2023-09-07 00:00:38 +03:00
|
|
|
import { expect, vi } from 'vitest';
|
2024-07-21 19:50:59 -04:00
|
|
|
import type {
|
|
|
|
Info,
|
|
|
|
InfoServices,
|
|
|
|
Pie,
|
|
|
|
PieServices,
|
|
|
|
GitGraph,
|
|
|
|
GitGraphServices,
|
|
|
|
} from '../src/language/index.js';
|
|
|
|
import {
|
|
|
|
createInfoServices,
|
|
|
|
createPieServices,
|
|
|
|
createGitGraphServices,
|
|
|
|
} from '../src/language/index.js';
|
2023-08-26 14:01:56 +03:00
|
|
|
|
2023-08-26 14:37:36 +03:00
|
|
|
const consoleMock = vi.spyOn(console, 'log').mockImplementation(() => undefined);
|
2023-08-26 14:01:56 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2023-11-03 22:35:01 +03:00
|
|
|
export function expectNoErrorsOrAlternatives(result: ParseResult) {
|
2023-08-26 14:01:56 +03:00
|
|
|
expect(result.lexerErrors).toHaveLength(0);
|
|
|
|
expect(result.parserErrors).toHaveLength(0);
|
|
|
|
|
|
|
|
expect(consoleMock).not.toHaveBeenCalled();
|
|
|
|
consoleMock.mockReset();
|
|
|
|
}
|
2023-11-03 22:35:01 +03:00
|
|
|
|
|
|
|
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;
|
2024-07-21 19:50:59 -04:00
|
|
|
|
|
|
|
const gitGraphServices: GitGraphServices = createGitGraphServices().GitGraph;
|
|
|
|
const gitGraphParser: LangiumParser = gitGraphServices.parser.LangiumParser;
|
|
|
|
export function createGitGraphTestServices() {
|
|
|
|
const parse = (input: string) => {
|
|
|
|
return gitGraphParser.parse<GitGraph>(input);
|
|
|
|
};
|
|
|
|
|
|
|
|
return { services: gitGraphServices, parse };
|
|
|
|
}
|
|
|
|
export const gitGraphParse = createGitGraphTestServices().parse;
|