2023-08-20 15:38:46 +03:00
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
import type { LangiumParser, ParseResult } from 'langium';
|
|
|
|
|
|
|
|
import type { InfoServices } from '../src/language/index.js';
|
|
|
|
import { Info, createInfoServices } from '../src/language/index.js';
|
2023-08-26 14:01:56 +03:00
|
|
|
import { noErrorsOrAlternatives } from './test-util.js';
|
2023-08-20 15:38:46 +03:00
|
|
|
|
|
|
|
const services: InfoServices = createInfoServices().Info;
|
|
|
|
const parser: LangiumParser = services.parser.LangiumParser;
|
2023-08-26 14:01:56 +03:00
|
|
|
function createInfoTestServices(): {
|
2023-08-20 15:38:46 +03:00
|
|
|
services: InfoServices;
|
|
|
|
parse: (input: string) => ParseResult<Info>;
|
|
|
|
} {
|
|
|
|
const parse = (input: string) => {
|
|
|
|
return parser.parse<Info>(input);
|
|
|
|
};
|
|
|
|
|
|
|
|
return { services, parse };
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('info', () => {
|
|
|
|
const { parse } = createInfoTestServices();
|
|
|
|
|
|
|
|
it.each([
|
|
|
|
`info`,
|
|
|
|
`
|
|
|
|
info`,
|
|
|
|
`info
|
|
|
|
`,
|
|
|
|
`
|
|
|
|
info
|
|
|
|
`,
|
|
|
|
])('should handle empty info', (context: string) => {
|
2023-08-26 14:01:56 +03:00
|
|
|
const result = parse(context);
|
|
|
|
noErrorsOrAlternatives(result);
|
2023-08-20 15:38:46 +03:00
|
|
|
|
2023-08-26 14:01:56 +03:00
|
|
|
expect(result.value.$type).toBe(Info);
|
2023-08-20 15:38:46 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it.each([
|
|
|
|
`info showInfo`,
|
|
|
|
`
|
|
|
|
info showInfo`,
|
|
|
|
`info
|
|
|
|
showInfo
|
|
|
|
`,
|
|
|
|
`
|
|
|
|
info
|
|
|
|
showInfo
|
|
|
|
`,
|
|
|
|
])('should handle showInfo', (context: string) => {
|
2023-08-26 14:01:56 +03:00
|
|
|
const result = parse(context);
|
|
|
|
noErrorsOrAlternatives(result);
|
2023-08-20 15:38:46 +03:00
|
|
|
|
2023-08-26 14:01:56 +03:00
|
|
|
expect(result.value.$type).toBe(Info);
|
2023-08-20 15:38:46 +03:00
|
|
|
});
|
|
|
|
});
|