Skip to content

Commit

Permalink
Use extractTestElements in execution lib
Browse files Browse the repository at this point in the history
  • Loading branch information
georg-schwarz committed May 28, 2024
1 parent 99dcda2 commit 5a5ea86
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import {
type BlockDefinition,
type InternalValueRepresentation,
type JayveeServices,
type TypedConstraintDefinition,
createJayveeServices,
isTypedConstraintDefinition,
} from '@jvalue/jayvee-language-server';
import { extractTestElements } from '@jvalue/jayvee-language-server/test';
import {
type ParseHelperOptions,
expectNoParserAndLexerErrors,
Expand All @@ -18,7 +20,6 @@ import {
import {
type AstNode,
type AstNodeLocator,
AstUtils,
type LangiumDocument,
} from 'langium';
import { NodeFileSystem } from 'langium/node';
Expand Down Expand Up @@ -53,14 +54,11 @@ describe('Validation of AllowlistConstraintExecutor', () => {
'pipelines@0/blocks@2',
) as BlockDefinition;

const allElements = AstUtils.streamAllContents(document.parseResult.value);
const allConstraints = [...allElements.filter(isTypedConstraintDefinition)];
expect(
allConstraints.length > 0,
'No constraint definition found in test file',
);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const constraint = allConstraints[0]!;
const constraint = extractTestElements(
document,
(x): x is TypedConstraintDefinition => isTypedConstraintDefinition(x),
)[0]!;

return new AllowlistConstraintExecutor().isValid(
value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ import {
type BlockDefinition,
type InternalValueRepresentation,
type JayveeServices,
type TypedConstraintDefinition,
createJayveeServices,
isTypedConstraintDefinition,
} from '@jvalue/jayvee-language-server';
import {
type ParseHelperOptions,
expectNoParserAndLexerErrors,
extractTestElements,
parseHelper,
readJvTestAssetHelper,
} from '@jvalue/jayvee-language-server/test';
import {
type AstNode,
type AstNodeLocator,
AstUtils,
type LangiumDocument,
} from 'langium';
import { NodeFileSystem } from 'langium/node';
Expand Down Expand Up @@ -53,14 +54,11 @@ describe('Validation of DenylistConstraintExecutor', () => {
'pipelines@0/blocks@2',
) as BlockDefinition;

const allElements = AstUtils.streamAllContents(document.parseResult.value);
const allConstraints = [...allElements.filter(isTypedConstraintDefinition)];
expect(
allConstraints.length > 0,
'No constraint definition found in test file',
);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const constraint = allConstraints[0]!;
const constraint = extractTestElements(
document,
(x): x is TypedConstraintDefinition => isTypedConstraintDefinition(x),
)[0]!;

return new DenylistConstraintExecutor().isValid(
value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import {
type BlockDefinition,
type ExpressionConstraintDefinition,
type InternalValueRepresentation,
type JayveeServices,
createJayveeServices,
Expand All @@ -12,13 +13,13 @@ import {
import {
type ParseHelperOptions,
expectNoParserAndLexerErrors,
extractTestElements,
parseHelper,
readJvTestAssetHelper,
} from '@jvalue/jayvee-language-server/test';
import {
type AstNode,
type AstNodeLocator,
AstUtils,
type LangiumDocument,
} from 'langium';
import { NodeFileSystem } from 'langium/node';
Expand Down Expand Up @@ -53,16 +54,12 @@ describe('Validation of AllowlistConstraintExecutor', () => {
'pipelines@0/blocks@2',
) as BlockDefinition;

const allElements = AstUtils.streamAllContents(document.parseResult.value);
const allConstraints = [
...allElements.filter(isExpressionConstraintDefinition),
];
expect(
allConstraints.length > 0,
'No constraint definition found in test file',
);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const constraint = allConstraints[0]!;
const constraint = extractTestElements(
document,
(x): x is ExpressionConstraintDefinition =>
isExpressionConstraintDefinition(x),
)[0]!;

return new ExpressionConstraintExecutor(constraint).isValid(
value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ import {
type BlockDefinition,
type InternalValueRepresentation,
type JayveeServices,
type TypedConstraintDefinition,
createJayveeServices,
isTypedConstraintDefinition,
} from '@jvalue/jayvee-language-server';
import {
type ParseHelperOptions,
expectNoParserAndLexerErrors,
extractTestElements,
parseHelper,
readJvTestAssetHelper,
} from '@jvalue/jayvee-language-server/test';
import {
type AstNode,
type AstNodeLocator,
AstUtils,
type LangiumDocument,
} from 'langium';
import { NodeFileSystem } from 'langium/node';
Expand Down Expand Up @@ -53,14 +54,11 @@ describe('Validation of LengthConstraintExecutor', () => {
'pipelines@0/blocks@2',
) as BlockDefinition;

const allElements = AstUtils.streamAllContents(document.parseResult.value);
const allConstraints = [...allElements.filter(isTypedConstraintDefinition)];
expect(
allConstraints.length > 0,
'No constraint definition found in test file',
);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const constraint = allConstraints[0]!;
const constraint = extractTestElements(
document,
(x): x is TypedConstraintDefinition => isTypedConstraintDefinition(x),
)[0]!;

return new LengthConstraintExecutor().isValid(
value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ import {
type BlockDefinition,
type InternalValueRepresentation,
type JayveeServices,
type TypedConstraintDefinition,
createJayveeServices,
initializeWorkspace,
isTypedConstraintDefinition,
} from '@jvalue/jayvee-language-server';
import {
type ParseHelperOptions,
expectNoParserAndLexerErrors,
extractTestElements,
parseHelper,
readJvTestAssetHelper,
} from '@jvalue/jayvee-language-server/test';
import {
type AstNode,
type AstNodeLocator,
AstUtils,
type LangiumDocument,
} from 'langium';
import { NodeFileSystem } from 'langium/node';
Expand Down Expand Up @@ -54,14 +55,11 @@ describe('Validation of RangeConstraintExecutor', () => {
'pipelines@0/blocks@2',
) as BlockDefinition;

const allElements = AstUtils.streamAllContents(document.parseResult.value);
const allConstraints = [...allElements.filter(isTypedConstraintDefinition)];
expect(
allConstraints.length > 0,
'No constraint definition found in test file',
);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const constraint = allConstraints[0]!;
const constraint = extractTestElements(
document,
(x): x is TypedConstraintDefinition => isTypedConstraintDefinition(x),
)[0]!;

return new RangeConstraintExecutor().isValid(
value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ import {
type BlockDefinition,
type InternalValueRepresentation,
type JayveeServices,
type TypedConstraintDefinition,
createJayveeServices,
isTypedConstraintDefinition,
} from '@jvalue/jayvee-language-server';
import {
type ParseHelperOptions,
expectNoParserAndLexerErrors,
extractTestElements,
parseHelper,
readJvTestAssetHelper,
} from '@jvalue/jayvee-language-server/test';
import {
type AstNode,
type AstNodeLocator,
AstUtils,
type LangiumDocument,
} from 'langium';
import { NodeFileSystem } from 'langium/node';
Expand Down Expand Up @@ -53,14 +54,11 @@ describe('Validation of RegexConstraintExecutor', () => {
'pipelines@0/blocks@2',
) as BlockDefinition;

const allElements = AstUtils.streamAllContents(document.parseResult.value);
const allConstraints = [...allElements.filter(isTypedConstraintDefinition)];
expect(
allConstraints.length > 0,
'No constraint definition found in test file',
);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const constraint = allConstraints[0]!;
const constraint = extractTestElements(
document,
(x): x is TypedConstraintDefinition => isTypedConstraintDefinition(x),
)[0]!;

return new RegexConstraintExecutor().isValid(
value,
Expand Down
11 changes: 6 additions & 5 deletions libs/execution/src/lib/transforms/transform-executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@ import path from 'node:path';
import {
type InternalValueRepresentation,
type JayveeServices,
type TransformDefinition,
createJayveeServices,
isTransformDefinition,
} from '@jvalue/jayvee-language-server';
import {
type ParseHelperOptions,
expectNoParserAndLexerErrors,
extractTestElements,
loadTestExtensions,
parseHelper,
readJvTestAssetHelper,
} from '@jvalue/jayvee-language-server/test';
import {
type AstNode,
type AstNodeLocator,
AstUtils,
type LangiumDocument,
} from 'langium';
import { NodeFileSystem } from 'langium/node';
Expand Down Expand Up @@ -78,11 +79,11 @@ describe('Validation of TransformExecutor', () => {
const document = await parse(input, { validation: true });
expectNoParserAndLexerErrors(document);

const allElements = AstUtils.streamAllContents(document.parseResult.value);
const allTransforms = [...allElements.filter(isTransformDefinition)];
expect(allTransforms.length > 0);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const transform = allTransforms[0]!;
const transform = extractTestElements(
document,
(x): x is TransformDefinition => isTransformDefinition(x),
)[0]!;

const executionContext = getTestExecutionContext(
locator,
Expand Down

0 comments on commit 5a5ea86

Please sign in to comment.