Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 63bc30aa7f | |||
| 44f3d58db4 | |||
| 551da30a7e | |||
| e7736f26b7 | |||
| 1a878fe4e7 | |||
| 75f5c948ed | |||
| ad9e3e6bad |
13
.idea/.idea.VAR.ExpressionEvaluator/.idea/.gitignore
generated
vendored
Normal file
13
.idea/.idea.VAR.ExpressionEvaluator/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Rider ignored files
|
||||||
|
/.idea.VAR.ExpressionEvaluator.iml
|
||||||
|
/modules.xml
|
||||||
|
/contentModel.xml
|
||||||
|
/projectSettingsUpdater.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
4
.idea/.idea.VAR.ExpressionEvaluator/.idea/encodings.xml
generated
Normal file
4
.idea/.idea.VAR.ExpressionEvaluator/.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||||
|
</project>
|
||||||
8
.idea/.idea.VAR.ExpressionEvaluator/.idea/indexLayout.xml
generated
Normal file
8
.idea/.idea.VAR.ExpressionEvaluator/.idea/indexLayout.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="UserContentModel">
|
||||||
|
<attachedFolders />
|
||||||
|
<explicitIncludes />
|
||||||
|
<explicitExcludes />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/.idea.VAR.ExpressionEvaluator/.idea/vcs.xml
generated
Normal file
6
.idea/.idea.VAR.ExpressionEvaluator/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -241,6 +241,19 @@ namespace VAR.ExpressionEvaluator.Tests
|
|||||||
Assert.Equal(4m, result);
|
Assert.Equal(4m, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Functions__ZeroParameters()
|
||||||
|
{
|
||||||
|
EvaluationContext evaluationContex = new EvaluationContext();
|
||||||
|
evaluationContex.SetFunction("constant", (parameters) =>
|
||||||
|
{
|
||||||
|
return 9m;
|
||||||
|
});
|
||||||
|
string expression = "constant()";
|
||||||
|
object result = Parser.EvaluateString(expression, evaluationContex);
|
||||||
|
Assert.Equal(9m, result);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion Functions
|
#endregion Functions
|
||||||
|
|
||||||
#region Strings
|
#region Strings
|
||||||
@@ -253,6 +266,14 @@ namespace VAR.ExpressionEvaluator.Tests
|
|||||||
Assert.Equal("Hello World", result);
|
Assert.Equal("Hello World", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Strings__Contatenate_Hello_World_SimpleQuotes()
|
||||||
|
{
|
||||||
|
string expression = "'Hello' + ' ' +'World'";
|
||||||
|
object result = Parser.EvaluateString(expression);
|
||||||
|
Assert.Equal("Hello World", result);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Strings__Contatenate_Hello_World_WithVariables()
|
public void Strings__Contatenate_Hello_World_WithVariables()
|
||||||
{
|
{
|
||||||
@@ -664,7 +685,7 @@ namespace VAR.ExpressionEvaluator.Tests
|
|||||||
|
|
||||||
#endregion String coercions
|
#endregion String coercions
|
||||||
|
|
||||||
#region Excepctions
|
#region Exceptions
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Exceptions__HelloAtEnd__UnexpectedCharactersAtEndException()
|
public void Exceptions__HelloAtEnd__UnexpectedCharactersAtEndException()
|
||||||
@@ -848,6 +869,33 @@ namespace VAR.ExpressionEvaluator.Tests
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endregion Exceptions
|
||||||
|
|
||||||
|
#region Misc
|
||||||
|
|
||||||
|
[Fact()]
|
||||||
|
public void Misc__MixedExpression_EqualsFalse()
|
||||||
|
{
|
||||||
|
EvaluationContext evaluationContex = new EvaluationContext();
|
||||||
|
evaluationContex.SetVariable("QI_86", null);
|
||||||
|
evaluationContex.SetVariable("QI_87", null);
|
||||||
|
evaluationContex.SetVariable("QI_104", null);
|
||||||
|
string expression = "( QI_86 = 0 Or QI_86 = null ) And ( QI_87 = 0 Or QI_87 = null ) And QI_104 > 0";
|
||||||
|
object result = Parser.EvaluateString(expression, evaluationContex);
|
||||||
|
Assert.False((bool?)result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact()]
|
||||||
|
public void Misc__ProductWithStringDecimals_EqualsFalse()
|
||||||
|
{
|
||||||
|
EvaluationContext evaluationContex = new EvaluationContext();
|
||||||
|
evaluationContex.SetVariable("$1109", "1933");
|
||||||
|
evaluationContex.SetVariable("$1150", "02.00000");
|
||||||
|
string expression = "$1109 * $1150";
|
||||||
|
object result = Parser.EvaluateString(expression, evaluationContex);
|
||||||
|
Assert.Equal(3866.00000M, result);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion Misc
|
#endregion Misc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
|
|
||||||
if (leftValue is string)
|
if (leftValue is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
if (rightValue is string)
|
if (rightValue is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
// Decimal
|
// Decimal
|
||||||
if (leftValue is string)
|
if (leftValue is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
leftValue = null;
|
leftValue = null;
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
}
|
}
|
||||||
if (rightValue is string)
|
if (rightValue is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
rightValue = null;
|
rightValue = null;
|
||||||
}
|
}
|
||||||
@@ -85,7 +85,7 @@
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
decimal decValue;
|
decimal decValue;
|
||||||
if (decimal.TryParse(text, out decValue))
|
if (decimal.TryParse(text, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decValue))
|
||||||
{
|
{
|
||||||
return decValue != 0;
|
return decValue != 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
|
|
||||||
if (leftValue is string)
|
if (leftValue is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
if (rightValue is string)
|
if (rightValue is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
|
|
||||||
if (leftValue is string)
|
if (leftValue is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)leftValue, out decimal dec) == false)
|
if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue));
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
}
|
}
|
||||||
if (rightValue is string)
|
if (rightValue is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)rightValue, out decimal dec) == false)
|
if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
|
|
||||||
if (value is string)
|
if (value is string)
|
||||||
{
|
{
|
||||||
if (decimal.TryParse((string)value, out decimal dec) == false)
|
if (decimal.TryParse((string)value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false)
|
||||||
{
|
{
|
||||||
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)value));
|
throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)value));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
|
|
||||||
#region Creator
|
#region Creator
|
||||||
|
|
||||||
private ITokenizer _tokenizer;
|
private readonly ITokenizer _tokenizer;
|
||||||
|
|
||||||
public Parser(ITokenizer tokenizer)
|
public Parser(ITokenizer tokenizer)
|
||||||
{
|
{
|
||||||
@@ -60,7 +60,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
IExpressionNode rightNode = ParseRelations();
|
IExpressionNode rightNode = ParseRelations();
|
||||||
leftNode = new ExpressionBooleanAndNode(leftNode, rightNode);
|
leftNode = new ExpressionBooleanAndNode(leftNode, rightNode);
|
||||||
}
|
}
|
||||||
if (_tokenizer.Token == Token.Or)
|
else if (_tokenizer.Token == Token.Or)
|
||||||
{
|
{
|
||||||
_tokenizer.NextToken();
|
_tokenizer.NextToken();
|
||||||
IExpressionNode rightNode = ParseRelations();
|
IExpressionNode rightNode = ParseRelations();
|
||||||
@@ -84,7 +84,7 @@ namespace VAR.ExpressionEvaluator
|
|||||||
IExpressionNode rightNode = ParsePlusAndMinus();
|
IExpressionNode rightNode = ParsePlusAndMinus();
|
||||||
leftNode = new ExpressionEqualsNode(leftNode, rightNode);
|
leftNode = new ExpressionEqualsNode(leftNode, rightNode);
|
||||||
}
|
}
|
||||||
if (_tokenizer.Token == Token.ExclusiveEquals)
|
else if (_tokenizer.Token == Token.ExclusiveEquals)
|
||||||
{
|
{
|
||||||
// TODO: Implement ExpressionExclusiveEqualsNode
|
// TODO: Implement ExpressionExclusiveEqualsNode
|
||||||
_tokenizer.NextToken();
|
_tokenizer.NextToken();
|
||||||
@@ -239,15 +239,18 @@ namespace VAR.ExpressionEvaluator
|
|||||||
{
|
{
|
||||||
_tokenizer.NextToken();
|
_tokenizer.NextToken();
|
||||||
var parameters = new List<IExpressionNode>();
|
var parameters = new List<IExpressionNode>();
|
||||||
while (true)
|
if (_tokenizer.Token != Token.ParenthesisEnd)
|
||||||
{
|
{
|
||||||
parameters.Add(ParseBooleanOp());
|
while (true)
|
||||||
if (_tokenizer.Token == Token.Comma)
|
|
||||||
{
|
{
|
||||||
_tokenizer.NextToken();
|
parameters.Add(ParseBooleanOp());
|
||||||
continue;
|
if (_tokenizer.Token == Token.Comma)
|
||||||
|
{
|
||||||
|
_tokenizer.NextToken();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (_tokenizer.Token != Token.ParenthesisEnd)
|
if (_tokenizer.Token != Token.ParenthesisEnd)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PackageId>VAR.ExpressionEvaluator</PackageId>
|
<PackageId>VAR.ExpressionEvaluator</PackageId>
|
||||||
<Title>VAR.ExpressionEvaluator</Title>
|
<Title>VAR.ExpressionEvaluator</Title>
|
||||||
<Version>0.2.5</Version>
|
<Version>0.2.8</Version>
|
||||||
<Description>Expression Evaluation Library</Description>
|
<Description>Expression Evaluation Library</Description>
|
||||||
<Authors>VAR</Authors>
|
<Authors>VAR</Authors>
|
||||||
<Company>VAR</Company>
|
<Company>VAR</Company>
|
||||||
|
|||||||
Reference in New Issue
Block a user