Skip to content

Commit

Permalink
Add at least one negative test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lotes committed Feb 4, 2025
1 parent dedc35c commit 079f4a9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
23 changes: 1 addition & 22 deletions examples/expression/src/type-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* This program and the accompanying materials are made available under the
* terms of the MIT License, which is available in the project root.
******************************************************************************/
import { createTypirServices, InferenceRuleNotApplicable, InferOperatorWithMultipleOperands, InferOperatorWithSingleOperand, isAssignabilityProblem, isInferenceProblem, NO_PARAMETER_NAME, TypirServices, ValidationMessageDetails } from 'typir';
import { createTypirServices, InferenceRuleNotApplicable, InferOperatorWithMultipleOperands, InferOperatorWithSingleOperand, NO_PARAMETER_NAME } from 'typir';
import { BinaryExpression, isAstNode, isBinaryExpression, isNumeric, isPrintout, isUnaryExpression, isVariableDeclaration, isVariableUsage, UnaryExpression } from './ast.js';

export function initializeTypir() {
Expand Down Expand Up @@ -65,26 +65,5 @@ export function initializeTypir() {
return InferenceRuleNotApplicable;
});

typir.validation.Collector.addValidationRule(
(node: unknown) => {
if (isPrintout(node)) {
const actual = typir.Inference.inferType(node.value)!;
if(!Array.isArray(actual)) {
const expected = typeString;
const result = typir.Assignability.getAssignabilityResult(actual, expected);
if(isAssignabilityProblem(result)) {
return [{
$problem: 'ValidationProblem',
languageNode: node,
message: 'Not assignable!',
severity: 'error'
}];
}
}
}
return [];
}
);

return typir;
}
4 changes: 4 additions & 0 deletions examples/expression/test/validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ const typir = initializeTypir();

describe('Validator', () => {
test('Positives', () => {
expectValidationMessages('VAR X = 1+2+3; PRINT X;');
expectValidationMessages('PRINT 1+2+3;');
expectValidationMessages('PRINT "Hallo!";');
expectValidationMessages('PRINT "Hallo!"+"Welt!";');
});
test('Negatives', () => {
expectValidationMessages('PRINT "1"-"2";', 'The given operands for the overloaded function \'-\' match the expected types only partially.');
});
});


Expand Down

0 comments on commit 079f4a9

Please sign in to comment.