Skip to content

Commit d107857

Browse files
authored
Merge pull request #24 from codingseb/dev
Dev For Version 1.3.4.0
2 parents 682addc + fb266a2 commit d107857

File tree

8 files changed

+408
-105
lines changed

8 files changed

+408
-105
lines changed

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorScriptEvaluateTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,24 @@ public static IEnumerable<TestCaseData> TestCasesForScriptEvaluateTests
683683

684684
#endregion
685685

686+
#region prefix operators
687+
yield return new TestCaseData(Resources.Script0047, null, null, null)
688+
.SetCategory("Script")
689+
.SetCategory("Variable Assignation")
690+
.SetCategory("PrefixOperators")
691+
.SetCategory("++")
692+
.SetCategory("=")
693+
.Returns("x:6 y:6");
694+
yield return new TestCaseData(Resources.Script0048, null, null, null)
695+
.SetCategory("Script")
696+
.SetCategory("Variable Assignation")
697+
.SetCategory("PrefixOperators")
698+
.SetCategory("--")
699+
.SetCategory("=")
700+
.Returns("x:4 y:4");
701+
702+
#endregion
703+
686704
#endregion
687705

688706
#region while

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorTests.cs

Lines changed: 131 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using NUnit.Framework;
1+
using Newtonsoft.Json;
2+
using NUnit.Framework;
3+
using Shouldly;
24
using System;
35
using System.Collections.Generic;
46
using System.Text.RegularExpressions;
5-
using Shouldly;
6-
using Newtonsoft.Json;
77

88
namespace CodingSeb.ExpressionEvaluator.Tests
99
{
@@ -91,6 +91,23 @@ public void TypeTesting(string expression, Type type)
9191

9292
#region Test cases for DirectExpressionEvaluation
9393

94+
#region Other bases numbers
95+
96+
[TestCase("0xab", ExpectedResult = 0xab, Category = "HexNumber")]
97+
[TestCase("0xAB", ExpectedResult = 0xab, Category = "HexNumber")]
98+
[TestCase("0x1", ExpectedResult = 0x1, Category = "HexNumber")]
99+
[TestCase("0xf", ExpectedResult = 0xf, Category = "HexNumber")]
100+
[TestCase("-0xf", ExpectedResult = -0xf, Category = "HexNumber")]
101+
[TestCase("0xff_2a", ExpectedResult = 0xff_2a, Category = "HexNumber")]
102+
103+
[TestCase("0b01100111", ExpectedResult = 0b01100111, Category = "BinaryNumber")]
104+
[TestCase("0b0100", ExpectedResult = 0b0100, Category = "BinaryNumber")]
105+
[TestCase("0b1010", ExpectedResult = 0b1010, Category = "BinaryNumber")]
106+
[TestCase("0b10_10", ExpectedResult = 0b10_10, Category = "BinaryNumber")]
107+
[TestCase("-0b10_10", ExpectedResult = -0b10_10, Category = "BinaryNumber")]
108+
109+
#endregion
110+
94111
#region Null Expression
95112
[TestCase("null", ExpectedResult = null, Category = "Null Expression")]
96113
#endregion
@@ -391,6 +408,16 @@ public void TypeTesting(string expression, Type type)
391408
[TestCase("3 --(2 *+(5 - 3 - +(-Abs(-5) - 6)))", TestOf = typeof(double), ExpectedResult = 29, Category = "ParenthesisPriority")]
392409
#endregion
393410

411+
#region BitwiseComplement
412+
[TestCase("~-10", TestOf = typeof(int), ExpectedResult = 9, Category = "BitwiseComplement")]
413+
[TestCase("~-2", TestOf = typeof(int), ExpectedResult = 1, Category = "BitwiseComplement")]
414+
[TestCase("~-1", TestOf = typeof(int), ExpectedResult = 0, Category = "BitwiseComplement")]
415+
[TestCase("~0", TestOf = typeof(int), ExpectedResult = -1, Category = "BitwiseComplement")]
416+
[TestCase("~1", TestOf = typeof(int), ExpectedResult = -2, Category = "BitwiseComplement")]
417+
[TestCase("~2", TestOf = typeof(int), ExpectedResult = -3, Category = "BitwiseComplement")]
418+
[TestCase("~10", TestOf = typeof(int), ExpectedResult = -11, Category = "BitwiseComplement")]
419+
#endregion
420+
394421
#region SimpleModulo
395422
[TestCase("-4 % 2", TestOf = typeof(int), ExpectedResult = 0, Category = "SimpleModulo")]
396423
[TestCase("-3 % 2", TestOf = typeof(int), ExpectedResult = -1, Category = "SimpleModulo")]
@@ -490,6 +517,24 @@ public void TypeTesting(string expression, Type type)
490517
[TestCase("typeof(string) == 12.GetType()", ExpectedResult = false, Category = "typeof keyword")]
491518
#endregion
492519

520+
#region sizeof keyword
521+
522+
[TestCase("sizeof(sbyte)", ExpectedResult = sizeof(sbyte), Category = "sizeof keyword")]
523+
[TestCase("sizeof(byte)", ExpectedResult = sizeof(byte), Category = "sizeof keyword")]
524+
[TestCase("sizeof(short)", ExpectedResult = sizeof(short), Category = "sizeof keyword")]
525+
[TestCase("sizeof(ushort)", ExpectedResult = sizeof(ushort), Category = "sizeof keyword")]
526+
[TestCase("sizeof(int)", ExpectedResult = sizeof(int), Category = "sizeof keyword")]
527+
[TestCase("sizeof(uint)", ExpectedResult = sizeof(uint), Category = "sizeof keyword")]
528+
[TestCase("sizeof(long)", ExpectedResult = sizeof(long), Category = "sizeof keyword")]
529+
[TestCase("sizeof(ulong)", ExpectedResult = sizeof(ulong), Category = "sizeof keyword")]
530+
[TestCase("sizeof(char)", ExpectedResult = sizeof(char), Category = "sizeof keyword")]
531+
[TestCase("sizeof(float)", ExpectedResult = sizeof(float), Category = "sizeof keyword")]
532+
[TestCase("sizeof(double)", ExpectedResult = sizeof(double), Category = "sizeof keyword")]
533+
[TestCase("sizeof(decimal)", ExpectedResult = sizeof(decimal), Category = "sizeof keyword")]
534+
[TestCase("sizeof(bool)", ExpectedResult = sizeof(bool), Category = "sizeof keyword")]
535+
536+
#endregion
537+
493538
#region Create instance with new Keyword
494539
[TestCase("new ClassForTest1().GetType()", ExpectedResult = typeof(ClassForTest1), Category = "Create instance with new Keyword")]
495540
[TestCase("new ClassForTest2(15).GetType()", ExpectedResult = typeof(ClassForTest2), Category = "Create instance with new Keyword")]
@@ -970,9 +1015,7 @@ public static IEnumerable<TestCaseData> TestCasesForWithCustomVariablesExpressio
9701015

9711016
yield return new TestCaseData("+x", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary +").Returns(5);
9721017
yield return new TestCaseData("-5 + +x", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary +").Returns(0);
973-
yield return new TestCaseData("-5++x", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary +").Returns(0);
9741018
yield return new TestCaseData("5 + +x", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary +").Returns(10);
975-
yield return new TestCaseData("5++x", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary +").Returns(10);
9761019
yield return new TestCaseData("5 - +x", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary +").Returns(0);
9771020
yield return new TestCaseData("5-+x", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary +").Returns(0);
9781021
yield return new TestCaseData("-5 - +x", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary +").Returns(-10);
@@ -985,23 +1028,15 @@ public static IEnumerable<TestCaseData> TestCasesForWithCustomVariablesExpressio
9851028
yield return new TestCaseData("5 + -x", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary -").Returns(0);
9861029
yield return new TestCaseData("5+-x", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary -").Returns(0);
9871030
yield return new TestCaseData("-5 - -x", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary -").Returns(0);
988-
yield return new TestCaseData("-5--x", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary -").Returns(0);
9891031
yield return new TestCaseData("5 - -x", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary -").Returns(10);
990-
yield return new TestCaseData("5--x", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary -").Returns(10);
9911032
yield return new TestCaseData("-x - -y", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary -").Returns(15);
992-
yield return new TestCaseData("-x--y", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary -").Returns(15);
9931033
yield return new TestCaseData("+x - -y", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary both +-").Returns(25);
994-
yield return new TestCaseData("+x--y", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary both +-").Returns(25);
9951034
yield return new TestCaseData("+x + -y", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary both +-").Returns(-15);
9961035
yield return new TestCaseData("+x+-y", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary both +-").Returns(-15);
9971036
yield return new TestCaseData("-x - +y", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary both +-").Returns(-25);
9981037
yield return new TestCaseData("-x-+y", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary both +-").Returns(-25);
9991038
yield return new TestCaseData("-x + +y", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary both +-").Returns(15);
1000-
yield return new TestCaseData("-x++y", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary both +-").Returns(15);
1001-
yield return new TestCaseData("-x++y", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary both +-").Returns(15);
10021039
yield return new TestCaseData("(-x + +y)", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary both +-,Parenthis").Returns(15);
1003-
yield return new TestCaseData("(-x++y)", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary both +-,Parenthis").Returns(15);
1004-
yield return new TestCaseData("-(-x++y)", variablesForSimpleVariablesInjection, true).SetCategory("SimpleVariablesInjection,Unary both +-,Parenthis").Returns(-15);
10051040

10061041
yield return new TestCaseData("ISTHISREAL", variablesForSimpleVariablesInjection, false).SetCategory("SimpleVariablesInjection,IgnoreCase").Returns(true).SetCategory("Options, OptionCaseSensitiveEvaluationActive");
10071042
yield return new TestCaseData("isthisreal", variablesForSimpleVariablesInjection, false).SetCategory("SimpleVariablesInjection,IgnoreCase").Returns(true).SetCategory("Options, OptionCaseSensitiveEvaluationActive");
@@ -1367,5 +1402,88 @@ public void ExceptionThrowingEvaluation(ExpressionEvaluator evaluator, string ex
13671402
}
13681403

13691404
#endregion
1405+
1406+
#region EvaluateWithSpecificEvaluator
1407+
1408+
#region TestCasesEvaluateWithSpecificEvaluator
1409+
1410+
public static IEnumerable<TestCaseData> TestCasesEvaluateWithSpecificEvaluator
1411+
{
1412+
get
1413+
{
1414+
#region Different culture for numbers
1415+
1416+
yield return new TestCaseData(new ExpressionEvaluator
1417+
{
1418+
OptionNumberParsingDecimalSeparator = ",",
1419+
}
1420+
, "0,5")
1421+
.Returns(0.5)
1422+
.SetCategory("Options")
1423+
.SetCategory("Numbers Culture");
1424+
1425+
yield return new TestCaseData(new ExpressionEvaluator
1426+
{
1427+
OptionNumberParsingDecimalSeparator = "'",
1428+
}
1429+
, "0'5")
1430+
.Returns(0.5)
1431+
.SetCategory("Options")
1432+
.SetCategory("Numbers Culture");
1433+
1434+
yield return new TestCaseData(new ExpressionEvaluator
1435+
{
1436+
OptionNumberParsingDecimalSeparator = ".",
1437+
}
1438+
, "0.5")
1439+
.Returns(0.5)
1440+
.SetCategory("Options")
1441+
.SetCategory("Numbers Culture");
1442+
1443+
yield return new TestCaseData(new ExpressionEvaluator
1444+
{
1445+
OptionNumberParsingDecimalSeparator = ",",
1446+
OptionFunctionArgumentsSeparator = ";"
1447+
}
1448+
, "Max(0,5; 0,7)")
1449+
.Returns(0.7)
1450+
.SetCategory("Options")
1451+
.SetCategory("Numbers Culture");
1452+
1453+
yield return new TestCaseData(new ExpressionEvaluator
1454+
{
1455+
OptionNumberParsingDecimalSeparator = ",",
1456+
OptionNumberParsingThousandSeparator = "'",
1457+
OptionFunctionArgumentsSeparator = ";"
1458+
}
1459+
, "Max(1'200,5; 1'111'000,7)")
1460+
.Returns(1111000.7)
1461+
.SetCategory("Options")
1462+
.SetCategory("Numbers Culture");
1463+
1464+
yield return new TestCaseData(new ExpressionEvaluator
1465+
{
1466+
OptionNumberParsingDecimalSeparator = ",",
1467+
OptionNumberParsingThousandSeparator = "'",
1468+
OptionInitializersSeparator = ";"
1469+
}
1470+
, "new double[]{1'200,5; 1'111'000,7}.Max()")
1471+
.Returns(1111000.7)
1472+
.SetCategory("Options")
1473+
.SetCategory("Numbers Culture");
1474+
1475+
#endregion
1476+
}
1477+
}
1478+
1479+
#endregion
1480+
1481+
[TestCaseSource(nameof(TestCasesEvaluateWithSpecificEvaluator))]
1482+
public object EvaluateWithSpecificEvaluator(ExpressionEvaluator evaluator, string expression)
1483+
{
1484+
return evaluator.Evaluate(expression);
1485+
}
1486+
1487+
#endregion
13701488
}
13711489
}

CodingSeb.ExpressionEvaluator.Tests/Resources.Designer.cs

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CodingSeb.ExpressionEvaluator.Tests/Resources.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,10 @@
256256
<data name="Script0046" type="System.Resources.ResXFileRef, System.Windows.Forms">
257257
<value>resources\script0046.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
258258
</data>
259+
<data name="Script0047" type="System.Resources.ResXFileRef, System.Windows.Forms">
260+
<value>resources\script0047.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
261+
</data>
262+
<data name="Script0048" type="System.Resources.ResXFileRef, System.Windows.Forms">
263+
<value>resources\script0048.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
264+
</data>
259265
</root>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* Script0047 */
2+
x = 5;
3+
y = ++x;
4+
$"x:{x} y:{y}";
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* Script0048 */
2+
x = 5;
3+
y = --x;
4+
$"x:{x} y:{y}";

CodingSeb.ExpressionEvaluator/CodingSeb.ExpressionEvaluator.csproj

Lines changed: 16 additions & 18 deletions
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. And from version 1.2.0 can execute small C# like scripts</Description>
77
<Copyright>Copyright © Coding Seb 2017</Copyright>
8-
<Version>1.3.3.0</Version>
9-
<AssemblyVersion>1.3.3.0</AssemblyVersion>
10-
<FileVersion>1.3.3.0</FileVersion>
8+
<Version>1.3.4.0</Version>
9+
<AssemblyVersion>1.3.4.0</AssemblyVersion>
10+
<FileVersion>1.3.4.0</FileVersion>
1111
<OutputPath>bin\$(Configuration)\</OutputPath>
1212
<Authors>Coding Seb</Authors>
1313
<PackageId>CodingSeb.ExpressionEvaluator</PackageId>
@@ -18,21 +18,19 @@
1818
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1919
<PackageIconUrl>https://github.com/codingseb/ExpressionEvaluator/blob/master/Icon.png?raw=true</PackageIconUrl>
2020
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
21-
<PackageReleaseNotes>Main improvements
22-
* Support &lt;&gt; syntax for specify types of generics
23-
* Support of creation initializers for collections, dictionnaries and objects
24-
25-
Here a few examples of what this version allow to do :
26-
27-
new List&lt;string&gt;() { "text1", "text2" }
28-
new Dictionnary&lt;string, int&gt; { {"seven", 7}, {"nine", 9}}
29-
new Dictionnary&lt;string, int&gt; { ["seven"]= 7, ["nine"] = 9}
30-
new MyObject() { MyStringProperty = "A value", MyIntProperty = 8}
31-
32-
Other changes
33-
* Add ListOfType Standard function
34-
* A reference on the current evaluator added in VariableEvaluationEventArg and FunctionEvaluationEventArg
35-
* Small improvement of the Indexing []</PackageReleaseNotes>
21+
<PackageReleaseNotes>* Support ++ and -- as prefix operators
22+
* Support ~ as bitwise complement operator
23+
* Support of the sizeof keyword
24+
* Add hexadecimal and binary notations for int values with 0x and 0b prefixes
25+
* Add the _ (underscore) as digit separator in numbers (all notations)
26+
* Add the following options to have a culture dependant way to evaluate numbers
27+
* CultureInfoForNumberParsing
28+
* OptionNumberParsingDecimalSeparator
29+
* OptionNumberParsingThousandSeparator
30+
* OptionFunctionArgumentsSeparator
31+
* OptionInitializersSeparator
32+
* Some memory management and performance improvement
33+
* Some bugs corrections</PackageReleaseNotes>
3634
</PropertyGroup>
3735
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
3836
<DebugType>full</DebugType>

0 commit comments

Comments
 (0)