2 Commits
0.2.1 ... 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
8 changed files with 273 additions and 77 deletions

View File

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

View File

@@ -300,6 +300,22 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(false, result); 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()] [TestMethod()]
public void Relations_1Equals1_EqualsTrue() public void Relations_1Equals1_EqualsTrue()
{ {
@@ -308,6 +324,22 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(true, result); 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()] [TestMethod()]
public void Relations_10NotEquals1_EqualsTrue() public void Relations_10NotEquals1_EqualsTrue()
{ {
@@ -316,6 +348,22 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(true, result); 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()] [TestMethod()]
public void Relations_10Different1_EqualsTrue() public void Relations_10Different1_EqualsTrue()
{ {
@@ -324,6 +372,22 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(true, result); 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()] [TestMethod()]
public void Relations_10LessThan1_EqualsFalse() public void Relations_10LessThan1_EqualsFalse()
{ {
@@ -332,6 +396,22 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(false, result); 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()] [TestMethod()]
public void Relations_1GreaterOrEqualThan1_EqualsTrue() public void Relations_1GreaterOrEqualThan1_EqualsTrue()
{ {
@@ -340,6 +420,22 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(true, result); 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()] [TestMethod()]
public void Relations_1LessOrEqualThan1_EqualsTrue() public void Relations_1LessOrEqualThan1_EqualsTrue()
{ {
@@ -364,6 +460,22 @@ namespace VAR.ExpressionEvaluator.Tests
Assert.AreEqual(false, result); 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 #endregion Relations
#region BooleanOps #region BooleanOps

View File

@@ -11,21 +11,18 @@ namespace VAR.ExpressionEvaluator
private static object EqualsOp(object leftValue, object rightValue) 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) if (leftValue is string && rightValue is string)
{ {
return string.Compare((string)leftValue, (string)rightValue) == 0; return string.Compare((string)leftValue, (string)rightValue) == 0;
} }
if (leftValue is string) if (leftValue is string)
{
if (string.IsNullOrEmpty((string)leftValue))
{
leftValue = null;
}
else
{ {
if (decimal.TryParse((string)leftValue, out decimal dec) == false) if (decimal.TryParse((string)leftValue, out decimal dec) == false)
{ {
@@ -33,7 +30,14 @@ namespace VAR.ExpressionEvaluator
} }
leftValue = dec; leftValue = dec;
} }
}
if (rightValue is string) if (rightValue is string)
{
if (string.IsNullOrEmpty((string)rightValue))
{
leftValue = null;
}
else
{ {
if (decimal.TryParse((string)rightValue, out decimal dec) == false) if (decimal.TryParse((string)rightValue, out decimal dec) == false)
{ {
@@ -41,6 +45,16 @@ namespace VAR.ExpressionEvaluator
} }
rightValue = dec; 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) if ((leftValue is decimal) == false || (rightValue is decimal) == false)
{ {

View File

@@ -11,17 +11,18 @@ namespace VAR.ExpressionEvaluator
private static object GreaterOrEqualThanOp(object leftValue, object rightValue) private static object GreaterOrEqualThanOp(object leftValue, object rightValue)
{ {
if (leftValue == null || rightValue == null)
{
return false;
}
if (leftValue is string && rightValue is string) if (leftValue is string && rightValue is string)
{ {
return string.Compare((string)leftValue, (string)rightValue) >= 0; return string.Compare((string)leftValue, (string)rightValue) >= 0;
} }
if (leftValue is string) if (leftValue is string)
{
if (string.IsNullOrEmpty((string)leftValue))
{
leftValue = null;
}
else
{ {
if (decimal.TryParse((string)leftValue, out decimal dec) == false) if (decimal.TryParse((string)leftValue, out decimal dec) == false)
{ {
@@ -29,7 +30,14 @@ namespace VAR.ExpressionEvaluator
} }
leftValue = dec; leftValue = dec;
} }
}
if (rightValue is string) if (rightValue is string)
{
if (string.IsNullOrEmpty((string)rightValue))
{
leftValue = null;
}
else
{ {
if (decimal.TryParse((string)rightValue, out decimal dec) == false) if (decimal.TryParse((string)rightValue, out decimal dec) == false)
{ {
@@ -37,6 +45,12 @@ namespace VAR.ExpressionEvaluator
} }
rightValue = dec; rightValue = dec;
} }
}
if (leftValue == null || rightValue == null)
{
return false;
}
if ((leftValue is decimal) == false || (rightValue is decimal) == false) if ((leftValue is decimal) == false || (rightValue is decimal) == false)
{ {

View File

@@ -11,17 +11,18 @@ namespace VAR.ExpressionEvaluator
private static object GreaterThanOp(object leftValue, object rightValue) private static object GreaterThanOp(object leftValue, object rightValue)
{ {
if (leftValue == null || rightValue == null)
{
return false;
}
if (leftValue is string && rightValue is string) if (leftValue is string && rightValue is string)
{ {
return string.Compare((string)leftValue, (string)rightValue) > 0; return string.Compare((string)leftValue, (string)rightValue) > 0;
} }
if (leftValue is string) if (leftValue is string)
{
if (string.IsNullOrEmpty((string)leftValue))
{
leftValue = null;
}
else
{ {
if (decimal.TryParse((string)leftValue, out decimal dec) == false) if (decimal.TryParse((string)leftValue, out decimal dec) == false)
{ {
@@ -29,7 +30,14 @@ namespace VAR.ExpressionEvaluator
} }
leftValue = dec; leftValue = dec;
} }
}
if (rightValue is string) if (rightValue is string)
{
if (string.IsNullOrEmpty((string)rightValue))
{
leftValue = null;
}
else
{ {
if (decimal.TryParse((string)rightValue, out decimal dec) == false) if (decimal.TryParse((string)rightValue, out decimal dec) == false)
{ {
@@ -37,6 +45,12 @@ namespace VAR.ExpressionEvaluator
} }
rightValue = dec; rightValue = dec;
} }
}
if (leftValue == null || rightValue == null)
{
return false;
}
if ((leftValue is decimal) == false || (rightValue is decimal) == false) if ((leftValue is decimal) == false || (rightValue is decimal) == false)
{ {

View File

@@ -11,17 +11,18 @@ namespace VAR.ExpressionEvaluator
private static object LessOrEqualThanOp(object leftValue, object rightValue) private static object LessOrEqualThanOp(object leftValue, object rightValue)
{ {
if (leftValue == null || rightValue == null)
{
return false;
}
if (leftValue is string && rightValue is string) if (leftValue is string && rightValue is string)
{ {
return string.Compare((string)leftValue, (string)rightValue) <= 0; return string.Compare((string)leftValue, (string)rightValue) <= 0;
} }
if (leftValue is string) if (leftValue is string)
{
if (string.IsNullOrEmpty((string)leftValue))
{
leftValue = null;
}
else
{ {
if (decimal.TryParse((string)leftValue, out decimal dec) == false) if (decimal.TryParse((string)leftValue, out decimal dec) == false)
{ {
@@ -29,7 +30,14 @@ namespace VAR.ExpressionEvaluator
} }
leftValue = dec; leftValue = dec;
} }
}
if (rightValue is string) if (rightValue is string)
{
if (string.IsNullOrEmpty((string)rightValue))
{
leftValue = null;
}
else
{ {
if (decimal.TryParse((string)rightValue, out decimal dec) == false) if (decimal.TryParse((string)rightValue, out decimal dec) == false)
{ {
@@ -37,6 +45,12 @@ namespace VAR.ExpressionEvaluator
} }
rightValue = dec; rightValue = dec;
} }
}
if (leftValue == null || rightValue == null)
{
return false;
}
if ((leftValue is decimal) == false || (rightValue is decimal) == false) if ((leftValue is decimal) == false || (rightValue is decimal) == false)
{ {

View File

@@ -11,17 +11,18 @@ namespace VAR.ExpressionEvaluator
private static object LessThanOp(object leftValue, object rightValue) private static object LessThanOp(object leftValue, object rightValue)
{ {
if (leftValue == null || rightValue == null)
{
return false;
}
if (leftValue is string && rightValue is string) if (leftValue is string && rightValue is string)
{ {
return string.Compare((string)leftValue, (string)rightValue) < 0; return string.Compare((string)leftValue, (string)rightValue) < 0;
} }
if (leftValue is string) if (leftValue is string)
{
if (string.IsNullOrEmpty((string)leftValue))
{
leftValue = null;
}
else
{ {
if (decimal.TryParse((string)leftValue, out decimal dec) == false) if (decimal.TryParse((string)leftValue, out decimal dec) == false)
{ {
@@ -29,7 +30,14 @@ namespace VAR.ExpressionEvaluator
} }
leftValue = dec; leftValue = dec;
} }
}
if (rightValue is string) if (rightValue is string)
{
if (string.IsNullOrEmpty((string)rightValue))
{
leftValue = null;
}
else
{ {
if (decimal.TryParse((string)rightValue, out decimal dec) == false) if (decimal.TryParse((string)rightValue, out decimal dec) == false)
{ {
@@ -37,6 +45,12 @@ namespace VAR.ExpressionEvaluator
} }
rightValue = dec; rightValue = dec;
} }
}
if (leftValue == null || rightValue == null)
{
return false;
}
if ((leftValue is decimal) == false || (rightValue is decimal) == false) if ((leftValue is decimal) == false || (rightValue is decimal) == false)
{ {

View File

@@ -11,21 +11,18 @@ namespace VAR.ExpressionEvaluator
private static object NotEqualsOp(object leftValue, object rightValue) 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) if (leftValue is string && rightValue is string)
{ {
return string.Compare((string)leftValue, (string)rightValue) != 0; return string.Compare((string)leftValue, (string)rightValue) != 0;
} }
if (leftValue is string) if (leftValue is string)
{
if (string.IsNullOrEmpty((string)leftValue))
{
leftValue = null;
}
else
{ {
if (decimal.TryParse((string)leftValue, out decimal dec) == false) if (decimal.TryParse((string)leftValue, out decimal dec) == false)
{ {
@@ -33,7 +30,14 @@ namespace VAR.ExpressionEvaluator
} }
leftValue = dec; leftValue = dec;
} }
}
if (rightValue is string) if (rightValue is string)
{
if (string.IsNullOrEmpty((string)rightValue))
{
leftValue = null;
}
else
{ {
if (decimal.TryParse((string)rightValue, out decimal dec) == false) if (decimal.TryParse((string)rightValue, out decimal dec) == false)
{ {
@@ -41,6 +45,16 @@ namespace VAR.ExpressionEvaluator
} }
rightValue = dec; 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) if ((leftValue is decimal) == false || (rightValue is decimal) == false)
{ {