5 Commits
0.2.0 ... 0.2.2

Author SHA1 Message Date
d6b5408f8a 0.2.2 2020-04-03 13:52:08 +02:00
f0984520f4 Handle strings on boolean operators. 2020-04-03 13:51:06 +02:00
101ec64e95 0.2.1 2019-12-03 10:02:55 +01:00
4eca26daca Tokenizer: Accept "<>" as NotEqual token. 2019-12-03 10:02:20 +01:00
6e9b8c9826 Fix Build.Nuget.cmd for Visual Studio 2017 Enterprise. 2019-12-03 09:59:36 +01:00
10 changed files with 288 additions and 78 deletions

View File

@@ -1,8 +1,8 @@
using System.Reflection;
[assembly: AssemblyCompany("VAR")]
[assembly: AssemblyCopyright("Copyright © VAR 2019")]
[assembly: AssemblyCopyright("Copyright © VAR 2019-2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("0.2.0.0")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyVersion("0.2.2.0")]
[assembly: AssemblyFileVersion("0.2.2.0")]

View File

@@ -300,6 +300,22 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_StringEmptyGreatherThan1_EqualsFalse()
{
string expression = "\"\">1";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_1GreatherThanStringEmpty_EqualsFalse()
{
string expression = "1>\"\"";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_1Equals1_EqualsTrue()
{
@@ -308,6 +324,22 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(true, result);
}
[TestMethod()]
public void Relations_StringEmptyEquals1_EqualsFalse()
{
string expression = "\"\"=1";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_1EqualsStringEmpty_EqualsFalse()
{
string expression = "1=\"\"";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_10NotEquals1_EqualsTrue()
{
@@ -316,6 +348,46 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(true, result);
}
[TestMethod()]
public void Relations_StringEmptyNotEquals1_EqualsTrue()
{
string expression = "\"\"!=1";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(true, result);
}
[TestMethod()]
public void Relations_1NotEqualsStringEmpty_EqualsTrue()
{
string expression = "1!=\"\"";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(true, result);
}
[TestMethod()]
public void Relations_10Different1_EqualsTrue()
{
string expression = "10<>1";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(true, result);
}
[TestMethod()]
public void Relations_StringEmptyDifferent1_EqualsTrue()
{
string expression = "\"\"<>1";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(true, result);
}
[TestMethod()]
public void Relations_1DifferentStringEmpty_EqualsTrue()
{
string expression = "1<>\"\"";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(true, result);
}
[TestMethod()]
public void Relations_10LessThan1_EqualsFalse()
{
@@ -324,6 +396,22 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_StringEmptyLessThan1_EqualsFalse()
{
string expression = "\"\"<1";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_1LessThanStringEmpty_EqualsFalse()
{
string expression = "1<\"\"";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_1GreaterOrEqualThan1_EqualsTrue()
{
@@ -332,6 +420,22 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(true, result);
}
[TestMethod()]
public void Relations_StringEmptyGreaterOrEqualThan1_EqualsFalse()
{
string expression = "\"\">=1";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_1GreaterOrEqualThanStringEmpty_EqualsFalse()
{
string expression = "1>=\"\"";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_1LessOrEqualThan1_EqualsTrue()
{
@@ -356,6 +460,22 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_StringEmptyLessOrEqualThan1_EqualsFalse()
{
string expression = "\"\"<=1";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(false, result);
}
[TestMethod()]
public void Relations_1LessOrEqualThanStringEmpty_EqualsFalse()
{
string expression = "1<=\"\"";
object result = Parser.EvaluateString(expression);
Assert.AreEqual(false, result);
}
#endregion Relations
#region BooleanOps
@@ -439,7 +559,7 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(null, Parser.EvaluateString("100 / null"));
Assert.AreEqual(null, Parser.EvaluateString("null / null"));
}
#endregion
}
}

View File

@@ -5,6 +5,7 @@ if exist "%windir%\Microsoft.Net\Framework\v4.0.30319" set MsBuildPath=%windir%\
if exist "%windir%\Microsoft.Net\Framework64\v4.0.30319" set MsBuildPath=%windir%\Microsoft.NET\Framework64\v4.0.30319
if exist "C:\Program Files (x86)\MSBuild\14.0\Bin" set MsBuildPath=C:\Program Files (x86)\MSBuild\14.0\Bin
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin" set MsBuildPath=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin" set MsBuildPath=C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin
set PATH=%MsBuildPath%;%PATH%
echo %MsBuildPath%

View File

@@ -11,15 +11,6 @@ namespace VAR.ExpressionEvaluator
private static object EqualsOp(object leftValue, object rightValue)
{
if (leftValue == null && rightValue == null)
{
return true;
}
if (leftValue == null || rightValue == null)
{
return false;
}
if (leftValue is string && rightValue is string)
{
return string.Compare((string)leftValue, (string)rightValue) == 0;
@@ -27,19 +18,42 @@ namespace VAR.ExpressionEvaluator
if (leftValue is string)
{
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)leftValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
leftValue = null;
}
else
{
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
}
leftValue = dec;
}
leftValue = dec;
}
if (rightValue is string)
{
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)rightValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
leftValue = null;
}
rightValue = dec;
else
{
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
}
rightValue = dec;
}
}
if (leftValue == null && rightValue == null)
{
return true;
}
if (leftValue == null || rightValue == null)
{
return false;
}
if ((leftValue is decimal) == false || (rightValue is decimal) == false)

View File

@@ -11,11 +11,6 @@ namespace VAR.ExpressionEvaluator
private static object GreaterOrEqualThanOp(object leftValue, object rightValue)
{
if (leftValue == null || rightValue == null)
{
return false;
}
if (leftValue is string && rightValue is string)
{
return string.Compare((string)leftValue, (string)rightValue) >= 0;
@@ -23,19 +18,38 @@ namespace VAR.ExpressionEvaluator
if (leftValue is string)
{
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)leftValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
leftValue = null;
}
else
{
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
}
leftValue = dec;
}
leftValue = dec;
}
if (rightValue is string)
{
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)rightValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
leftValue = null;
}
rightValue = dec;
else
{
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
}
rightValue = dec;
}
}
if (leftValue == null || rightValue == null)
{
return false;
}
if ((leftValue is decimal) == false || (rightValue is decimal) == false)

View File

@@ -11,11 +11,6 @@ namespace VAR.ExpressionEvaluator
private static object GreaterThanOp(object leftValue, object rightValue)
{
if (leftValue == null || rightValue == null)
{
return false;
}
if (leftValue is string && rightValue is string)
{
return string.Compare((string)leftValue, (string)rightValue) > 0;
@@ -23,19 +18,38 @@ namespace VAR.ExpressionEvaluator
if (leftValue is string)
{
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)leftValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
leftValue = null;
}
else
{
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
}
leftValue = dec;
}
leftValue = dec;
}
if (rightValue is string)
{
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)rightValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
leftValue = null;
}
rightValue = dec;
else
{
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
}
rightValue = dec;
}
}
if (leftValue == null || rightValue == null)
{
return false;
}
if ((leftValue is decimal) == false || (rightValue is decimal) == false)

View File

@@ -11,11 +11,6 @@ namespace VAR.ExpressionEvaluator
private static object LessOrEqualThanOp(object leftValue, object rightValue)
{
if (leftValue == null || rightValue == null)
{
return false;
}
if (leftValue is string && rightValue is string)
{
return string.Compare((string)leftValue, (string)rightValue) <= 0;
@@ -23,19 +18,38 @@ namespace VAR.ExpressionEvaluator
if (leftValue is string)
{
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)leftValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
leftValue = null;
}
else
{
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
}
leftValue = dec;
}
leftValue = dec;
}
if (rightValue is string)
{
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)rightValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
leftValue = null;
}
rightValue = dec;
else
{
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
}
rightValue = dec;
}
}
if (leftValue == null || rightValue == null)
{
return false;
}
if ((leftValue is decimal) == false || (rightValue is decimal) == false)

View File

@@ -11,11 +11,6 @@ namespace VAR.ExpressionEvaluator
private static object LessThanOp(object leftValue, object rightValue)
{
if (leftValue == null || rightValue == null)
{
return false;
}
if (leftValue is string && rightValue is string)
{
return string.Compare((string)leftValue, (string)rightValue) < 0;
@@ -23,19 +18,38 @@ namespace VAR.ExpressionEvaluator
if (leftValue is string)
{
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)leftValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
leftValue = null;
}
else
{
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
}
leftValue = dec;
}
leftValue = dec;
}
if (rightValue is string)
{
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)rightValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
leftValue = null;
}
rightValue = dec;
else
{
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
}
rightValue = dec;
}
}
if (leftValue == null || rightValue == null)
{
return false;
}
if ((leftValue is decimal) == false || (rightValue is decimal) == false)

View File

@@ -11,15 +11,6 @@ namespace VAR.ExpressionEvaluator
private static object NotEqualsOp(object leftValue, object rightValue)
{
if (leftValue == null && rightValue == null)
{
return false;
}
if (leftValue == null || rightValue == null)
{
return true;
}
if (leftValue is string && rightValue is string)
{
return string.Compare((string)leftValue, (string)rightValue) != 0;
@@ -27,19 +18,42 @@ namespace VAR.ExpressionEvaluator
if (leftValue is string)
{
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)leftValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
leftValue = null;
}
else
{
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
}
leftValue = dec;
}
leftValue = dec;
}
if (rightValue is string)
{
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
if (string.IsNullOrEmpty((string)rightValue))
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
leftValue = null;
}
rightValue = dec;
else
{
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
{
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
}
rightValue = dec;
}
}
if (leftValue == null && rightValue == null)
{
return false;
}
if (leftValue == null || rightValue == null)
{
return true;
}
if ((leftValue is decimal) == false || (rightValue is decimal) == false)

View File

@@ -144,6 +144,11 @@ namespace VAR.ExpressionEvaluator
NextChar();
_currentToken = Token.LessOrEqualThan;
}
if (_currentChar == '>')
{
NextChar();
_currentToken = Token.NotEquals;
}
return;
case '&':