Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation Tests #359

Merged
merged 20 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
createJayveeServices,
useExtension,
} from '../../../lib';
import { validateColumnId } from '../../../lib/validation/checks/column-id';
import {
ParseHelperOptions,
expectNoParserAndLexerErrors,
Expand All @@ -21,6 +20,8 @@ import {
} from '../../../test';
import { TestLangExtension } from '../../../test/extension';

import { validateColumnId } from './column-id';

describe('column-id validation tests', () => {
let parse: (
input: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg
//
// SPDX-License-Identifier: AGPL-3.0-only

import { AstNode, AstNodeLocator, LangiumDocument } from 'langium';
import { NodeFileSystem } from 'langium/node';

import {
EvaluationContext,
ExpressionConstraintDefinition,
RuntimeParameterProvider,
ValidationContext,
createJayveeServices,
useExtension,
} from '../../../lib';
import {
ParseHelperOptions,
expectNoParserAndLexerErrors,
parseHelper,
readJvTestAssetHelper,
validationAcceptorMockImpl,
} from '../../../test';
import { TestLangExtension } from '../../../test/extension';

import { validateExpressionConstraintDefinition } from './expression-constraint-definition';

describe('expression-constraint-definition validation tests', () => {
f3l1x98 marked this conversation as resolved.
Show resolved Hide resolved
let parse: (
input: string,
options?: ParseHelperOptions,
) => Promise<LangiumDocument<AstNode>>;

const validationAcceptorMock = jest.fn(validationAcceptorMockImpl);

let locator: AstNodeLocator;

const readJvTestAsset = readJvTestAssetHelper(
__dirname,
'../../../test/assets/',
);

async function parseAndValidateExpressionConstraintDefinition(input: string) {
const document = await parse(input);
expectNoParserAndLexerErrors(document);

const expressionConstraint =
locator.getAstNode<ExpressionConstraintDefinition>(
document.parseResult.value,
'constraints@0',
) as ExpressionConstraintDefinition;

validateExpressionConstraintDefinition(
expressionConstraint,
new ValidationContext(validationAcceptorMock),
new EvaluationContext(new RuntimeParameterProvider()),
);
}

beforeAll(() => {
// Register test extension
useExtension(new TestLangExtension());
// Create language services
const services = createJayveeServices(NodeFileSystem).Jayvee;
locator = services.workspace.AstNodeLocator;
// Parse function for Jayvee (without validation)
parse = parseHelper(services);
});

afterEach(() => {
// Reset mock
validationAcceptorMock.mockReset();
});

it('should have no error on valid expression constraint', async () => {
const text = readJvTestAsset(
'expression-constraint-definition/valid-text-constraint.jv',
);

await parseAndValidateExpressionConstraintDefinition(text);

expect(validationAcceptorMock).toHaveBeenCalledTimes(0);
});

it('error on incompatible type', async () => {
f3l1x98 marked this conversation as resolved.
Show resolved Hide resolved
const text = readJvTestAsset(
'expression-constraint-definition/invalid-incompatible-type.jv',
);

await parseAndValidateExpressionConstraintDefinition(text);

expect(validationAcceptorMock).toHaveBeenCalledTimes(1);
expect(validationAcceptorMock).toHaveBeenCalledWith(
'error',
`The value needs to be of type boolean but is of type integer`,
expect.any(Object),
);
});

it('info on simplifiable expression constraint', async () => {
f3l1x98 marked this conversation as resolved.
Show resolved Hide resolved
const text = readJvTestAsset(
'expression-constraint-definition/valid-simplify-info.jv',
);

await parseAndValidateExpressionConstraintDefinition(text);

expect(validationAcceptorMock).toHaveBeenCalledTimes(1);
expect(validationAcceptorMock).toHaveBeenCalledWith(
'info',
`The expression can be simplified to 8`,
expect.any(Object),
);
});
});
123 changes: 123 additions & 0 deletions libs/language-server/src/lib/validation/checks/jayvee-model.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg
//
// SPDX-License-Identifier: AGPL-3.0-only

import { AstNode, LangiumDocument } from 'langium';
import { NodeFileSystem } from 'langium/node';

import {
JayveeModel,
ValidationContext,
createJayveeServices,
useExtension,
} from '../../../lib';
import {
ParseHelperOptions,
expectNoParserAndLexerErrors,
parseHelper,
readJvTestAssetHelper,
validationAcceptorMockImpl,
} from '../../../test';
import { TestLangExtension } from '../../../test/extension';

import { validateJayveeModel } from './jayvee-model';

describe('jayvee-model validation tests', () => {
let parse: (
input: string,
options?: ParseHelperOptions,
) => Promise<LangiumDocument<AstNode>>;

const validationAcceptorMock = jest.fn(validationAcceptorMockImpl);

const readJvTestAsset = readJvTestAssetHelper(
__dirname,
'../../../test/assets/',
);

async function parseAndValidateJayveeModel(input: string) {
const document = await parse(input);
expectNoParserAndLexerErrors(document);

const jayveeModel = document.parseResult.value as JayveeModel;

validateJayveeModel(
jayveeModel,
new ValidationContext(validationAcceptorMock),
);
}

beforeAll(() => {
// Register test extension
useExtension(new TestLangExtension());
// Create language services
const services = createJayveeServices(NodeFileSystem).Jayvee;
// Parse function for Jayvee (without validation)
parse = parseHelper(services);
});

afterEach(() => {
// Reset mock
validationAcceptorMock.mockReset();
});

it('error on non unique pipelines', async () => {
const text = readJvTestAsset(
'jayvee-model/invalid-non-unique-pipelines.jv',
);

await parseAndValidateJayveeModel(text);

expect(validationAcceptorMock).toHaveBeenCalledTimes(2);
expect(validationAcceptorMock).toHaveBeenCalledWith(
'error',
`The pipelinedefinition name "Pipeline" needs to be unique.`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you actually found a bug here. It message is supposed to state The pipeline name "Pipeline" needs to be unique.

Same for transforms, valuetypes and constraints.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to directly fix the bug? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@georg-schwarz not sure if you mean me, but if yes I would do that in a separate PR and create an issue for that 😄

expect.any(Object),
);
});

it('error on non unique transforms', async () => {
const text = readJvTestAsset(
'jayvee-model/invalid-non-unique-transforms.jv',
);

await parseAndValidateJayveeModel(text);

expect(validationAcceptorMock).toHaveBeenCalledTimes(2);
expect(validationAcceptorMock).toHaveBeenCalledWith(
'error',
`The transformdefinition name "Transform" needs to be unique.`,
expect.any(Object),
);
});

it('error on non unique valuetypes', async () => {
const text = readJvTestAsset(
'jayvee-model/invalid-non-unique-valuetypes.jv',
);

await parseAndValidateJayveeModel(text);

expect(validationAcceptorMock).toHaveBeenCalledTimes(2);
expect(validationAcceptorMock).toHaveBeenCalledWith(
'error',
`The valuetypedefinition name "ValueType" needs to be unique.`,
expect.any(Object),
);
});

it('error on non unique constraints', async () => {
const text = readJvTestAsset(
'jayvee-model/invalid-non-unique-constraints.jv',
);

await parseAndValidateJayveeModel(text);

expect(validationAcceptorMock).toHaveBeenCalledTimes(2);
expect(validationAcceptorMock).toHaveBeenCalledWith(
'error',
`The expressionconstraintdefinition name "Constraint" needs to be unique.`,
expect.any(Object),
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
createJayveeServices,
useExtension,
} from '../../../lib';
import { validatePipeDefinition } from '../../../lib/validation/checks/pipe-definition';
import {
ParseHelperOptions,
expectNoParserAndLexerErrors,
Expand All @@ -21,6 +20,8 @@ import {
} from '../../../test';
import { TestLangExtension } from '../../../test/extension';

import { validatePipeDefinition } from './pipe-definition';

describe('pipe-definition validation tests', () => {
let parse: (
input: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
createJayveeServices,
useExtension,
} from '../../../lib';
import { validatePipelineDefinition } from '../../../lib/validation/checks/pipeline-definition';
import {
ParseHelperOptions,
expectNoParserAndLexerErrors,
Expand All @@ -21,6 +20,8 @@ import {
} from '../../../test';
import { TestLangExtension } from '../../../test/extension';

import { validatePipelineDefinition } from './pipeline-definition';

describe('pipeline-definition validation tests', () => {
let parse: (
input: string,
Expand Down
Loading