TUnit icon indicating copy to clipboard operation
TUnit copied to clipboard

Unclear precedence of AND and OR

Open vbreuss opened this issue 4 months ago • 6 comments

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).

vbreuss avatar Oct 13 '24 03:10 vbreuss