Skip to content

Commit b9bc766

Browse files
authored
Merge pull request #60 from codingseb/dev
Dev
2 parents 3955b0b + dbe81db commit b9bc766

File tree

4 files changed

+167
-51
lines changed

4 files changed

+167
-51
lines changed

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorTests.cs

+17-2
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,13 @@ public static IEnumerable<TestCaseData> TestCasesForWithCustomVariablesExpressio
11111111
yield return new TestCaseData("nullVar?[1][3]", onInstanceVariables, true).SetCategory("Instance Property,Null Conditional indexing").Returns(null);
11121112
yield return new TestCaseData("simpleArray2?[3]?.Trim()", onInstanceVariables, true).SetCategory("Instance Property,Null Conditional indexing").Returns(null);
11131113

1114+
yield return new TestCaseData( "false && 1/0 == 0", onInstanceVariables, true ).SetCategory( "Instance Property,And Conditional" ).Returns( false );
1115+
yield return new TestCaseData( "!string.IsNullOrEmpty(nullVar) && nullVar.StartsWith(\"ABC\")", onInstanceVariables, true ).SetCategory( "Instance Property,And Conditional" ).Returns( false );
1116+
yield return new TestCaseData( "string.IsNullOrEmpty(nullVar) || nullVar.StartsWith(\"ABC\")", onInstanceVariables, true ).SetCategory( "Instance Property,Or Conditional" ).Returns( true );
1117+
yield return new TestCaseData( "true || 1/0 == 0", onInstanceVariables, true ).SetCategory( "Instance Property,Or Conditional" ).Returns( true );
1118+
yield return new TestCaseData( "false && true || true", onInstanceVariables, true ).SetCategory( "Instance Property,Or Conditional,And Conditional,Precedence check" ).Returns( true );
1119+
yield return new TestCaseData( "true || true && false", onInstanceVariables, true ).SetCategory( "Instance Property,Or Conditional,And Conditional,Precedence check" ).Returns( true );
1120+
11141121
yield return new TestCaseData("simpleInt.ToString()", onInstanceVariables, true).SetCategory("Instance Method").Returns("42");
11151122
yield return new TestCaseData("simpleInt.ToString().Length", onInstanceVariables, true).SetCategory("Instance Method,Instance Property").Returns(2);
11161123

@@ -1141,6 +1148,11 @@ public static IEnumerable<TestCaseData> TestCasesForWithCustomVariablesExpressio
11411148
yield return new TestCaseData("simpleInt++ - simpleInt", onInstanceVariables, true).SetCategory("Postfix operator, ++").Returns(-1);
11421149
yield return new TestCaseData("simpleInt--", onInstanceVariables, true).SetCategory("Postfix operator, --").Returns(42);
11431150
yield return new TestCaseData("simpleInt-- - simpleInt", onInstanceVariables, true).SetCategory("Postfix operator, --").Returns(1);
1151+
1152+
yield return new TestCaseData("false && 1/0>0", onInstanceVariables, true ).SetCategory( "Conditional And, negative left operand (should respect left associativity)" ).Returns( false );
1153+
yield return new TestCaseData("true || 1/0>0", onInstanceVariables, true ).SetCategory( "Conditional Or, positive left operand (should respect left associativity)" ).Returns( true );
1154+
yield return new TestCaseData("false && (true && 1/0>0)", onInstanceVariables, true ).SetCategory( "Conditional And, negative left operand (should respect left associativity)" ).Returns( false );
1155+
yield return new TestCaseData("true || (false || 1/0>0)", onInstanceVariables, true ).SetCategory( "Conditional Or, positive left operand (should respect left associativity)" ).Returns( true );
11441156
#endregion
11451157

11461158
#region Delegates as a variable
@@ -1426,7 +1438,7 @@ public static IEnumerable<TestCaseData> TestCasesForExceptionThrowingEvaluation
14261438
evaluator = new ExpressionEvaluator(new Dictionary<string, object>
14271439
{
14281440
{ "P1var", "P1" },
1429-
{ "myObj", new ClassForTest1() },
1441+
{ "myObj", new ClassForTest1() }
14301442
});
14311443

14321444
evaluator.PreEvaluateVariable += (sender, e) =>
@@ -1446,7 +1458,10 @@ public static IEnumerable<TestCaseData> TestCasesForExceptionThrowingEvaluation
14461458
yield return new TestCaseData(evaluator, "myObj.PropertyThatWillFailed", typeof(ExpressionEvaluatorSyntaxErrorException)).SetCategory("OnTheFly canceled Var");
14471459
yield return new TestCaseData(evaluator, "myObj.Add3To(5)", typeof(ExpressionEvaluatorSyntaxErrorException)).SetCategory("OnTheFly canceled Func");
14481460
yield return new TestCaseData(evaluator, "Abs(-5)", typeof(ExpressionEvaluatorSyntaxErrorException)).SetCategory("OnTheFly canceled Func");
1449-
1461+
yield return new TestCaseData(evaluator, "true && 1/0>0",typeof(DivideByZeroException) ).SetCategory( "Conditional And, positive left operand (should lead to exception)" );
1462+
yield return new TestCaseData(evaluator, "false || 1/0>0", typeof( DivideByZeroException ) ).SetCategory( "Conditional Or, positive left operand (should lead to exception associativity)" );
1463+
yield return new TestCaseData(evaluator, "true && (true && 1/0>0)", typeof( DivideByZeroException ) ).SetCategory( "Conditional And, positive left operand (should lead to exception)" );
1464+
yield return new TestCaseData(evaluator, "false || (false || 1/0>0)", typeof( DivideByZeroException ) ).SetCategory( "Conditional Or, positive left operand (should lead to exception associativity)" );
14501465
#endregion
14511466
}
14521467
}

CodingSeb.ExpressionEvaluator.Tests/TestsUtils/XExpressionEvaluator3.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ protected override void Init()
1515
/// <summary>
1616
/// To evaluate DateTimes objects with #year-month-day syntax (#2019-05-28)
1717
/// </summary>
18-
protected virtual bool EvaluateDateTimeSyntax(string expression, Stack<object> stack, ref int i)
18+
protected virtual bool? EvaluateDateTimeSyntax(string expression, Stack<object> stack, ref int i)
1919
{
2020
Match match = Regex.Match(expression.Substring(i), @"^\s*#(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})");
2121

@@ -40,7 +40,7 @@ protected virtual bool EvaluateDateTimeSyntax(string expression, Stack<object> s
4040
/// <summary>
4141
/// To evaluate a string replace with custom ternary indicator
4242
/// </summary>
43-
protected virtual bool EvaluateSpecialTernaryOperator(string expression, Stack<object> stack, ref int i)
43+
protected virtual bool? EvaluateSpecialTernaryOperator(string expression, Stack<object> stack, ref int i)
4444
{
4545
if (expression.Substring(i, 1).Equals("°"))
4646
{

CodingSeb.ExpressionEvaluator/CodingSeb.ExpressionEvaluator.csproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<Product>CodingSeb.ExpressionEvaluator</Product>
66
<Description>A Simple Math and Pseudo C# Expression Evaluator in One C# File. Can also execute small C# like scripts</Description>
77
<Copyright>Copyright © Coding Seb 2017</Copyright>
8-
<Version>1.4.11.0</Version>
9-
<AssemblyVersion>1.4.11.0</AssemblyVersion>
10-
<FileVersion>1.4.11.0</FileVersion>
8+
<Version>1.4.12.0</Version>
9+
<AssemblyVersion>1.4.12.0</AssemblyVersion>
10+
<FileVersion>1.4.12.0</FileVersion>
1111
<OutputPath>bin\$(Configuration)\</OutputPath>
1212
<Authors>Coding Seb</Authors>
1313
<PackageId>CodingSeb.ExpressionEvaluator</PackageId>
@@ -18,7 +18,7 @@
1818
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1919
<PackageIconUrl>https://github.com/codingseb/ExpressionEvaluator/blob/master/Icon.png?raw=true</PackageIconUrl>
2020
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
21-
<PackageReleaseNotes>* Correction of Ternary conditional operator bug</PackageReleaseNotes>
21+
<PackageReleaseNotes>* Correction of a bug on &amp;&amp; and || operators when the right part throw an exception when only the left part should be evaluated</PackageReleaseNotes>
2222
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
2323
<RepositoryUrl>https://github.com/codingseb/ExpressionEvaluator</RepositoryUrl>
2424
</PropertyGroup>

0 commit comments

Comments
 (0)