TUnit
TUnit copied to clipboard
Unclear precedence of AND and OR
I couldn't find anything in the documentation with regards to the precedence between AND and OR.
Consider the following test:
[Test]
public async Task And_Or_Precedence_Test()
{
char[] sut = "CD".ToCharArray();
await Assert.That(sut)
.Contains('A').And
.Contains('B').Or
.Contains('C').And
.Contains('D');
}
I would have expected the test to fail, as I would expect the condition to be interpreted as (A && B) || (C && D)
, to be in line with the operator precedence in C#.
However, this test succeeds, because A && B || C && D
seems to be interpreted as (((A && B) || C) && D)
.