Skip to content

Commit f50e2db

Browse files
Merge pull request #54 from delegateas/tst/fixes
Tst/fixes
2 parents eb4be7e + 8760370 commit f50e2db

4 files changed

Lines changed: 41 additions & 38 deletions

File tree

ExpressionEngine/ExpressionGrammar.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public ExpressionGrammar(IEnumerable<IFunction> functions)
2828
constString => new ConstantRule(new ValueContainer(constString, true))
2929
);
3030

31+
Parser<IRule> decimalInvariant =
32+
Parse.DecimalInvariant.Select(x => new ConstantRule(new ValueContainer(x, true)));
33+
34+
Parser<IRule> number = decimalInvariant.Or(integer);
35+
3136
Parser<string> simpleString =
3237
Parse.AnyChar.Except(Parse.Char('@')).AtLeastOnce().Text();
3338

@@ -71,7 +76,7 @@ from index in Parse.AnyChar.Except(
7176
select new IndexRule(new StringLiteralRule(new ValueContainer(index)), nll);
7277

7378
Parser<IRule> argument =
74-
from arg in Parse.Ref(() => _method.Or(stringLiteral).Or(integer).Or(boolean))
79+
from arg in Parse.Ref(() => _method.Or(stringLiteral).Or(number).Or(boolean))
7580
select arg;
7681

7782
Parser<IOption<IEnumerable<IRule>>> arguments =

ExpressionEngine/FlowRunnerDependencyExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private static void AddLogicalComparisonFunctions(IServiceCollection services)
8585

8686
private static void AddMathFunctions(IServiceCollection services)
8787
{
88-
services.AddTransient<IFunction, AndFunction>();
88+
services.AddTransient<IFunction, AddFunction>();
8989
services.AddTransient<IFunction, DivFunction>();
9090
services.AddTransient<IFunction, MaxFunction>();
9191
services.AddTransient<IFunction, MinFunction>();

ExpressionEngine/ValueContainer.cs

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ public ValueContainer(string value, bool tryToParse = false)
2424

2525
if (tryToParse)
2626
{
27-
if (int.TryParse(value, out var iValue))
28-
{
29-
_value = iValue;
30-
_type = ValueType.Integer;
31-
}
32-
else if (float.TryParse(value, out var fValue))
27+
if (value.Contains('.') && double.TryParse(value, out var fValue))
3328
{
3429
_value = fValue;
3530
_type = ValueType.Float;
3631
}
32+
else if (int.TryParse(value, out var iValue))
33+
{
34+
_value = iValue;
35+
_type = ValueType.Integer;
36+
}
3737
else if (bool.TryParse(value, out var bValue))
3838
{
3939
_value = bValue;
@@ -236,37 +236,29 @@ public int CompareTo(object? obj)
236236
throw new InvalidOperationException("Cannot compare these two...");
237237

238238
var other = (ValueContainer) obj;
239-
if (other.Type() != _type)
240-
{
241-
// TODO: Fix comparison
242239

243-
throw new InvalidOperationException("Cannot compare two different ValueContainers");
244-
}
245-
else
240+
switch (_value)
246241
{
247-
switch (_value)
248-
{
249-
case bool b:
250-
return b.CompareTo(other._value);
251-
case int i:
252-
return i.CompareTo(other._value);
253-
case float f:
254-
return f.CompareTo(other._value);
255-
case double f:
256-
return f.CompareTo(other._value);
257-
case decimal f:
258-
return f.CompareTo(other._value);
259-
case string s:
260-
return s.CompareTo(other._value);
261-
case Dictionary<string, ValueContainer> d:
262-
var d2 = (Dictionary<string, ValueContainer>) other._value;
263-
return d.Count - d2.Count;
264-
case IEnumerable<ValueContainer> l:
265-
var l2 = (IEnumerable<ValueContainer>) other._value;
266-
return l.Count() - l2.Count();
267-
default:
268-
return -1;
269-
}
242+
case bool b:
243+
return b.CompareTo(other._value);
244+
case int i:
245+
return i.CompareTo(other._value);
246+
case float f:
247+
return f.CompareTo(other._value);
248+
case double f:
249+
return f.CompareTo(other._value);
250+
case decimal f:
251+
return f.CompareTo(other._value);
252+
case string s:
253+
return s.CompareTo(other._value);
254+
case Dictionary<string, ValueContainer> d:
255+
var d2 = (Dictionary<string, ValueContainer>) other._value;
256+
return d.Count - d2.Count;
257+
case IEnumerable<ValueContainer> l:
258+
var l2 = (IEnumerable<ValueContainer>) other._value;
259+
return l.Count() - l2.Count();
260+
default:
261+
return -1;
270262
}
271263
}
272264

@@ -357,7 +349,8 @@ public static async ValueTask<ValueContainer> CreateValueContainerFromJToken(JTo
357349
return v;
358350
}
359351

360-
private static async ValueTask<ValueContainer> JsonToValueContainer(JToken json, IExpressionEngine expressionEngine)
352+
private static async ValueTask<ValueContainer> JsonToValueContainer(JToken json,
353+
IExpressionEngine expressionEngine)
361354
{
362355
switch (json)
363356
{

Test/ParserTest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ public async Task TestSimpleInput(TestInput testInput)
9090
new TestInput("@{toLower(\'Hej med dig \')}@{trim(\' Mads \')}", new ValueContainer("hej med dig Mads")),
9191
new TestInput("@@1", new ValueContainer("@1")),
9292
new TestInput("aes", new ValueContainer("aes")),
93+
new TestInput("@greater(11, 10)", new ValueContainer(true)),
94+
new TestInput("@greater(10.1, 10.0)", new ValueContainer(true)),
95+
new TestInput("@greater(10.1, 10)", new ValueContainer(true)),
96+
new TestInput("@add(10,0.5)", new ValueContainer(10.5)),
97+
9398
};
9499

95100
#endregion

0 commit comments

Comments
 (0)