Skip to content

Commit

Permalink
added failOnParseErrors option to validationHelper (#1699)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Dietrich <[email protected]>
  • Loading branch information
cdietrich authored Sep 25, 2024
1 parent 335f9a9 commit 8faa4b8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/langium/src/test/langium-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as assert from 'node:assert';
import { stream } from '../utils/stream.js';
import { Disposable } from '../utils/disposable.js';
import { normalizeEOL } from '../generate/template-string.js';
import { DocumentValidator } from '../validation/document-validator.js';

export interface ParseHelperOptions extends BuildOptions {
/**
Expand Down Expand Up @@ -550,18 +551,29 @@ export interface ValidationResult<T extends AstNode = AstNode> extends AsyncDisp
document: LangiumDocument<T>;
}

export function validationHelper<T extends AstNode = AstNode>(services: LangiumCoreServices): (input: string, options?: ParseHelperOptions) => Promise<ValidationResult<T>> {
export type ValidationHelperOptions = ParseHelperOptions & { failOnParsingErrors?: boolean };

export function validationHelper<T extends AstNode = AstNode>(services: LangiumCoreServices): (input: string, options?: ValidationHelperOptions) => Promise<ValidationResult<T>> {
const parse = parseHelper<T>(services);
return async (input, options) => {
const document = await parse(input, {
...(options ?? {}),
validation: true
});
return {
const result = {
document,
diagnostics: document.diagnostics ?? [],
dispose: () => clearDocuments(services, [document])
};
if (options?.failOnParsingErrors) {
expectNoIssues(result, {
severity: DiagnosticSeverity.Error,
data: {
code: DocumentValidator.ParsingError,
},
});
}
return result;
};
}

Expand Down

0 comments on commit 8faa4b8

Please sign in to comment.