ExpressionParser icon indicating copy to clipboard operation
ExpressionParser copied to clipboard

Unary minus after parenthesis

Open jnyrup opened this issue 2 years ago • 0 comments

The expression "(-50)" is not correctly handled. DetermineOperatorType does not detect that - after an ExpressionTokenType.OpenParenthesis is a unary minus and not binary minus. So HandleOperator will treat it as a binary number which fails as there is only a single operand.

[TestMethod]
public void Handle_Unary_Minus_Inside_Parentheses()
{
    GivenInput("(-50)");
    ExpectResult("-50");
}

A workaround is avoid unary minus directly after a parenthesis by using "(0+-50)"

jnyrup avatar Feb 14 '23 17:02 jnyrup