Skip to content

Commit

Permalink
Corrected null handling issues with the logical && and || operators a…
Browse files Browse the repository at this point in the history
…nd ensure that there is unit test coverage for these cases.
  • Loading branch information
stephenquan committed Dec 6, 2024
1 parent c96e628 commit 47b5f7a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.303",
"version": "9.0.100",
"rollForward": "latestFeature",
"allowPrerelease": false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public void MathExpressionConverter_WithMultipleVariable_ReturnsCorrectResult(st
[InlineData("x && x1", new object?[] { "Cat", false }, false)]
[InlineData("x && x1", new object?[] { "", false }, "")]
[InlineData("x && x1", new object?[] { false, "" }, false)]
[InlineData("x && x1", new object?[] { null, "Cat" }, null)]
[InlineData("x && x1", new object?[] { "Cat", null }, null)]
[InlineData("x && x1", new object?[] { "", null }, "")]
[InlineData("x && x1", new object?[] { null, "" }, null)]
[InlineData("x || x1", new object?[] { true, true }, true)]
[InlineData("x || x1", new object?[] { false, true }, true)]
[InlineData("x || x1", new object?[] { true, false }, true)]
Expand All @@ -92,12 +96,15 @@ public void MathExpressionConverter_WithMultipleVariable_ReturnsCorrectResult(st
[InlineData("x || x1", new object?[] { "Cat", false }, "Cat")]
[InlineData("x || x1", new object?[] { "", false }, false)]
[InlineData("x || x1", new object?[] { false, "" }, "")]
[InlineData("x || x1", new object?[] { null, "Cat" }, "Cat")]
[InlineData("x || x1", new object?[] { "Cat", null }, "Cat")]
[InlineData("x || x1", new object?[] { "", null }, null)]
[InlineData("x || x1", new object?[] { null, "" }, "")]
[InlineData("x || x1", new object?[] { false, new int[] { 1, 2, 3 } }, new int[] { 1, 2, 3 })]
public void MultiMathExpressionConverter_WithMultipleVariable_ReturnsCorrectLogicalResult(string expression, object?[] variables, object? expectedResult)
{
var mathExpressionConverter = new MultiMathExpressionConverter();
var result = mathExpressionConverter.Convert(variables, typeof(object), expression);
Assert.NotNull(result);
Assert.Equal(expectedResult, result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@ internal MathExpression(string expression, IEnumerable<object?>? arguments = nul
switch (mathOperator.Name)
{
case "if":
case "&&":
case "||":
nullGuard = args[0] is null;
break;
case "and":
case "or":
case "==":
case "!=":
nullGuard = false;
Expand Down

0 comments on commit 47b5f7a

Please sign in to comment.