Skip to content

Commit 138fbce

Browse files
author
Rajesh Jinaga
committed
Change non-short circuiting and operator to short-circuiting and , or operator
1 parent 30d644c commit 138fbce

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.VisitExpression.Predicate.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ public override Expression VisitLogicalExpression([NotNull] SimpleflowParser.Log
5858
switch (symbolType)
5959
{
6060
case SimpleflowLexer.And:
61-
return Expression.And(left, right);
61+
return Expression.AndAlso(left, right);
6262

6363
case SimpleflowLexer.Or:
64-
return Expression.Or(left, right);
64+
return Expression.OrElse(left, right);
6565
}
6666

6767
return null;

src/Simpleflow/Simpleflow.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<TargetFrameworks>net48;netcoreapp3.1;net6.0;</TargetFrameworks>
44
<PackageIcon>PackageIcon.png</PackageIcon>
55
<VersionPrefix>1.0.11</VersionPrefix>
6-
<VersionSuffix>beta3</VersionSuffix>
6+
<VersionSuffix>beta4</VersionSuffix>
77
<PackageReadmeFile>README.md</PackageReadmeFile>
88
</PropertyGroup>
99

test/Simpleflow.Tests/Scripting/PredicateStatementsTest.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using Xunit;
55
using Simpleflow.Tests.Helpers;
6-
6+
using System.Collections.Generic;
77

88
namespace Simpleflow.Tests.Scripting
99
{
@@ -153,5 +153,30 @@ rule when d2 < d1 then
153153
Assert.Single(output.Messages);
154154
}
155155

156+
157+
[Fact]
158+
public void CheckShortCircuitingAndOperator()
159+
{
160+
// Arrange
161+
162+
var script =
163+
@"
164+
rule when $exists(dict: arg, key: 'ContentType') and arg['ContentType'] == none then
165+
message 'got it'
166+
";
167+
168+
FlowOutput output = SimpleflowEngine.Run(script,
169+
new Dictionary<string, object> { {"test", null } }
170+
,
171+
new FunctionRegister().Add("exists", (System.Func<IDictionary<string, object>, string, bool>)Exists));
172+
173+
Assert.Empty(output.Messages);
174+
}
175+
176+
public static bool Exists(IDictionary<string, object> dict, string key)
177+
{
178+
return dict.ContainsKey(key);
179+
}
180+
156181
}
157182
}

0 commit comments

Comments
 (0)