Skip to content

Commit

Permalink
Allow negative numbers in the typechecker
Browse files Browse the repository at this point in the history
Closes #87
  • Loading branch information
pSub committed Mar 30, 2022
1 parent cc52b38 commit 4e39818
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private static Either<ValidationResult.Builder.ElementStep, ExpressionType> type
}

private static Either<ValidationResult.Builder.ElementStep, ExpressionType> typecheckUnaryExpression(final Context context, final Operator operator, final FeelExpression operand) {
final Stream<Operator> allowedOperators = Stream.of(Operator.GT, Operator.GE, Operator.LT, Operator.LE, Operator.NOT);
final Stream<Operator> allowedOperators = Stream.of(Operator.GT, Operator.GE, Operator.LT, Operator.LE, Operator.NOT, Operator.SUB);
return typecheck(context, operand).bind(type ->
check(allowedOperators.anyMatch(operator::equals), "Operator is not supported in UnaryExpression.")
.orElse(checkOperatorCompatibility(type, operator))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void unboundVariableHasNoType() {
}

@ParameterizedTest
@CsvSource({"<5, INTEGER", "<5.2, DOUBLE"})
@CsvSource({"<5, INTEGER", "<5.2, DOUBLE", "-1, INTEGER"})
void lessThanExpressionHasNumericType(String input, String expectedType) {
final FeelExpression expression = FeelParser.PARSER.parse(input);
final Either<ValidationResult.Builder.ElementStep, ExpressionType> type = FeelTypecheck.typecheck(expression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class OutputEntryTypeValidatorTest extends WithDecisionTable {
private final OutputEntryTypeValidator testee = new OutputEntryTypeValidator();

@ParameterizedTest
@CsvSource({"integer, 42", "long, 42", "double, 42", "integer, "})
@CsvSource({"integer, 42", "long, 42", "double, 42", "integer, -1", "integer, "})
void shouldAcceptWellTypedOutputExpression(final String typeref, final String textContent) {
final Output output = modelInstance.newInstance(Output.class);
output.setTypeRef(typeref);
Expand Down

0 comments on commit 4e39818

Please sign in to comment.