diff --git a/src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.VisitExpression.Predicate.cs b/src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.VisitExpression.Predicate.cs index 76f1dc5..b31aa4e 100644 --- a/src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.VisitExpression.Predicate.cs +++ b/src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.VisitExpression.Predicate.cs @@ -58,10 +58,10 @@ public override Expression VisitLogicalExpression([NotNull] SimpleflowParser.Log switch (symbolType) { case SimpleflowLexer.And: - return Expression.And(left, right); + return Expression.AndAlso(left, right); case SimpleflowLexer.Or: - return Expression.Or(left, right); + return Expression.OrElse(left, right); } return null; diff --git a/src/Simpleflow/Simpleflow.csproj b/src/Simpleflow/Simpleflow.csproj index bba9532..486bac2 100644 --- a/src/Simpleflow/Simpleflow.csproj +++ b/src/Simpleflow/Simpleflow.csproj @@ -3,7 +3,7 @@ net48;netcoreapp3.1;net6.0; PackageIcon.png 1.0.11 - beta3 + beta4 README.md diff --git a/test/Simpleflow.Tests/Scripting/PredicateStatementsTest.cs b/test/Simpleflow.Tests/Scripting/PredicateStatementsTest.cs index 40be5de..6b2986e 100644 --- a/test/Simpleflow.Tests/Scripting/PredicateStatementsTest.cs +++ b/test/Simpleflow.Tests/Scripting/PredicateStatementsTest.cs @@ -3,7 +3,7 @@ using Xunit; using Simpleflow.Tests.Helpers; - +using System.Collections.Generic; namespace Simpleflow.Tests.Scripting { @@ -153,5 +153,30 @@ rule when d2 < d1 then Assert.Single(output.Messages); } + + [Fact] + public void CheckShortCircuitingAndOperator() + { + // Arrange + + var script = + @" + rule when $exists(dict: arg, key: 'ContentType') and arg['ContentType'] == none then + message 'got it' + "; + + FlowOutput output = SimpleflowEngine.Run(script, + new Dictionary { {"test", null } } + , + new FunctionRegister().Add("exists", (System.Func, string, bool>)Exists)); + + Assert.Empty(output.Messages); + } + + public static bool Exists(IDictionary dict, string key) + { + return dict.ContainsKey(key); + } + } }