Path: redb-route/tests/redb.Route.Tests/Expressions/LogicalShortCircuitTests.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests/Expressions/LogicalShortCircuitTests.cs
----
using AwesomeAssertions;
using redb.Route.Core;
using redb.Route.Expressions;
using redb.Route.Expressions.Ast;
using redb.Route.Predicates;
namespace redb.Route.Tests.Expressions;
///
/// AND and OR short-circuit over the truthiness rule (findings register row 25), and ?? evaluates its right side only
/// when the left is null (row 26): the right side runs only when the left
/// one does not decide. The values are the ones the language gave before; what stops is a side effect or a fault on a
/// right side that does not matter. XOR needs both sides and evaluates both.
///
public sealed class LogicalShortCircuitTests
{
private static Exchange Message(bool flag)
{
var exchange = new Exchange(new Message("x"));
exchange.In.Headers["flag"] = flag;
exchange.In.Headers["n"] = 0;
return exchange;
}
[Theory]
[InlineData("header.flag AND header.n++ > 0", false, 0)]
[InlineData("header.flag && header.n++ > 0", false, 0)]
[InlineData("header.flag OR header.n++ > 0", true, 0)]
[InlineData("header.flag || header.n++ > 0", true, 0)]
[InlineData("header.flag AND header.n++ > 0", true, 1)]
[InlineData("header.flag OR header.n++ > 0", false, 1)]
[InlineData("header.flag XOR header.n++ > 0", false, 1)]
[InlineData("header.flag XOR header.n++ > 0", true, 1)]
public void TheRightSide_RunsOnlyWhenTheLeftDoesNotDecide(string expression, bool flag, int nAfter)
{
var exchange = Message(flag);
new StringExpression(expression).Evaluate