test: update all parser test cases

This commit is contained in:
Reda Al Sulais
2023-11-03 22:35:01 +03:00
parent 1cda37659e
commit 922bb1452f
3 changed files with 113 additions and 163 deletions

View File

@@ -1,26 +1,9 @@
import type { LangiumParser, ParseResult } from 'langium';
import { describe, expect, it } from 'vitest';
import type { InfoServices } 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 parser: LangiumParser = services.parser.LangiumParser;
function createInfoTestServices(): {
services: InfoServices;
parse: (input: string) => ParseResult<Info>;
} {
const parse = (input: string) => {
return parser.parse<Info>(input);
};
return { services, parse };
}
import { Info } from '../src/language/index.js';
import { expectNoErrorsOrAlternatives, infoParse as parse } from './test-util.js';
describe('info', () => {
const { parse } = createInfoTestServices();
it.each([
`info`,
`
@@ -32,26 +15,34 @@ describe('info', () => {
`,
])('should handle empty info', (context: string) => {
const result = parse(context);
noErrorsOrAlternatives(result);
expectNoErrorsOrAlternatives(result);
expect(result.value.$type).toBe(Info);
});
it.each([
`info showInfo`,
`info showInfo
`,
`
info showInfo`,
`info
showInfo`,
`info
showInfo
`,
`
info
showInfo
`,
`
info
showInfo`,
`
info showInfo
`,
])('should handle showInfo', (context: string) => {
const result = parse(context);
noErrorsOrAlternatives(result);
expectNoErrorsOrAlternatives(result);
expect(result.value.$type).toBe(Info);
});
});